Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDs in Scratch: Cloud Variables

Tags:

mit-scratch

I have a multiplayer project which has some forever loops with checking code inside of them. block of code][![block of code

The problem is, multiple computers might process this and change crabx or craby due to lag in the variables dvotes, uvotes, lvotes, or rvotes. Only one machine should change this, though.

This can be easily solved by giving each player an ID like many people do in SQL. I would just check if the ID is 1, and that would be the "operating machine". I would then do all of these checks on that one machine. It would do things a Scratch server would do if you could program it...

The problem with this is that there is no way to detect when a player leaves the game. There is no block that is called "on exit" or "on stop button pressed". How would I go about doing this? I have seen people have a button which people click to exit, but some people will not click it/not even see it.

Thanks in advance!

like image 336
yummypasta Avatar asked Jul 23 '26 05:07

yummypasta


1 Answers

Option 1

I've never been especially successful with cloud data myself, but I've heard the theory on this before:

Essentially, each player gets a "counter". Their computer then constantly increases that counter. If the counter ever stops increasing (which will be detected by the other computers, who are all looking after one another), the project will know that the user has left and one of the computers will take care of removing their ID and other data.

Obviously, this is much easier said than done. (As I said, I've never gotten complex cloud data to work well for myself, but I've seen it done successfully and explained.)

Option 2

Alternatively, you might be better off taking advantage of this cloud api created by MegaApuTurkUltra. I find that stealing from others tends to be the best way of solving problems when it comes to code. ;)

like image 93
PullJosh Avatar answered Jul 26 '26 03:07

PullJosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!