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

#1 2012-04-16 14:25:15

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Linking variable number to a sprite

What is the most efficient way to set a sprite (say I've made sprites of the numbers 0-9 in a cool sci-fi font) to link to a variable, so that when that variable changes from 0 to 1 to 2 etc. the sprite will reflect that number? So, the variable score changes to 1, the sprite will show the number 1?
(basically I'm trying to set up a custom score indicator for my game linked in my signature  using a sprite rather than the default variable box)

Thanks for any help

Last edited by SD7 (2012-04-16 14:25:45)


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#2 2012-04-16 14:41:45

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Linking variable number to a sprite

Probably using this:

forever
switch to costume ((letter (length of (score)) of (score)) + [1]) //+1 so you can include 0
and on another sprite
forever
if <(score) > [9]>
switch to costume ((letter ((length of (score)) - [1]) of (score)) + [1])
end
and another
forever
if <(score) > [99]>
switch to costume ((letter ((length of (score)) - [2]) of (score)) + [1])
end
ect. Use as many sprites as you think you'll need.

Or, if you want to add loads of costumes instead of sprites, use
forever
switch to costume ((score) + [1])

Last edited by Splodgey (2012-04-16 14:43:53)

Offline

 

#3 2012-04-16 14:52:28

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: Linking variable number to a sprite

Do this:

forever
 switch to costume number ((variable))
 

Last edited by mythbusteranimator (2012-04-16 14:52:56)


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#4 2012-04-16 16:07:55

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Linking variable number to a sprite

mythbusteranimator wrote:

Do this:

forever
 switch to costume (variable)
 

Offline

 

#5 2012-04-17 05:48:08

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Linking variable number to a sprite

mythbusteranimator wrote:

Do this:

forever
 switch to costume number ((variable))
 

There will need to be a score of 0.

forever
 switch to costume ((variable) + [1])
 
And anyway I've already said that.

Last edited by Splodgey (2012-04-17 05:48:33)

Offline

 

#6 2012-04-17 09:35:44

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Linking variable number to a sprite

Here is a project I made that uses one sprite with stamping to display the score. However if you want something where each number has an individual sprite, you could try using a project like this one, by Paddle2See.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#7 2012-04-17 12:58:34

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Linking variable number to a sprite

Splodgey: I'm using your example, and it's working beautifully, but I'd like to understand what it's doing exactly, rather than just copying. What is the [letter [length of score] of score] doing?


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#8 2012-04-17 13:14:22

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Linking variable number to a sprite

SD7 wrote:

Splodgey: I'm using your example, and it's working beautifully, but I'd like to understand what it's doing exactly, rather than just copying. What is the [letter [length of score] of score] doing?

That gets the last digit.

Offline

 

#9 2012-04-17 13:19:11

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Re: Linking variable number to a sprite

The last digit of the score? And then by adding [letter of score]-[1] it's getting the second-to-last digit, and so on?


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#10 2012-04-17 13:21:42

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Linking variable number to a sprite

SD7 wrote:

The last digit of the score? And then by adding [letter of score]-[1] it's getting the second-to-last digit, and so on?

Yep.

Offline

 

Board footer