Discuss Scratch

gobothe-clown
Scratcher
88 posts

How to make a variable with a dollar sign in front of it?

Basically I’m making a game and i want my variable to contain a dollar sign in front of the number that the variable displays on the variable, is this possible? Thanks
legendary34678
Scratcher
1000+ posts

How to make a variable with a dollar sign in front of it?

Yes, just have two variables. One with the dollar sign and one without. Like this:

set [money v] to [10.00]
set [money display v] to (join [$] (money))
ikuzduy
Scratcher
100+ posts

How to make a variable with a dollar sign in front of it?

You could use
(join [$] [money])
change money to var

Last edited by ikuzduy (Jan. 13, 2023 03:29:00)

Spentine
Scratcher
1000+ posts

How to make a variable with a dollar sign in front of it?

You have one variable that stores the amount of money. It will be the actual number being changed in the code when you, let's say, buy something, or get more money.

The other variable just serves as a display. It just shows the user how much money they have. Every frame, you can set the display money to the regular amount of money with a dollar sign every frame with this script:

when gf clicked
forever
set [display money v] to (join [$] (money))
wait (0) seconds :: grey // may not be needed
end

Where the display money variable is shown, and the money variable is hidden. This will repeat every frame.

Last edited by Spentine (Jan. 13, 2023 04:28:56)

Powered by DjangoBB