ARI FISHER
ARI FISHER

Reputation: 353

Why is my Scratch Cloud Variable not Updating?

I am making a multiplayer game, which can be found here: project. It has the following script, before the main one. I tested this script thoroughly, but it seems like it isn't working. For some reason, despite the fact that my cloud variable should be updating every 0.2 seconds, it won't change in five seconds, on the other browser. What's going on, and how do I fix it?

when green flag clicked
set [tick_p1 v] to (☁p1)
set [tick_p2 v] to (☁p2)
wait ( 5 ) secs
if <(☁p1) = (tick_p1)> then
set [ (g) player v] to (1)
else
if <(☁p2) = (tick_p2)> then
set [ (g) player v] to (2)
else
stop [every single thing in this project v]
end
end

Upvotes: 2

Views: 4710

Answers (4)

Projectmakerio
Projectmakerio

Reputation: 1

If you have added a cloud variable project some minute ago and its not updating you should do the following:

  1. Login to an alternate account in scratch.
  2. Open the test project. [*Note : It should be shared]
  3. Then in the main account i.e. the account from which you shared the project, go the project's editor , update the cloud variable and click on file and click save now.
  4. Do this every time you update. *Note : For constant update use run without screen refresh

Upvotes: 0

Super Coder
Super Coder

Reputation: 85

Try doing the whole thing in a block running without screen refresh.

Much also depends on your network speed, so try playing some Griffpatch multiplayer games and check if your net speed is appropriately fast for the cloud variable to update faster.
Make the tick loop in the define block which RUNS WITHOUT SCREEN REFRESH ... As @Catogram quoted:

it must run on a fast loop...

(This is what Griffpatch and all other cloud multiplayer game makers always do, but the program also tend to break when the network connectivity is low).


Hope this solves your problem !

Upvotes: 0

GD Vicious bee
GD Vicious bee

Reputation: 47

Cloud variables have limitations, for example, you cannot store letters and symbols in cloud variables. Also cloud variables always would take an eternity to reload, like I tried in my scratch game. It is better used for keeping track of a WR instead of an encrypted account variable. Also fun fact: griffpatch's multiplayer games don't work anymore

Upvotes: 0

Catogram
Catogram

Reputation: 323

That is likely due to network lag. Scratch cloud variables can often be quite glitchy and take quite a large amount of time to update. I know this may not be the answer you are looking for, but making an online multiplayer game that updates immediately is very difficult, if not impossible, using scratch. As described in this scratch wiki article:

"To avoid overloading the cloud data infrastructure, cloud data updates are limited to a certain number per second when a project is being run. One should always avoid attempting to update a cloud variable in a fast loop that does not wait between updates. Generally, one should carefully consider how often a cloud variable is updated and try to limit any updates to only times when it is needed, such as when the value actually changes, and to limit how often the variable is updated."

In other words, cloud variables cannot be updated quickly and are better suited for saving data such as a username for a highscore, rather than a live online multiplayer game.

Upvotes: 3

Related Questions