Discuss Scratch

happyisthegirl
Scratcher
22 posts

Counting Up Votes

Hello there, fellow Scratchers! I need help with some scripts in this project: https://scratch.mit.edu/projects/80129232/

I need to a code to count up votes in this project without having to add a script that takes a ton of time. I think some of you are getting confused. Okay, so let me say that some Scratcher is called @TaylorSwift2215. They drew an Elsa, and it is in my Different Elsas project and it is in my Voting for Elsas project. Some person votes for that person's Elsa, and then another person votes for that Elsa. I don't want to have to manually go to the votes list and count the 2 votes. I need a code to just count up the votes for each person without me doing anything except running the code. If somebody could give me a code that would let me know the top __ votes, then that would be even better.
So if you can help, I would love it.

Thanks,
Happy

Last edited by happyisthegirl (Oct. 18, 2015 16:43:38)

abbotcostello
Scratcher
100+ posts

Counting Up Votes

Yes, people, pleeaaseee help!!! ・ω・
DrKat123
Scratcher
1000+ posts

Counting Up Votes

OK, try using Cloud data,
Script example:
When this sprite is clicked :: events
Change [Cloud data v] by (1)
It seems that you're a scratcher. That means that you can access cloud data.
How to make cloud variables:
Click “Make a Variable”
Name it
Select “Cloud variable”
Note that cloud variables can only be used in the online editor.
happyisthegirl
Scratcher
22 posts

Counting Up Votes

DrKat123 wrote:

OK, try using Cloud data,
Script example:
When this sprite is clicked :: events
Change [Cloud data v] by (1)
It seems that you're a scratcher. That means that you can access cloud data.
How to make cloud variables:
Click “Make a Variable”
Name it
Select “Cloud variable”
Note that cloud variables can only be used in the online editor.
That doesn't help much because I already know what cloud data is and I don't know how that can help. Did you check the project and go inside? I've already used cloud lists and all that and they're working fine, but I need to know how to find a quick way to count up votes for each person so I don't have to manually count those up.
ZozaTech
Scratcher
500+ posts

Counting Up Votes

You need cloud variables. I am consuming you have.
when this sprite clicked
change [votes(cloud var)] by (1)

Last edited by ZozaTech (Oct. 18, 2015 13:25:17)

TheLogFather
Scratcher
1000+ posts

Counting Up Votes

I'm not sure I follow completely, but are you wanting to count how many times each person votes for something?

If so, you can add the counts for each person as the following items in the cloud list after each person. Or you can create a second list with the counts, and encode that list into a second cloud variable.

Either way, when you decode the information from the list(s), you can find the relevant counts that go with each person.

Does that help? (And is it what you're asking?)

Last edited by TheLogFather (Oct. 18, 2015 13:32:52)

happyisthegirl
Scratcher
22 posts

Counting Up Votes

TheLogFather wrote:

I'm not sure I follow completely, but are you wanting to count how many times each person votes for something?

If so, you can add the counts for each person as the following items in the cloud list after each person. Or you can create a second list with the counts, and encode that list into a second cloud variable.

Either way, when you decode the information from the list(s), you can find the relevant counts that go with each person.

Does that help? (And is it what you're asking?)

No, actually I want to know how to count up votes for each person without having to manually count up votes. Wait, let me add all this to the question post.
happyisthegirl
Scratcher
22 posts

Counting Up Votes

It's actually a bit different, @ZozaTech

Last edited by happyisthegirl (Oct. 18, 2015 16:45:43)

happyisthegirl
Scratcher
22 posts

Counting Up Votes

ZozaTech wrote:

You need cloud variables. I am consuming you have.
when this sprite clicked
change [votes(cloud var)] by (1)

That is not actually what I mean. How about you read the first post again? I explain it way better there.

Last edited by happyisthegirl (Oct. 19, 2015 22:30:42)

TheLogFather
Scratcher
1000+ posts

Counting Up Votes

OK, gotcha - understand now: you want to count how many times each picture was voted for.

It has nothing to do with cloud variables, and is simply counting how many times each particular name appears in the list.


What would be helpful here would be to have a list of the different possible picture names, in the same order as the backdrops. Then you can avoid all of those “if” checks in the Stage, one for each name to go with each background.

I would suggest you make a list of picture names like that, such that each name's position in the list corresponds to its backdrop number (minus one, since the first backdrop is like a title screen). Then you can replace all of those “if”s in Stage with, simply:
if ( ( (backdrop #) > [1] ) and ( (backdrop #) < ((length of [picture list v])+(2)) ) ) then
add ( (backdrop #) - (1) ) to [What Vote? v]
But, even more useful than the script-shortening above, you can then write a script that goes through each picture name in the list and counts how many times that name appears in the “What Vote?” list.


If you want to be even more snazzy, you could've named the backdrops themselves with the desired picture name, and used THAT list of backdrop names as effectively the list of picture names. Then you could just add the backdrop name to the “What Vote?” list when space pressed, and you could write a script which checks if you are the current user, and, if so, as you go through the backdrops yourself, it counts for you how many items there are in the “What Votes?” list which have the same name as the current backdrop, showing that in a variable.


Hope that all helps!

Last edited by TheLogFather (Oct. 20, 2015 08:01:38)

happyisthegirl
Scratcher
22 posts

Counting Up Votes

TheLogFather wrote:

OK, gotcha - understand now: you want to count how many times each picture was voted for.

It has nothing to do with cloud variables, and is simply counting how many times each particular name appears in the list.


What would be helpful here would be to have a list of the different possible picture names, in the same order as the backdrops. Then you can avoid all of those “if” checks in the Stage, one for each name to go with each background.

I would suggest you make a list of picture names like that, such that each name's position in the list corresponds to its backdrop number (minus one, since the first backdrop is like a title screen). Then you can replace all of those “if”s in Stage with, simply:
if ( ( (backdrop #) > [1] ) and ( (backdrop #) < ((length of [picture list v])+(2)) ) ) then
add ( (backdrop #) - (1) ) to [What Vote? v]
But, even more useful than the script-shortening above, you can then write a script that goes through each picture name in the list and counts how many times that name appears in the “What Vote?” list.


If you want to be even more snazzy, you could've named the backdrops themselves with the desired picture name, and used THAT list of backdrop names as effectively the list of picture names. Then you could just add the backdrop name to the “What Vote?” list when space pressed, and you could write a script which checks if you are the current user, and, if so, as you go through the backdrops yourself, it counts for you how many items there are in the “What Votes?” list which have the same name as the current backdrop, showing that in a variable.


Hope that all helps!

I don't really get how that script will help me count the number of votes for each picture.
TheLogFather
Scratcher
1000+ posts

Counting Up Votes

happyisthegirl wrote:

TheLogFather wrote:


if ( ( (backdrop #) > [1] ) and ( (backdrop #) < ((length of [picture list v])+(2)) ) ) then
add ( (backdrop #) - (1) ) to [What Vote? v]

I don't really get how that script will help me count the number of votes for each picture.
That script itself doesn't help you do that. But what I'm suggesting is that you add an extra “picture list” that contains names of the pictures.

I was demonstrating what a useful thing that is for your existing script (on the Stage, with all those “if” checks - you can replace all of those with the single short script above), and then that you can use that picture list to do exactly the counting you want.


Ok, if you want some script, it looks something like this:
define votecount = number of votes for (name)  // make this custom block run without screen refresh
set [pos v] to [0]
set [votecount v] to [0] // this will end up being the number of votes for that name
repeat (length of [What Vote? v])
change [pos v] by (1)
if ( (item (pos) of [What Vote? v]) = (name) ) then
change [votecount v] by (1)
end
end

If you have the picture list I mention above, you could then have a script like this:
when [v v] key pressed // special key for you to press to show/hide votes
if ( (username) = [happyisthegirl] ) then // just for you! :)
if ( (length of [vote counts v]) > [0] ) then // it will toggle between showing and hiding the list
hide list [vote counts v] // this is another new list; it will contain the vote counts (worked out below)
delete (all v) of [vote counts v] // clean out the list ready for next press of 'v' key
else
set [picpos v] to [0]
repeat (length of [picture list v])
change [picpos v] by (1)
votecount = number of votes for (item (picpos) of [picture list v]) :: custom block // this is the custom block defined above
add (join (item (picpos) of [picture list v]) (join [ has ] ( join (votecount) [ votes]) ) ) to [vote counts v]
end
show list [vote counts v] // make sure you press 'v' again to hide & clear the list before saving!
end

Is that more like what you're after…?

Last edited by TheLogFather (Oct. 20, 2015 15:13:52)

happyisthegirl
Scratcher
22 posts

Counting Up Votes

TheLogFather wrote:

happyisthegirl wrote:

TheLogFather wrote:


if ( ( (backdrop #) > [1] ) and ( (backdrop #) < ((length of [picture list v])+(2)) ) ) then
add ( (backdrop #) - (1) ) to [What Vote? v]

I don't really get how that script will help me count the number of votes for each picture.
That script itself doesn't help you do that. But what I'm suggesting is that you add an extra “picture list” that contains names of the pictures.

I was demonstrating what a useful thing that is for your existing script (on the Stage, with all those “if” checks - you can replace all of those with the single short script above), and then that you can use that picture list to do exactly the counting you want.


Ok, if you want some script, it looks something like this:
define votecount = number of votes for (name)  // make this custom block run without screen refresh
set [pos v] to [0]
set [votecount v] to [0] // this will end up being the number of votes for that name
repeat (length of [What Vote? v])
change [pos v] by (1)
if ( (item (pos) of [What Vote? v]) = (name) ) then
change [votecount v] by (1)
end
end

If you have the picture list I mention above, you could then have a script like this:
when [v v] key pressed // special key for you to press to show/hide votes
if ( (username) = [happyisthegirl] ) then // just for you! :)
if ( (length of [vote counts v]) > [0] ) then // it will toggle between showing and hiding the list
hide list [vote counts v] // this is another new list; it will contain the vote counts (worked out below)
delete (all v) of [vote counts v] // clean out the list ready for next press of 'v' key
else
set [picpos v] to [0]
repeat (length of [picture list v])
change [picpos v] by (1)
votecount = number of votes for (item (picpos) of [picture list v]) :: custom block // this is the custom block defined above
add (join (item (picpos) of [picture list v]) (join [ has ] ( join (votecount) [ votes]) ) ) to [vote counts v]
end
show list [vote counts v] // make sure you press 'v' again to hide & clear the list before saving!
end

Is that more like what you're after…?


Yes, thanks! I will use this kind of script when the time for counting up votes comes!

Powered by DjangoBB