This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-05-15 08:16:40

Payphone
Scratcher
Registered: 2010-05-15
Posts: 3

Show variable placement

Does anybody know a way to fix the position on the screen of where a variable's value is when it is shown? I need my variables to appear in particular places, but every time I reload the file in scratch, the variables default to their position at the top left corner of the presentation screen.

Any help would be greatly appreciated.

Offline

 

#2 2010-05-15 10:47:19

Payphone
Scratcher
Registered: 2010-05-15
Posts: 3

Re: Show variable placement

If this doesn't work, is there a way to get a sprite to display a variable without "saying" or "thinking" the value? Thanks

Offline

 

#3 2010-05-15 10:53:07

Wolfie1996
Retired Community Moderator
Registered: 2009-07-08
Posts: 1000+

Re: Show variable placement

Ah - when you save or upload, the variables must be showing, otherwise they move. You can always get them to hide on startup, but be showing before the green flag is clicked.

To display variables a different way (only applies when there is a limited amount of possible values) you could give a sprite costumes with each possible value written on, then add a script like this:
[blocks]

<switch to costume[ (( <{ variable }> <+> put a number here if wanted ))

[/blocks]

Hope this helps!  big_smile

Last edited by Wolfie1996 (2010-05-15 10:53:29)


"...Jargon - the practice of never calling a spade a spade, when you might instead call it a manual earth-restructing implement..." - Bill Bryson, Mother Tongue

Offline

 

#4 2010-05-15 11:01:04

Payphone
Scratcher
Registered: 2010-05-15
Posts: 3

Re: Show variable placement

Thanks for that, disappointing but not particularly surprising. I will see if I can be bothered to put in all the extra code to make it so the variable display where I need them to, when I need them to!

Offline

 

#5 2010-05-15 11:01:30

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Show variable placement

Well, you can always try using sprites to display your variable. There are two ways to display a variable using sprites. The first one involves stamping:

Make a sprite which has 10 costumes, each one is a number. The numbers should be in this order: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Then, make a variable for each place you want. If your variable only goes up to 100, you'll need 3 variables, if it goes up to 1000, you'll need 4, and so forth. Name them "hundreds" "tens" "ones," etc.

Then, use this script to determine the values of these variables:

set (place) to (round ( ( ( ( variableToBeShown ) mod ( place * 10 ) ) / (place) ) + ( 0.5 ) )

For example, for thousands, we would do:

set (thousands) to (round ( ( ( ( variableToBeShown ) mod ( 10000 ) ) / ( 1000 ) ) + (0.5)

Do this for every place down to "ones." The value of the variables is the place value, so if the value of the variable I wanted to print out were 4277, the above code would return "4" because that's the thousands place.

Then, make your sprite go to where you want the variable to start. Make it switch to the costume of the variable for that place, then stamp, then move enough pixels to the left to make room for the next place, stamping it again. After it's printed the number out, clear it.

Method number 2: You can achieve the same effect by making a sprite for each place, and then setting their costume to the place.

Offline

 

Board footer