Trouble with IF statement

Zalinian

New Member
Reaction score
0
For some reason jass doesn't like multiple IF statements next to each other if they involve similar comparison types. I can't seem to get this working properly. Can anyone fix this or does anyone know of a better way to split a number's digits(ex: 1234 would become 1, 2 ,3 ,4 with each set to its own variable. This way I can measure ones, tens, hundreds, thousands, etc)

This my coding for a bonus system btw. Once the abilities are set up, simply call the function with the target unit, the number, and the bonus type (damage, armor, etc) and bam. Currently only damage is added in. It's also set to cap at 9999.

JASS:
//          Bonus System
function bonus_add takes unit target, integer bonus_num, string bonus_type returns nothing
    local integer num
    local integer thousand
    local integer hundred
    local integer ten
    local integer one
    local integer array skill
    if bonus_type == "damage" then
        set skill[1] = 'A00U'
        set skill[2] = 'A00V'
        set skill[3] = 'A00P'
        set skill[4] = 'A00I'
    endif
    if bonus_num < 10000 then
        set num = bonus_num
        if num >= 1000 then
            set thousand = num / 1000
            set num = num - (thousand * 1000)
        endif
        if num >= 100 then
            set hundred = num / 100
            set num = num - (hundred * 100)
        endif
        if num >= 10 then
            set ten = num / 10
            set num = num - (ten * 10)
        endif
        if num >= 1 then
            set one = num / 1
            set num = num - (one * 1)
        endif
    else
        set thousand = 9
        set hundred = 9
        set ten = 9
        set one = 9
    endif
    call BJDebugMsg(I2S(thousand))
    call BJDebugMsg(I2S(hundred))
    call BJDebugMsg(I2S(ten))
    call BJDebugMsg(I2S(one))
    if thousand > 0 then
        call UnitAddAbility(target, skill[4])
        call SetUnitAbilityLevel(target, skill[4], thousand)
        call UnitMakeAbilityPermanent(target, true, skill[4])
    endif
    if hundred > 0 then
        call UnitAddAbility(target, skill[3])
        call SetUnitAbilityLevel(target, skill[3], hundred)
        call UnitMakeAbilityPermanent(target, true, skill[3])
    endif
    if ten > 0 then
        call UnitAddAbility(target, skill[2])
        call SetUnitAbilityLevel(target, skill[2], ten)
        call UnitMakeAbilityPermanent(target, true, skill[2])
    endif
    if one > 0 then
        call UnitAddAbility(target, skill[1])
        call SetUnitAbilityLevel(target, skill[1], one)
        call UnitMakeAbilityPermanent(target, true, skill[1])
    endif
endfunction
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Looks fine to me... I don't see where it would error (but then again, it's late and I'm tired, and I may have missed something...)
 

ZugZugZealot

New Member
Reaction score
33
There's a shortcut you can use for that via substrings.

Something like this
JASS:
function bonus_add takes unit target, integer bonus_num, string bonus_type returns nothing
    local string skillParse = " " + I2S(bonus_num)
    local string tempChar
    local integer tempInteger
    local integer array skill
    local integer i
    
    if bonus_type == "damage" then
        set skill[1] = 'A00U'
        set skill[2] = 'A00V'
        set skill[3] = 'A00P'
        set skill[4] = 'A00I'
    endif
    
    if StringLength(skillParse) < 6 then
        set i = 4
        loop
            exitwhen i < 1
            set tempChar = SubString( skillParse, i, i + 1 )
            if tempChar != null then
                set tempInteger = S2I(tempChar)
                if tempInteger > 0 then
                    call UnitAddAbility(target, skill[5 - i])
                    call SetUnitAbilityLevel(target, skill[5 - i], tempInteger)
                    call UnitMakeAbilityPermanent(target, true, skill[5 - i])
                endif
            endif
            set i = i - 1
        endloop
    else
        set i = 1
        loop
            exitwhen i > 4
            call UnitAddAbility(target, skill<i>)
            call SetUnitAbilityLevel(target, skill<i>, 9)
            call UnitMakeAbilityPermanent(target, true, skill<i>)
            set i = i + 1
        endloop
    endif
    set tempChar = null
endfunction</i></i></i>
 

Zalinian

New Member
Reaction score
0
It saves fine, it just doesn't work correctly. It won't register a number unless its over 1000.
 

ZakkWylde-

New Member
Reaction score
14
I have no actual basis for this recommendation other than my logic/math intuition.

change the if statements so that one number does not (potentially) fall under all 4 if commands...I know it sounds stupid...but hey =D

i.e.

JASS:
if 10000 &gt; num &gt;= 1000 then
            set thousand = num / 1000
            set num = num - (thousand * 1000)
        endif
        if 1000 &gt; num &gt;= 100 then
            set hundred = num / 100
            set num = num - (hundred * 100)
        endif
        if 100 &gt; num &gt;= 10 then
            set ten = num / 10
            set num = num - (ten * 10)
        endif
        if 10 &gt; num &gt;= 1 then
            set one = num / 1
            set num = num - (one * 1)
        endif


Let me know if it works...I'd be interested to see...
(also, I'm not sure about writing inequalities in JASS...if you can do it the way I did...worst comes to worst, have [ljass]1000> num and num >=100[/ljass])

re-EDIT: Hrmm--ignore everything I wrote above...lemme try and find a way to do this for you (if you'd prefer a raw integer comparison of sorts to ZUGZUG's trigger...). I love a problem like this (YAY MATH!)
EDIT#2: PROBLEM SOLVED =D Below...
 

ZakkWylde-

New Member
Reaction score
14
JASS:
function Trig_Math_Actions takes nothing returns nothing
    local integer thousand
    local integer hundred
    local integer ten
    local integer one
    local integer random 
    set random = GetRandomInt(1, 12000)
    call BJDebugMsg(I2S(random))
    if random &lt; 10000 then
        set thousand = (random / 1000)
        set hundred = ((random - (thousand*1000)) / 100)
        set ten = (((random - (thousand*1000)) - (hundred*100)) / 10)
        set one = (((random - (thousand*1000)) - (hundred*100)) - (ten*10)) //if you want to be classy, 
        //you can divide all of it by 1 (to be consistent xD)
        call BJDebugMsg(I2S(thousand))
        call BJDebugMsg(I2S(hundred))
        call BJDebugMsg(I2S(ten))
        call BJDebugMsg(I2S(one))
    endif
endfunction

//===========================================================================
function InitTrig_Math takes nothing returns nothing
    set gg_trg_Math = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Math, 3, true)
    call TriggerAddAction( gg_trg_Math, function Trig_Math_Actions )
endfunction


There you go...if you run the trigger...every 3 seconds you'll see (i'll give examples)

1450
1
4
5
0
----
9009
9
0
0
9
----
3076
3
0
7
6
----
10
0
0
1
0

Hopefully this is exactly what you wanted =D. If the parentheses really bother you, I'm sure there's a way you could remove a few...but I didn't bother--I went overboard with the parentheses to know exactly what was going first (even if order of operations tells me anyways).
 

Zalinian

New Member
Reaction score
0
Yea I was just thinking of the same setup. I was about to test it without any IF statements.

EDIT: Yea it works perfectly. thanks for the input.

Final Code:
JASS:
//          Bonus System
function bonus_add takes unit target, integer bonus_num, string bonus_type returns nothing
    local integer num
    local integer thousand
    local integer hundred
    local integer ten
    local integer one
    local integer array skill
    if bonus_type == &quot;damage&quot; then
        set skill[1] = &#039;A00U&#039;
        set skill[2] = &#039;A00V&#039;
        set skill[3] = &#039;A00P&#039;
        set skill[4] = &#039;A00I&#039;
    endif
    if bonus_num &lt; 10000 then
        set num = bonus_num
        set thousand = num / 1000
        set num = num - (thousand * 1000)
        set hundred = num / 100
        set num = num - (hundred * 100)
        set ten = num / 10
        set num = num - (ten * 10)
        set one = num / 1
        set num = num - (one * 1)
    else
        set thousand = 9
        set hundred = 9
        set ten = 9
        set one = 9
    endif
    //call BJDebugMsg(I2S(thousand))
    //call BJDebugMsg(I2S(hundred))
    //call BJDebugMsg(I2S(ten))
    //call BJDebugMsg(I2S(one))
    if thousand &gt; 0 then
        call UnitAddAbility(target, skill[4])
        call SetUnitAbilityLevel(target, skill[4], thousand)
        call UnitMakeAbilityPermanent(target, true, skill[4])
    endif
    if hundred &gt; 0 then
        call UnitAddAbility(target, skill[3])
        call SetUnitAbilityLevel(target, skill[3], hundred)
        call UnitMakeAbilityPermanent(target, true, skill[3])
    endif
    if ten &gt; 0 then
        call UnitAddAbility(target, skill[2])
        call SetUnitAbilityLevel(target, skill[2], ten)
        call UnitMakeAbilityPermanent(target, true, skill[2])
    endif
    if one &gt; 0 then
        call UnitAddAbility(target, skill[1])
        call SetUnitAbilityLevel(target, skill[1], one)
        call UnitMakeAbilityPermanent(target, true, skill[1])
    endif
endfunction

And the remove one:
JASS:
function bonus_remove takes unit target, string bonus_type returns nothing
    local integer array skill
    local integer start
    local integer end
    if bonus_type == &quot;damage&quot; then
        set skill[1] = &#039;A00U&#039;
        set skill[2] = &#039;A00V&#039;
        set skill[3] = &#039;A00P&#039;
        set skill[4] = &#039;A00I&#039;
    endif
    set start = 1
    loop
        exitwhen start &gt; end
        call UnitRemoveAbility(target, skill[start])
        set start = start + 1
    endloop
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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