Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How Do I Make A Voting System?
- Shademist
-
Scratcher
34 posts
How Do I Make A Voting System?
How do i make a foolproof voting system that only lets you vote once? I know its possible using cloud data…. i just don't know how!!! If you post the solution below just fyi i will be using it so…..please don't be like…..heres the answer just don't use it!!!
- ggenije
-
Scratcher
500+ posts
How Do I Make A Voting System?
Make cloud list of names of people which vote For cloud lists see this https://scratch.mit.edu/studios/2942315/
and then
and then
if <[users which are voted] contains [username] ?> then
vote
end
Last edited by ggenije (Aug. 16, 2016 23:29:07)
- Shademist
-
Scratcher
34 posts
How Do I Make A Voting System?
Make cloud list of names of people which vote For cloud lists see this https://scratch.mit.edu/studios/2942315/
and thenif <[users which are voted] contains [username] ?> then
vote
end[/quote]
Okay but how do i get the weird red hacked blocks?
- amylaser
-
Scratcher
500+ posts
How Do I Make A Voting System?
I'm not too sure on this, but I think that all you need to do is a make a list and store the Scratcher's username in it once they press the “vote” button (or whatever you're using). Then you just need a cloud variable to store the number of votes.
Here's an example: let's say you have two buttons that the voter clicks if their favorite color is either red or blue. For the “vote button” sprite, you would have something like this:
Assuming this is for the “red vote” button:
Just make sure that your “red votes” variable (or whatever you want to name it) is a cloud variable. You will also need a cloud variable called “list of voters” to store the username (preferably in encoded form…read the Scratch wiki page about that), and then a function to break down that variable into list form.
And if you want to add more vote buttons, just make more costumes (or sprites). I recommend using clones and if/else blocks.
Hope this helped!
Here's an example: let's say you have two buttons that the voter clicks if their favorite color is either red or blue. For the “vote button” sprite, you would have something like this:
Assuming this is for the “red vote” button:
when this sprite clicked
if <not <[list of voters v] contains (username) ?>> then
change [red votes v] by (1)
set [list of voters v] to (join (list of voters) (join [,] (username)))
end
Just make sure that your “red votes” variable (or whatever you want to name it) is a cloud variable. You will also need a cloud variable called “list of voters” to store the username (preferably in encoded form…read the Scratch wiki page about that), and then a function to break down that variable into list form.
And if you want to add more vote buttons, just make more costumes (or sprites). I recommend using clones and if/else blocks.
Hope this helped!

Last edited by amylaser (Aug. 17, 2016 02:42:43)
- deck26
-
Scratcher
1000+ posts
How Do I Make A Voting System?
As you can see from your post the red blocks are just things that appear in Scratchblocks that the forum doesn't recognise. What is being suggested by @ggenije is that you put your own code in there. The actual voting mechanism is trivial once you have the cloud list in place and they were just covering the bit you needed help with. Perhaps it doesn't seem so trivial to you but @amylaser gives you more on that but the cloud list is key to storing the usernames. There are lots of cloud list projects and the wiki page on Global High Scores covers the encoding/decoding of a cloud list.Make cloud list of names of people which vote For cloud lists see this https://scratch.mit.edu/studios/2942315/
and thenif <[users which are voted] contains [username] ?> then
vote
end
Okay but how do i get the weird red hacked blocks?
- squidgaming777
-
Scratcher
44 posts
How Do I Make A Voting System?
say you were voting between chocolate cake and ice cream. This works.
_________________________________________
But make sure that
are cloud variables.
when this sprite clickedthat would be for chocolate cake and
if <not <[list of voters v] contains (username) ?>> then
change [chocolate cake v] by (1)
set [list of voters v] to (join (list of voters) (join [, ] (username)))
add (username) to [list of voters v]
end
when this sprite clickedWould be for ice cream
if <not <[list of voters v] contains (username) ?>> then
change [ice cream v] by (1)
set [list of voters v] to (join (list of voters) (join [, ] (username)))
add (username) to [list of voters v]
end
_________________________________________
But make sure that
(list of voters)and
(chocolate cake)and
(ice cream)
are cloud variables.
Last edited by squidgaming777 (April 28, 2018 02:15:53)
- deck26
-
Scratcher
1000+ posts
How Do I Make A Voting System?
say you were voting between chocolate cake and ice cream. This works.Please don't necropost. Cloud variables have become much more restricted since this topic was last posted on and it probably isn't really feasible to do this any more - assuming 16 characters per username you'd only be able to store around 40 usernames with no space left for the actual vote count. OK, usernames vary in length so you might manage a few more but less than 100.when this sprite clickedthat would be for chocolate cake and
if <not <[list of voters v] contains (username) ?>> then
change [chocolate cake v] by (1)
set [list of voters v] to (join (list of voters) (join [, ] (username)))
add (username) to [list of voters v]
endwhen this sprite clickedWould be for ice cream
if <not <[list of voters v] contains (username) ?>> then
change [ice cream v] by (1)
set [list of voters v] to (join (list of voters) (join [, ] (username)))
add (username) to [list of voters v]
end
_________________________________________
But make sure that(list of voters)and(chocolate cake)and(ice cream)
are cloud variables.
- Discussion Forums
- » Help with Scripts
-
» How Do I Make A Voting System?