Discuss Scratch

anthonytoney
Scratcher
40 posts

Whenever I make an online game, it always sets the player as player 2 (or maybe it always make the costume the second one).

Here's the project I'm working on; https://scratch.mit.edu/projects/561252620/

Last edited by anthonytoney (Sept. 15, 2021 14:15:50)

deck26
Scratcher
1000+ posts

Whenever I make an online game, it always sets the player as player 2 (or maybe it always make the costume the second one).

Doesn't fix your problem but try not to duplicate code. Assuming PlayerID can only be 1 or 2 the message1 receiver in Shapeman only needs the if block to set the costume - everything else is just duplicated. In fact you don't even need the if blocks since you can use ‘jopin’ to get the costume name from playerID.

You should allow 0.1 seconds between changes to cloud variables - even different ones. You set P1 Check and P2 Check in consecutive blocks.

I'm also not sure you understand how the checks are supposed to work. You should store the value of the cloud variable in a local varialbe, wait and then check if the local variable still matches. You're setting the variable in the block before you check the value so if the cloud is updating as quickly as you expect it will always match and both if blocks will set PlayerID with the second one overwriting the first and setting PlayerID to 2. You should be using if/else.
anthonytoney
Scratcher
40 posts

Whenever I make an online game, it always sets the player as player 2 (or maybe it always make the costume the second one).

deck26 wrote:

Doesn't fix your problem but try not to duplicate code. Assuming PlayerID can only be 1 or 2 the message1 receiver in Shapeman only needs the if block to set the costume - everything else is just duplicated. In fact you don't even need the if blocks since you can use ‘jopin’ to get the costume name from playerID.

You should allow 0.1 seconds between changes to cloud variables - even different ones. You set P1 Check and P2 Check in consecutive blocks.

I'm also not sure you understand how the checks are supposed to work. You should store the value of the cloud variable in a local varialbe, wait and then check if the local variable still matches. You're setting the variable in the block before you check the value so if the cloud is updating as quickly as you expect it will always match and both if blocks will set PlayerID with the second one overwriting the first and setting PlayerID to 2. You should be using if/else.
Can I have TLDR?
deck26
Scratcher
1000+ posts

Whenever I make an online game, it always sets the player as player 2 (or maybe it always make the costume the second one).

anthonytoney wrote:

deck26 wrote:

Doesn't fix your problem but try not to duplicate code. Assuming PlayerID can only be 1 or 2 the message1 receiver in Shapeman only needs the if block to set the costume - everything else is just duplicated. In fact you don't even need the if blocks since you can use ‘jopin’ to get the costume name from playerID.

You should allow 0.1 seconds between changes to cloud variables - even different ones. You set P1 Check and P2 Check in consecutive blocks.

I'm also not sure you understand how the checks are supposed to work. You should store the value of the cloud variable in a local varialbe, wait and then check if the local variable still matches. You're setting the variable in the block before you check the value so if the cloud is updating as quickly as you expect it will always match and both if blocks will set PlayerID with the second one overwriting the first and setting PlayerID to 2. You should be using if/else.
Can I have TLDR?
If that's too long for you to read you need someone else to help you.
anthonytoney
Scratcher
40 posts

Whenever I make an online game, it always sets the player as player 2 (or maybe it always make the costume the second one).

deck26 wrote:

anthonytoney wrote:

deck26 wrote:

Doesn't fix your problem but try not to duplicate code. Assuming PlayerID can only be 1 or 2 the message1 receiver in Shapeman only needs the if block to set the costume - everything else is just duplicated. In fact you don't even need the if blocks since you can use ‘jopin’ to get the costume name from playerID.

You should allow 0.1 seconds between changes to cloud variables - even different ones. You set P1 Check and P2 Check in consecutive blocks.

I'm also not sure you understand how the checks are supposed to work. You should store the value of the cloud variable in a local varialbe, wait and then check if the local variable still matches. You're setting the variable in the block before you check the value so if the cloud is updating as quickly as you expect it will always match and both if blocks will set PlayerID with the second one overwriting the first and setting PlayerID to 2. You should be using if/else.
Can I have TLDR?
If that's too long for you to read you need someone else to help you.
Can you check to see if I did the code right?

Powered by DjangoBB