Matematical Isolation of Individual Numbers within other numbers

2evil

New Member
Reaction score
16
Sorry for the long title, but it kind of explains what I need help with.

Usually I could work something like this out on my own, but my ADD had been goin crazy recently and i just cant concentrate on all the numbers that well :(

So heres my problem: I need to isolate single digits within a number within one trigger. If the original number is 1020043 (7 numbers long), I need to set variable[loop a]=digit [a] of the number

ex. [loop a]=3, number=1020043, set variable[loop a]=digit[a]
set variable[3]=2 (1020043)

I've done this type of thing before, using modulos and that sort, but todays not my day :(

thanks,
2evil
 

hi_im_bob

......and you are?
Reaction score
44
Cant you just use the substrings (or something like that)

For Each Integer A:
Set loop[integer A] equal to substring integer A of (where # is coming from)

Something like that sorry dont have WE open.
 

2evil

New Member
Reaction score
16
theres only substring functions for strings and converting an integer to a string to an integer to a string again doesnt work too well. Heres the makeshift trigger doing that i made

Code:
Set Temp_Materials_A[Temp_value_2] = (Temp_Materials_A[Temp_value_2] + ((Integer((Substring((String(Item_Codes[(Integer B)])), Temp_value_2, Temp_value_2)))) x (Charges remaining in (Item carried by (Casting unit) in slot (Integer A)))))
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Set Number = 1234567
Set Length = Length of (String(Number))
For each Integer A from 0 to (Length - 1), do
- Set TempInteger = Number / 10
- Set Array[Length - Integer A] = Number - (10 x TempInteger)
- Set Number = TempInteger


After that loop:
Array[1] = 1
Array[2] = 2
...
Array[Length] = 7



If you prefer a less mathematical way, simply loop through the string of that number and use "conversion - convert string to integer" on the individual characters.


Then again, what that thing in post #3 is supposed to be... no idea.
 

2evil

New Member
Reaction score
16
I tried the string method above, but was kinda hazy about it

Code:
Set Temp_Materials_A[Temp_value_2][b]original value[/b] = (Temp_Materials_A[Temp_value_2][b]original value[/b] + (([b]conver string to [/b]Integer((Substring(([b]convert integer to [/b]String(Item_Codes[(Integer B)])), Temp_value_2 [b]extracting only digit temp_value_2[/b], Temp_value_2))))

And I don't quite get what you mean for the mathematical method. Can you please explain it more?
Thanks :)
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
For each Integer A from 1 to Length of <string>, do
- Set Array[ Integer A ] = Convert string to integer ( Substring(<string>, Integer A, Integer A) )

That would be the "string" method.

If you prefer heavy calculations involving actual numbers, refer to post #4.


The mystery line you're repeating here does:
Set Array[ Index ] = Array[ Index ] + <new digit>

Why is it adding it?
According to post #1, the array should hold one digit per value...
 
Z

Zell

Guest
You mean you want to search an entered string for a certain number and find its position in the string? I think that's what you need, but here's my best shot anyways:
Code:
Events
    Player - Player 1 (Red) types a chat message containing - as A substring
Conditions
Actions
    For each (Integer A) from 2 to (Length of (Entered chat string)), do (Actions)
        Loop - Actions
            Set Integer_Value[Integer A] = (Substring((Entered chat string), (Integer A), (Integer A))
    For each (Integer B) from 2 to (Length of (Entered chat string)), do (Actions)
        Loop - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    NumberYouWant = Integer_Value[Integer B]
                Then - Actions
                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        If - Conditions
                            PositionYouWant = Integer B
                        Then - Actions
                            <Do what you want>
                        Else - Actions
                Else - Actions
Basically this sets every character in the entered string (except the hyphen at the start) to it's own variable, then checks if any of them are equal to the number you want. It then checks that the number you want is in the position you want it. So let's say we want a 3 (NumberYouWant) in position 2 (PositionYouWant) of the string (I.E -311 would do it). The trigger sets 3 to spot 2, 1 to spot 3 and 1 to spot 4; all in Integer_Value. It then says "Are any of these equal to NumberYouWant (= 3)?". When it finds that Integer_Value[2] = 3, it says "Is it in the spot I want it?". Then it finds that Integer_Value[2], which equals 3 (= NumberYouWant), has the number you want in the position of its array number, which is 2.

I hope this works.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top