Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Cloud Multiplayer
- icmy123
-
Scratcher
100+ posts
Cloud Multiplayer
Recently, I want to develop m own Cloud Multiplayer Engine. It works pretty well, it can detect player slot, encode and decode. However, I don't know why it doesn't work when two players are online. Can you help me fix that? https://scratch.mit.edu/projects/376791527/
- deck26
-
Scratcher
1000+ posts
Cloud Multiplayer
Most projects that try to keep count of the number of players don't handle all the situations where the number changes in my opinion. You don't really need it as a cloud variable if you're checkng the slots before allocating a slot to a player. If you want to display a count of players you could just repeat your method of checking the player slots and update a local variable but I'd just drop the idea of keeping the count.
When checking the player slots don't store value 1, wait and check for a change and then repeat for slot 2 if necessary. Store both values and wait and then check the first value and the second if necessary.
You also need to avoid updating cloud variables too quickly - 10 times a second is about the max for all upgrades so if you have two variables being updated in a loop you could only update each 5 times a second. So you shouldn't build up your cloud variables P1 and P2 in a loop - build a temporary variable and then copy it to the cloud at the end of the loop.
The cloud variable monitor (link below the project window) is your best way fo checking what updates are happening.
When checking the player slots don't store value 1, wait and check for a change and then repeat for slot 2 if necessary. Store both values and wait and then check the first value and the second if necessary.
You also need to avoid updating cloud variables too quickly - 10 times a second is about the max for all upgrades so if you have two variables being updated in a loop you could only update each 5 times a second. So you shouldn't build up your cloud variables P1 and P2 in a loop - build a temporary variable and then copy it to the cloud at the end of the loop.
The cloud variable monitor (link below the project window) is your best way fo checking what updates are happening.
Last edited by deck26 (March 16, 2020 10:48:51)
- deck26
-
Scratcher
1000+ posts
Cloud Multiplayer
You're still building the cloud variable in a loop which means you're trying to update too frequently. Use a temporary variable to store the result and then set the cloud variable to the temporary variable once the loop has completed.
- Quak-a-doodles
-
Scratcher
47 posts
Cloud Multiplayer
I recommend that you create a server sprite and make a local variable and a cloud one named “My ID” which dictates what player are you. So once Join and someone already has an ID of 1, Then I check if someone has an ID of 2. If not then I set the Local ID variable to 2.
Then for player 2 there should be a If Statement Checking if the Local ID is equal 2 (same for player 1) Then do whatever script you want.
You should also have a checking connection script where it checks each player's connection. I made one myself:

Then for player 2 there should be a If Statement Checking if the Local ID is equal 2 (same for player 1) Then do whatever script you want.
You should also have a checking connection script where it checks each player's connection. I made one myself:

- Discussion Forums
- » Help with Scripts
-
» Cloud Multiplayer



