Detect New Scratcher (Broken due to cloud bugs)

13,840
0
2014-02-28に共有
▶︎▶︎▶︎▶︎ IMPORTANT! PLEASE READ THIS ◀︎◀︎◀︎◀︎
Currently (Aug.2023), Scratch Cloud appears to not check what values a cloudvar has when a project first loads (it only sees *changes* to a cloudvar *after* the project loads). That means this project is no longer working as intended.
There are lots of problems this cloud bug causes when using cloudvars - for example, it means you can't keep high score(s), since it(/they) won't have the latest values from cloud when the project starts.
It also means there doesn't seem to be a way for a project to check it is connected to cloud when it first runs - so you can't make a multiplayer game that actually knows it is going to work correctly as a multiplayer game (unless there are other people connected at the same time who are changing the cloudvar, and the project notices that). :(

>>>> READ BELOW carefully to understand what this is, how it works, and how you can set it up correctly <<<<

-----==== Why Would I Want This? ====-----
This is useful for a multiplayer cloud-based game.
If you know that the player has not connected to cloud then you can inform the player that the game will not work in multiplayer mode. (You could still choose to have a single-player mode in the game, perhaps.)

-----==== How This Detector Works ====-----
When the project first loads, everyone gets the value for 'cloud tester' that was saved with the project (i.e. zero). However, only full Scratchers then make a connection to the cloud to retrieve the latest value (which is one).
-So it's simple to test for a Scratcher!

It's possible for a Scratcher to also get the New Scratcher value if something goes wrong when your browser tries to connect to the cloud after the project loads (in which case a reload should fix it), or if there's a problem with the Scratch cloud servers (in which case they will hopefully fix that fairly quickly, and it'll work again on next reload).

Feel free to scatter liberally throughout your own multiplayer games!

-----==== Practical Steps to do this Yourself ====-----
This method relies on the cloud variable having two *different* values, so:
1) Choose a value to save with the project (I chose zero).
2) Have a script in the project which checks whether the cloudvar is set to that chosen value (after a short delay from the project first starting) – if you find it is *not* set to that value then you know the user is a Scratcher.
3) Set the cloudvar to the value you chose above *before* you save the project. [Note that I used the "when S key pressed" script here to do that.]
4) Then, right after the project has saved, just *manually* change the cloud variable to something else (I chose the value 1 here). [Note that I used the "when R key pressed" script here to do that.]
5) THIS IS IMPORTANT: Make sure you *do not* re-save the project after step (4)!
6) It's now a good idea to check the project's cloud log page to ensure the cloudvar has the correct value in the cloud (one in this case); also, *sign out* and reload the project to check the cloudvar has the correct non-cloud value when the project loads (zero in this case).
7) If you do want to edit & save your project afterwards, you *must* follow steps (3) to (6) again.

That second value gets stored in the cloud, and stays set there, while the first value is only in the saved project, and that's what the cloudvar starts out as when the project first gets loaded.
This means that the value that was saved with the project is *different* from the value stored in the cloud. Since a New Scratcher will not connect to cloud, it's only a Scratcher who is able to see the value stored in the cloud (one, in this case), while a New Scratcher (or someone not signed in) will only be able to see the value that was saved with the project (zero, in this case).