Game Breaking and Variables being renamed?

Hi, im making a creature collecting game (basically just a pokemon clone). Right now I have a map where you can talk to an NPC for a creature. Everything works fine, but sometimes my variables get automatically renamed. For example the NPC had its variable as “DrNPC” and then after a few hours and game testing it suddenly changed to “j”. When i rename the variable it’s saying that it’s already “DrNPC”. What in my code is breaking the game? How would I go about fixing this? I started makecode arcade a month ago so my code is really messy, could this be the problem?

Error code i’m constantly getting is:

“Program Error: sim error: failed cast on null”

when I fix it once, it happens again. I also have a lot of extensions.

2 Likes

Hi! It seems there are still some bugs in the new Makecode Arcade update! Variables getting deleted is a known bug, but yours seems a bit odd.

First, I would download a copy of the game so that if anything happens you have a copy. Either that, or you could just make a new copy of the game from the link you shared here if something goes wrong! I usually keep share links to my games in a document on my computer so that I have them if something goes wrong!

Next, try closing and opening Makecode again. Is the project still bugged? If so, maybe try naming the variables something else, and then change them back to what you want them to be. Hopefully doing that circumvents this weird bug!

About the “failed to cast on null” error, that just means you are trying to do something with a thing that doesn’t exist yet! In your case, this error is happening because you are trying to set a sprite to be invisible before the sprite exists:


The “On Start” block is be first thing that runs, so because you haven’t made (“set”) a “j” sprite yet, you can’t make it invisible or it will throw an error! If you move that block to after you create this “j” sprite, it should work!

Hopefully you can successfully rename this “j” variable because single character variables are always weird lol)

Also, if you are trying to make sure the sprite is invisible until you create it, don’t worry! It will not exist on the screen until you “set” it, so you don’t need to make it invisible.

3 Likes

Try checking the variables and using the Debug mode to find the issue faster.

This happened to me too! in my rpg game, the enemy variable got changed to “i”

1 Like

You can fix it by changing your version history to before the glitch and then sharing the project, reopening it by clicking edit code in the link it gives you and this has about a 75% chance of working.