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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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