my game was working fine until i added a new line of code to make the player sprite invisible on a certain thing and now whenever i make a change it just selects a random line (usually 60 to 50) and says “failed cast on null”
I’m not seeing the crash right away while playing it, is there something that has to happen in game to trigger it?
When that error occurs, it means you are trying to do something to something that doesn’t yet exist – for a simple example, swapping the order of these in the on start will do it:
There are a good number of loops in here, so I would imagine it’s likely something similar to that - expecting something to exist when it possibly hasn’t been made yet. A quick fix is to use an if
check to make sure the sprite exists before trying to make use of it, if there is a location you aren’t sure about.
If you press the little bug icon below the simulator, that’ll enter ‘debug mode’, and that will also stop on the line where the error is occurring when it happens, so that it’s easier to see where you need to change the code
Welcome to makecode forums
Your problem is that you are calling something before it is created.
Hope that helps
i just loaded the exact same file again and it’s working now. i’ve had many bugs with makecode such as it trying to turn a number variable into text with no indication or request that it be converted to text. it might’ve just been a bug all along.