Display the value of Variable

What is the best way to display the value of a variable. I can’t find any documentation on it.

There are lots of ways to learn the value of a variable; use whichever technique works best for your needs.

Probably the simplest way to find the value of a variable is to use a splash or a sprite say block. That’s super helpful if you’re trying to fix your code, since you learn not only what the value of the variable is but also where you are in your code.

If you’re used to doing traditional programming on a command line, there is a block in the Console drawer of the toolbox. (You’ll need to open the Advanced section to find it.) You can use the blocks there to send information to the console; a button appears below the simulator when you send your first message to the console. The nice thing about console messages is that you can leave them in your game; you’ll only see them if you open the console.

If you’re used to standard debugging tools, then MakeCode Arcade has a wonderful debugger. The team has worked really hard on the debugger to make it really useful. You enable and disable debug mode by clicking on the “bug” button in the toolbar below the game controls.

How about others? Do you all have some go-to techniques when you’re trying to figure out what your code is doing?


Thanks! I didn’t know about the bug icon, and have been using console commands exclusively. Good to know this will help a lot.

1 Like

If you want your sprite to say the value of a variable, do this:

((spritename) say (variablename))

Or if you want a score/life to be a variable, then you can do this:

(set score/life to ((variablename))

You can also use the “arcade-text” extension and do this:
(set (textspritename) to text sprite (variablename))

If that doesn’t work (because the variable is not a text variable), then you can do this:
(set (textspritename) to text sprite convert (variablename) to text)

(The text under each photo is NOT javascript or python, it’s just for if the photos dissapear for some reason.)