System Digit Checker + Number of Digits Checker

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.
JASS:
local integer OriginalNumber = Whatever You Want
local integer NumOfDigits
local integer Index
local boolean FoundDigits
loop
    exitwhen (FoundDigits == true)
    if (Pow(10,Index) > OriginalNumber then
        set NumOfDigits = Index
        set FoundDigits = true
    endif
    set Index = Index + 1
endloop


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] &gt; NumOfDigits
        call DisplayTextToPlayer(Player(0),0.00,0.00,(&quot;Digit #&quot; + I2S(Index[3]) + &quot; is &quot; + (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.
 
> StringLength(I2S(<number>)),
SubString(I2S(<number>),i,i + 1).

Can we say here: "omfg, Ace did it again !" ?

Just a cosmetic thing:
JASS:
local integer OriginalNumber = Whatever You Want
local integer NumOfDigits
local integer Index
local boolean FoundDigits
loop
    exitwhen (FoundDigits == true)
    if (Pow(10,Index) &gt; OriginalNumber then
        set NumOfDigits = Index
        set FoundDigits = true
    endif
    set Index = Index + 1
endloop

can be:
JASS:
local integer OriginalNumber = Whatever You Want
local integer NumOfDigits
local integer Index
local boolean FoundDigits
loop
    if (Pow(10,Index) &gt; OriginalNumber then
        set NumOfDigits = Index
        exitwhen true
    endif
    set Index = Index + 1
endloop

Your code is useful but Ace knows so much.
 
Digit checker wasn't the important part however, I just ran into a problem and realized I needed to know the amount of digits.
And as par usual I thought way too much.
As for the exitwhen true thing, I never really knew I could do that. I guess it would be the same as putting exitwhen after then and doing exitwhen 1 == 1 lol
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top