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

#1 2008-03-27 20:53:48

sausagestand
Scratcher
Registered: 2007-08-30
Posts: 34

hard

if you have a 2 digit variable, and you want to split it up to 2 different numbers, like for example 37, and you wanna split it into 3, and 7, is there a code to do that for any 2 digit #? O_O

Offline

 

#2 2008-03-28 02:50:49

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: hard

You can do it using the "mod" block to give you remainders.

xx mod 10 gives you the remainder when XX is divided by 10 - which will be the units.

(xx - (xx mod 10) ) / 10 will give you the 10s.

(by subtracting the units first, instead of using mod 100, you avoid rounding errors)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

Board footer