Why doesn't my Set Player State work?

In the info blocks of the multiplayer extension. I made a new player state called “Direction”. I try setting the Direction in the on start/on player connected blocks as well as setting it to a different number every time a directional key button is pressed. But the Player State still reads as “0”. By the way if anyone is curious; 1 means up, 2 means right, 3 means down, and 4 means left. Is this a bug with Makecode Arcade itself or am I doing this wrong since I’ve tried everything, and it doesn’t change the number. Here’s the link to my game to see my code: https://arcade.makecode.com/S29349-30338-59749-30192

2 Likes

Thank you for taking time to post your issue here. This is a known bug (see: https://github.com/microsoft/pxt-arcade/issues/5952). In the meantime, here’s a workaround:

Add this block to the top of your “on player connected” handler:
image

The problem is that MakeCode isn’t creating quite enough storage space on the player to hold the highest-numbered custom state slot defined by the program (which happens to be “Direction” in this case). The workaround is to pre-allocate extra slots beyond the highest-numbered slot defined by the program, creating some headroom so the bug isn’t hit.

Thank you! I thought I was just bad at coding lol. Coding makes you regret your whole life sometimes.

2 Likes

I’m the one bad at coding. That was my bug :slight_smile:

1 Like