elmstfreddie
The Finglonger
- Reaction score
- 203
Something I use in the digit checker is a loop that checks how many digits are in a number.
This will find the individual digits in a number (integer only at the time, but I guess the same method would work for reals too, but the loop would have to go into negatives)
OriginalNumber will be lost at the end since you subtract things, but this can easily be fixed by either having 2 separate variables (one for original, one for editing and getting digits from)
To retrieve the digits, just add them together after multiplying them by 10^([index] - 1), as seen when subtracting the digit from OriginalNumber.
This could be useful for scattering digits in a number throughout a save/load, then you can find them, multiply them by the power, and adding them all together.
JASS:
This will find the individual digits in a number (integer only at the time, but I guess the same method would work for reals too, but the loop would have to go into negatives)
JASS:
function FindDigits takes nothing returns nothing
local integer OriginalNumber = 28929163 //Random number for you to test!
local integer NumOfDigits = 1
local integer array Digits
local integer array Index
local boolean FoundDigits = false
set Index[1] = 1
set Index[3] = 1
loop
exitwhen (FoundDigits == true)
if (Pow(10,Index[1])) > OriginalNumber then
set NumOfDigits = Index[1]
set FoundDigits = true
endif
set Index[1] = Index[1] + 1
endloop
set Index[2] = NumOfDigits
loop
exitwhen Index[2] == 0
set Digits[Index[2]] = (R2I(OriginalNumber / (Pow(10,(Index[2] - 1)))))
set OriginalNumber = (OriginalNumber - (Digits[Index[2]] * R2I(Pow(10,((Index[2] - 1))))))
set Index[2] = Index[2] - 1
endloop
loop //This loop is unnecessary, it only displays the digits 1 by 1 so you can see it works <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" />
exitwhen Index[3] > NumOfDigits
call DisplayTextToPlayer(Player(0),0.00,0.00,("Digit #" + I2S(Index[3]) + " is " + (I2S(Digits[Index[3]]))))
set Index[3] = Index[3] + 1
endloop
endfunction
OriginalNumber will be lost at the end since you subtract things, but this can easily be fixed by either having 2 separate variables (one for original, one for editing and getting digits from)
To retrieve the digits, just add them together after multiplying them by 10^([index] - 1), as seen when subtracting the digit from OriginalNumber.
This could be useful for scattering digits in a number throughout a save/load, then you can find them, multiply them by the power, and adding them all together.