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

#1 2009-01-09 17:43:18

AlanProjects
Scratcher
Registered: 2008-06-23
Posts: 500+

Help with a VERY complicated algorithm for number input

I need help with this, and it is VERY complicated. If you understand how the decimal number system works(Powers of ten for each "place" including after the decimal point)) could you please look at it(And if not, thanks for looking at this anyway.)? Here it is: http://scratch.mit.edu/projects/AlanProjects/375844

Last edited by AlanProjects (2009-01-09 17:44:38)

Offline

 

#2 2009-01-09 18:17:20

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

Re: Help with a VERY complicated algorithm for number input

Can you explain exactly what it is that your project is supposed to do, and what it is not doing?


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

 

#3 2009-01-09 18:43:16

AlanProjects
Scratcher
Registered: 2008-06-23
Posts: 500+

Re: Help with a VERY complicated algorithm for number input

It is supposed to make you able to input a n-digit positive number into a variable using an array. Down array puts in a decimal point, I forgot to write that.

Offline

 

#4 2009-01-09 18:59:00

AlanProjects
Scratcher
Registered: 2008-06-23
Posts: 500+

Re: Help with a VERY complicated algorithm for number input

It is not properly adding the decimal part of a number. It works by separating out each part of a number, the whole part and the part after the decimal point (The 10^-x where x is the xth digit after the decimal point.) and adding them to a variable by the property of the decimal number system that each number "place" is a  power of 10. For in stance, to convert 10.24, it sees that 10 is the whole part and .2 is the less-than-1 part. It sees that 0 is the first digit in the whole section, so adds 0*(10^0) to the variable. Then it sees the 1 in the next "place", and adds 1*(10*2) . Then in the negative power(less-than-1) part, It sees 2 and adds 2*(10^-1) to the variable(Or is supposed to. This is where the problem is.) then it adds 4*(10^-2). Calculate that, and that is 10.24 . That is what its supposed to do, but in the script for the negative powers, If  "n" or the index variable used to do the powers (10^-1, 10^-2, etc.) and cycle through each element("Place") of the decimal part, equals zero, it looks at item 1 of the decimal part(Its in an array), and multiplies it by 10^(n*-1), which ends up being 0 because n=0. So it adds 0 to the array, when it should add item 1 of the array *-1. Sorry I didn't explain it well enough. This is the longest post i've ever typed.  big_smile

Offline

 

#5 2009-01-09 20:15:37

ScipioBellorum
Scratcher
Registered: 2007-05-15
Posts: 94

Re: Help with a VERY complicated algorithm for number input

I've downloaded your project and had a look at the code. Though the core coding is quite simple, there's lots of other stuff that needed to make it show up properly.

Instead of using the existing code, I've used a different system where by the variable 'Number' is multiplied by 10 and then has the number added to it:

Key 1 pressed
Add 1 to [list] Numbers

When space pressed
Set [var] Number to [var]Number * 10
Add item 1 of [list] Numbers to [var]Number

When the down key is pressed to insert the decimal point, its position is stored even though it is not added to the variable.

So if you put in 123.567 it is stored as 123567 and the decimal's location is 3.

The variable 'Number' is the divided to get it to 123.567. Unfortunately, variables in Scratch are automatically rounded so the only way to store the number properly is in a list.

As well as fixing the error, I've added a decimal places slider and simplified the code. The remixed project can be found here. I have put loads of comments in so you know what all the parts of the script do.

Hope this was of help,

SB


http://img393.imageshack.us/img393/339/logory8.png
                      The word processor for Scratch

Offline

 

#6 2009-01-10 07:40:18

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Help with a VERY complicated algorithm for number input

http://scratch.mit.edu/projects/bhz/370119
Decimals were just added

Offline

 

Board footer