Discuss Scratch

-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players


I recently had an idea for a new method of being able to efficiently and continuously provide the amount of players on a Scratch project (assuming they have the Scratch status & are signed in). When a user joins the project, a script begins to run that adds a number to a cloud variable. It adds the same number EVERY SECOND. Now, when a second user joins the project, the script is run on their project too, meaning now 2 scripts are running. If both of them are adding the same number to the cloud variable, the cloud variable should increase by double what it was with only one user. And 3 times as much with 3 users on the project, 4 times as much with 4 users on the project, and so on. It's a really simple concept.
I have another part of the script that takes that information and turns it into the player count. The way that works is the value of that cloud variable is stored, and then the NEXT value of the cloud variable is stored. The previous value is subtracted from the current one, therefore finding the amount of players online (AKA the amount of scripts running to change the cloud variable).

Let me show you what my scripts look like so far:
when gf clicked
set [Players Online v] to [0] // The number of players online
set [PrevVal v] to [0] // The cloud variable value right before the current one
set [ROC v] to [0] // The change between 2 iterations
set [C/P v] to ((1)/(100000)) // Change per player; the value that each player changes the cloud variable by
forever
change [☁ Detector v] by (C/P) // Changes the cloud variable every second
wait (1) secs // Waits one second
Detect, RWSR::custom // Detects the rate of change and the amount of players online
end
define Detect, RWSR
set [ROC v] to ((☁ Detector)-(PrevVal)) // Sets rate of change between previous & current iterations
set [PrevVal v] to (☁ Detector) // This is the PREVIOUS iteration
set [Players Online v] to (round ((ROC)*([10^ v] of ((length of (C/P)) - (2))::operators)))
**NOTE FOR “set Players Online” BLOCK IN DETECT SCRIPT**
The -2 is to tell the code to ignore the decimal and the 0 in front of it & only count the decimal places. Ten is taken to the power of the number of decimal points (turning it into a whole number), then it is multiplied by a number (ROC) that will take it back down to a single digit whole number.

I had really wanted to figure this out on my own, but for some reason, this hasn't been working! I've been testing it with my friend on a shared project, and the “Players Online” continued to display as 1 for both of us while we were both on. We've compared cloud variable changing times, and we're in sync (I live in Georgia, and she lives a few states away). What else could it be? I really appreciate any feedback you all may have. Get all the smart people you know to come help out, if you could xD

Last edited by -Yugen- (Nov. 11, 2016 12:19:33)

deck26
Scratcher
1000+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

Have you checked the cloud data log? (There's a link below the project.) That should allow you to see if the cloud variable is being changed and, if so, in what way.

Of course if two projects try to change the variable at exactly the same time they'll just make the same change. One option might be for each copy of the project to be assigned a random fraction of a second - eg 0.2 so it runs Detect after that interval and then waits for 0.8 seconds.

Remember the ‘wait’ block may not give you an exact time which may distort your values if the projects aren't runnning at the same speed - eg instead of getting 2 constantly you might get the occasional 1 and the occasional 3.

-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

deck26 wrote:

Have you checked the cloud data log? (There's a link below the project.) That should allow you to see if the cloud variable is being changed and, if so, in what way.

Of course if two projects try to change the variable at exactly the same time they'll just make the same change. One option might be for each copy of the project to be assigned a random fraction of a second - eg 0.2 so it runs Detect after that interval and then waits for 0.8 seconds.

Remember the ‘wait’ block may not give you an exact time which may distort your values if the projects aren't running at the same speed - eg instead of getting 2 constantly you might get the occasional 1 and the occasional 3.

If they chose the same randomization, then it wouldn't update. I see what you're saying, though. Thanks for helping, and I'm definitely taking your idea into consideration. I think my main issue is what you said about the projects trying to update the variable at the same time.

Edit: I knew this would happen… The cloud data monitor isn't working. I'm *pretty sure* the cloud data is actually changing, but nothing appears in the log. Is waiting one second too fast? Should I wait 2?

Last edited by -Yugen- (Nov. 10, 2016 12:25:36)

-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

Bump please
deck26
Scratcher
1000+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

-Yugen- wrote:

deck26 wrote:

Have you checked the cloud data log? (There's a link below the project.) That should allow you to see if the cloud variable is being changed and, if so, in what way.

Of course if two projects try to change the variable at exactly the same time they'll just make the same change. One option might be for each copy of the project to be assigned a random fraction of a second - eg 0.2 so it runs Detect after that interval and then waits for 0.8 seconds.

Remember the ‘wait’ block may not give you an exact time which may distort your values if the projects aren't running at the same speed - eg instead of getting 2 constantly you might get the occasional 1 and the occasional 3.

If they chose the same randomization, then it wouldn't update. I see what you're saying, though. Thanks for helping, and I'm definitely taking your idea into consideration. I think my main issue is what you said about the projects trying to update the variable at the same time.

Edit: I knew this would happen… The cloud data monitor isn't working. I'm *pretty sure* the cloud data is actually changing, but nothing appears in the log. Is waiting one second too fast? Should I wait 2?
(Don't bump so quickly!)

Cloud variables can be problematic - I'm not totally convinced they're reliable enough. You should be able to update more than once a second if the servers are responding quickly enough. It should be trivial in your case to monitor the cloud variable within your project to see if you're changing it so do that first - if you're not changing it then chances are a copy of the project won't do so either.
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

deck26 wrote:

Cloud variables can be problematic - I'm not totally convinced they're reliable enough. You should be able to update more than once a second if the servers are responding quickly enough. It should be trivial in your case to monitor the cloud variable within your project to see if you're changing it so do that first - if you're not changing it then chances are a copy of the project won't do so either.

xD Yeah, I realized after I asked for a bump that it was still on the top *lol*

The problem is that I can't tell if it IS updating. The cloud data monitor doesn't show any changes, so either that isn't working & the cloud data IS, or the cloud data isn't updating & the cloud data monitor is. What should I do? I'm fairly certain that I have my code right.
I added a bit more information to some of the notes attached to the blocks. The custom block is RWSR, etc. Will RWSR affect the cloud data?

Last edited by -Yugen- (Nov. 10, 2016 21:12:41)

Lataliat
Scratcher
100+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

I'm really bad at this, but here's what I noticed: Everytime the flag gets clicked, the amount of players online gets set to zero. Is that not a problem?
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

Lataliat wrote:

I'm really bad at this, but here's what I noticed: Everytime the flag gets clicked, the amount of players online gets set to zero. Is that not a problem?
No, because it is updated to 1 a moment later.
GearOS
New Scratcher
1 post

*BRAINS NEEDED* Cloud - Number of Online Players

when green flag clicked
change (☁ Players Online) by (1)
Then in another script: (You need a logout button)
when this sprite clicked
change (☁ Players Online) by (-1)
stop [ all]

That should work. Have fun!
deck26
Scratcher
1000+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

-Yugen- wrote:

deck26 wrote:

Cloud variables can be problematic - I'm not totally convinced they're reliable enough. You should be able to update more than once a second if the servers are responding quickly enough. It should be trivial in your case to monitor the cloud variable within your project to see if you're changing it so do that first - if you're not changing it then chances are a copy of the project won't do so either.

xD Yeah, I realized after I asked for a bump that it was still on the top *lol*

The problem is that I can't tell if it IS updating. The cloud data monitor doesn't show any changes, so either that isn't working & the cloud data IS, or the cloud data isn't updating & the cloud data monitor is. What should I do? I'm fairly certain that I have my code right.
I added a bit more information to some of the notes attached to the blocks. The custom block is RWSR, etc. Will RWSR affect the cloud data?
If you're displaying the cloud variable and it doesn't change when you run the project then the cloud variable is not updating and there's a problem with your code. It would help if, when you post here, you distinguish between monitoring (showing the variable) and checking the log as I'm not sure what you mean otherwise.
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

GearOS wrote:

when green flag clicked
change (☁ Players Online) by (1)
Then in another script: (You need a logout button)
when this sprite clicked
change (☁ Players Online) by (-1)
stop [ all]

That should work. Have fun!
Your script requires the player to click something before they leave. What happens if they don't, or they forget? It's not fullproof. Also, I'd appreciate comments that help me with the issue with my code, not alternatives
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

deck26 wrote:

-Yugen- wrote:

deck26 wrote:

Cloud variables can be problematic - I'm not totally convinced they're reliable enough. You should be able to update more than once a second if the servers are responding quickly enough. It should be trivial in your case to monitor the cloud variable within your project to see if you're changing it so do that first - if you're not changing it then chances are a copy of the project won't do so either.

xD Yeah, I realized after I asked for a bump that it was still on the top *lol*

The problem is that I can't tell if it IS updating. The cloud data monitor doesn't show any changes, so either that isn't working & the cloud data IS, or the cloud data isn't updating & the cloud data monitor is. What should I do? I'm fairly certain that I have my code right.
I added a bit more information to some of the notes attached to the blocks. The custom block is RWSR, etc. Will RWSR affect the cloud data?
If you're displaying the cloud variable and it doesn't change when you run the project then the cloud variable is not updating and there's a problem with your code. It would help if, when you post here, you distinguish between monitoring (showing the variable) and checking the log as I'm not sure what you mean otherwise.
Sorry, the “cloud data monitor” is what the log is called, hence me using the term. Sorry I wasn't clear :c. Also, the cloud variable IS changing, and changing for each user on the project, but it should be changing FASTER if 2 users are on the project. Here, let me share the project (on another account so it's not too conspicuous). Mess around with the code & try to figure out how it works Also, I'm going to add one more little change the notes in my code on the original post. It's on the last part of the custom block.
When you get on the project, keep in mind it takes a moment to “connect”. You'll see the variables go haywire, but then they'll settle down and do what they are told.

Last edited by -Yugen- (Nov. 11, 2016 12:14:15)

deck26
Scratcher
1000+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

The cloud data log (or history) seems to show no cloud access for your project. That may be because it is faulty at the moment or your cloud variable may not be working properly - which can happen. I remixed and the cloud data history seemed OK then so I'd be tempted to delete the cloud variable and recreate it to see if that helps.
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

Bump, please!
deck26
Scratcher
1000+ posts

*BRAINS NEEDED* Cloud - Number of Online Players

-Yugen- wrote:

Bump, please!
Did you try what I suggested and recreate the variable?
-Yugen-
Scratcher
56 posts

*BRAINS NEEDED* Cloud - Number of Online Players

deck26 wrote:

-Yugen- wrote:

Bump, please!
Did you try what I suggested and recreate the variable?
Didn't see the comment. I am now.
OldAboot
Scratcher
3 posts

*BRAINS NEEDED* Cloud - Number of Online Players

It's updating now. I wonder if that means it's working? Can you go on the project?


Edit: It's updating, but the values it says that it is updating are incorrect. Oh well(?)

Last edited by OldAboot (Nov. 12, 2016 14:28:49)

OldAboot
Scratcher
3 posts

*BRAINS NEEDED* Cloud - Number of Online Players

NVM, IT WORKS! Thanks so much @deck26! I just tested it with a friend, and it updated! All I had to do was delete and then re-create the variable! You rock!

Powered by DjangoBB