Problem keeping numbers numbers

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Problem keeping numbers numbers

Post by Nathnem »

This code block works fine until it gets passed a decimal, then it produces the error:
Illegal argument type java.lang.String, expecting java.math.BigDecimal

I’m pretty sure that the decimal is causing the var [r: exp = listGet( x, 1, ":")] to register as a string but I can’t find anything on forcing the var to register as a number.

Code: Select all

[r, MACRO("Skills@Lib:DoH"): Skills + ', 0, Admin, 0']
[h: Skills = macro.return]
(This should be all the code relevant to the problem default section.)

Code: Select all

[h: Parameter = macro.args]
[h: skillList = listGet(Parameter, 0)]
…
…
[r, switch(listGet(Parameter, 1)), CODE:
…
…
default: 
{
    [h: newList = '']
    [h: nRoll = (1d10 + (listGet( Parameter, 3) * 10)) / 100]
    [h: tmpList = listGet(skillList, listGet(Parameter, 1), "~*~")]
    [r, foreach( x, tmpList, "", "~"), CODE: 
    {
        [r: exp = listGet( x, 1, ":")]
        [r: exp = exp + nRoll]
        [h: newList = newList + if( newList == "", '', '~ ') + if( listGet( x, 0, ":") == listGet(Parameter, 2), listReplace( x, 1, if( listGet( x, 1, ":") < listGet(Parameter, 3), listGet(Parameter, 3), exp), ":"), x)]
    }]
    [h: skillList = listReplace( skillList, listGet(Parameter, 1), newList, "~*~")]
}]

[h: macro.return = skillList]
Full Function
Spoiler

Code: Select all

[h: Parameter = macro.args]
[h: skillList = listGet(Parameter, 0)]

[h: EducationalList = '
Admin~ Advocate~ Animals (Veterinary)~ Art (Preformer)~ Art (Holography)~ Art (Instrument)~ Art (Visual Media)~ Art (Write)~
Diplomat~
Electronics (Comms.)~ Electronics (Computers)~ Electronics (Remote Ops.)~ Electronics (Sensors)~
Engineer (Basic Systems)~ Engineer (Advanced Systems)~ Engineer (Power Plants)~ Engineer (M-Drives)~ Engineer (J-Drive)~
Engineer (H-Drive)~ Engineer (W-Drive)~ Engineer (A-Drive)~ Engineer (G-Drive)~ Engineer (S-Drive)~ Engineer (T-Drive)~
Investigate~
Math~ Mechanic~ Medic~
Science (Archaeology)~ Science (Astronomy)~ Science (Biology)~ Science (Botany)~ Science (Chemistry)~ Science (Cybernetics)~ Science (Economics)~ Science (Genetics)~ Science (History)~ Science (Magicology)~ Science (Psionicology)~ Science (Psychology)~ Science (Robotics)~ Science (Sophontology)~ Science (Xenology)~
Survival~
Tactics (Army)~ Tactics (Air Force)~ Tactics (Naval)~ Tactics (Gorilla)']

[h: SocialList = '
Animals (Handling)~ Animals (Training)~ Athletics (Dexterity)~ Athletics (Endurance)~ Athletics (Strength)~
Broker~
Carouse~
Deception~
Gambler~
Leadership~
Persuasion~ Perception~ Profession~
Recon~
Seduction~ Stealth~ Stewardship~ Streetwise~ Studied (Intellect)~ Studied (Will Power)~ Studied (Social Std.)']

[h: CombatList = '
Explosives~
Gunner (Capital)~ Gunner (Ortillery)~ Gunner (Screen)~ Gunner (Turret)~
Gun Combat (Archaic)~ Gun Combat (Slug)~ Gun Combat (Energy)~ Gun Combat (Plasma)~ Gun Combat (Thata)~ Gun Combat (Magical)~
Heavy Wpns (Artillery)~ Heavy Wpns (Man-Port.)~ Heavy Wpns (Vehicle)~
Melee (Angelic)~ Melee (Blade)~ Melee (Bludgeon)~ Melee (Demonic)~ Melee (Energy)~ Melee (Magical)~ Melee (Natural)~ Melee (Unarmed)']

[h: TransportList = '
Astrogation~
Navigation~
Drive (Hovercraft)~ Drive (Mole)~ Drive (Tracked)~ Drive (Walker)~ Drive (Wheeled)~ 
Flyer (Airship)~ Flyer (Grav)~ Flyer (Ornithopter)~ Flyer (Rotor)~ Flyer (Wing)~
Seafarer (Ocean Ships)~ Seafarer (Personal)~ Seafarer (Sail)~ Seafarer (Submarine)~
Pilot (Class A)~ Pilot (Class B)~ Pilot (Class C)~ Pilot (Class D)~
Vacc Suit']



[r, switch(listGet(Parameter, 1)), CODE:
case "build": 
{
    [h: skillList = '']
    [h: x = listCount(EducationalList, "~")]
    [h, for(i, 0, x, +1, ""): skillList = skillList + if(i == 0, '', '~ ') + listGet(EducationalList, i, "~") + ': -3']
    [h: skillList = skillList + "~*~"]
    [h: x = listCount(SocialList, "~")]
    [h, for(i, 0, x, +1, ""): skillList = skillList + if(i == 0, '', '~ ') + listGet(SocialList, i, "~") + ': -3']
    [h: skillList = skillList + "~*~"]
    [h: x = listCount(CombatList, "~")]
    [h, for(i, 0, x, +1, ""): skillList = skillList + if(i == 0, '', '~ ') + listGet(CombatList, i, "~") + ': -3']
    [h: skillList = skillList + "~*~"]
    [h: x = listCount(TransportList, "~")]
    [h, for(i, 0, x, +1, ""): skillList = skillList + if(i == 0, '', '~ ') + listGet(TransportList, i, "~") + ': -3']
    
};
case "check":
{
    [h: Checked = 0]
    
    [h: ctFound = 0]
    [h: tmpList = listGet(skillList, 0, "~*~")]
    [h, if (listCount(tmpList, "~") >= listCount(EducationalList, "~")), CODE:
    {
       [h: List1 = tmpList]
       [h: List2 = EducationalList]
       [h: Diff = 'Extra ']
    };
    {
       [h: List2 = tmpList]
       [h: List1 = EducationalList]
       [h: Diff = 'Missing ']
    }]
        
    [r, foreach( ck, List1, "", "~"), CODE:
    {
        [h: Found = 0]
        [h, for( i, 0, listCount(List2, "~")): Found = if( listGet(ck, 0, ":") == listGet( listGet(List2, i, "~"), 0, ":"), 1, Found)]
        [r: if( Found == 0, Diff + 'educational skill found: ' + listGet(ck, 0, ":") + '<br>', '')]
        [h: ctFound = if( Found == 0, ctFound, ctFound + 1)]
    }]
    [h: Checked = if( ctFound == listCount( List1, "~"), Checked +1, Checked)]
    
    
    
    [h: ctFound = 0]
    [h: tmpList = listGet(skillList, 1, "~*~")]
    [h, if (listCount(tmpList, "~") >= listCount(SocialList, "~")), CODE:
    {
       [h: List1 = tmpList]
       [h: List2 = SocialList]
       [h: Diff = 'Extra ']
    };
    {
       [h: List2 = tmpList]
       [h: List1 = SocialList]
       [h: Diff = 'Missing ']
    }]
        
    [r, foreach( ck, List1, "", "~"), CODE:
    {
        [h: Found = 0]
        [h, for( i, 0, listCount(List2, "~")): Found = if( listGet(ck, 0, ":") == listGet( listGet(List2, i, "~"), 0, ":"), 1, Found)]
        [r: if( Found == 0, Diff + 'social skill found: ' + listGet(ck, 0, ":") + '<br>', '')]
        [h: ctFound = if( Found == 0, ctFound, ctFound + 1)]
    }]
    [h: Checked = if( ctFound == listCount( List1, "~"), Checked +1, Checked)]
    
    
    
    
    [h: ctFound = 0]
    [h: tmpList = listGet(skillList, 2, "~*~")]
    [h, if (listCount(tmpList, "~") >= listCount(CombatList, "~")), CODE:
    {
       [h: List1 = tmpList]
       [h: List2 = CombatList]
       [h: Diff = 'Extra ']
    };
    {
       [h: List2 = tmpList]
       [h: List1 = CombatList]
       [h: Diff = 'Missing ']
    }]
        
    [r, foreach( ck, List1, "", "~"), CODE:
    {
        [h: Found = 0]
        [h, for( i, 0, listCount(List2, "~")): Found = if( listGet(ck, 0, ":") == listGet( listGet(List2, i, "~"), 0, ":"), 1, Found)]
        [r: if( Found == 0, Diff + 'combat skill found: ' + listGet(ck, 0, ":") + '<br>', '')]
        [h: ctFound = if( Found == 0, ctFound, ctFound + 1)]
    }]
    [h: Checked = if( ctFound == listCount( List1, "~"), Checked +1, Checked)]
    
    
    
    
    [h: ctFound = 0]
    [h: tmpList = listGet(skillList, 3, "~*~")]
    [h, if (listCount(tmpList, "~") >= listCount(TransportList, "~")), CODE:
    {
       [h: List1 = tmpList]
       [h: List2 = TransportList]
       [h: Diff = 'Extra ']
    };
    {
       [h: List2 = tmpList]
       [h: List1 = TransportList]
       [h: Diff = 'Missing ']
    }]
        
    [r, foreach( ck, List1, "", "~"), CODE:
    {
        [h: Found = 0]
        [h, for( i, 0, listCount(List2, "~")): Found = if( listGet(ck, 0, ":") == listGet( listGet(List2, i, "~"), 0, ":"), 1, Found)]
        [r: if( Found == 0, Diff + 'transportation skill found: ' + listGet(ck, 0, ":") + '<br>', '')]
        [h: ctFound = if( Found == 0, ctFound, ctFound + 1)]
    }]
    [h: Checked = if( ctFound == listCount( List1, "~"), Checked +1, Checked)]
    
    [r: if( Checked == 4, 'All skills check out.', '')]
    
};

default: 
{
    [h: newList = '']
    [h: nRoll = (1d10 + (listGet( Parameter, 3) * 10)) / 100]
    [h: tmpList = listGet(skillList, listGet(Parameter, 1), "~*~")]
    [r, foreach( x, tmpList, "", "~"), CODE: 
    {
        [r: exp = listGet( x, 1, ":")]
        [r: exp = exp + nRoll]
        [h: newList = newList + if( newList == "", '', '~ ') + if( listGet( x, 0, ":") == listGet(Parameter, 2), listReplace( x, 1, if( listGet( x, 1, ":") < listGet(Parameter, 3), listGet(Parameter, 3), exp), ":"), x)]
    }]
    [h: skillList = listReplace( skillList, listGet(Parameter, 1), newList, "~*~")]
}]

[h: macro.return = skillList]

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Problem keeping numbers numbers

Post by wolph42 »

did you isolate the line and ran it separately in a macro so you can check whether that's *actually* causing the issue? Or have you used e.g. 'pause()' to isolate the line where the execution fails? If not than I would suggest to check out the if() statement, which would be my guess.

To answer your question directly: number

Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Re: Problem keeping numbers numbers

Post by Nathnem »

No I have not confirmed that is the issue, just my best guess based on its behavior. I'll look into the Pause() function. Are you referring to the statement if( listGet( x, 0, ":") == ... I can't find a syntax error so am I just blind or is it too many pointers and function calls for one line.

Also Thank you for the direct answer as well as your experienced insight.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Problem keeping numbers numbers

Post by wolph42 »

its proby not a syntax error but a iist not setup correctly, without isolaton its hard to tell. Check out the debug article linked in my sig, to get knowledgeable about debugging maptool script.

Nathnem
Kobold
Posts: 7
Joined: Sat May 27, 2017 3:12 pm

Re: Problem keeping numbers numbers

Post by Nathnem »

Ok this just gets more confusing. pause tells me that exp = 0.50 (For the first cycle), Parameter 3 = 0, and listGet( x, 0, ":") = 0.4 . Not sure if the additional 0 on exp signifies a string or a remnant of math so I added number() which only get rid of the extra 0 and not the error.

The lists look fine it pulls the correct value out of the parameters and the skill list, and exp is a rand num. I do all my coding out of np++ and all the lists (with the obvious exception of Parameters) are built in this function if that helps (See Spoiler). The error defiantly occurs in the [h: newList = ...

After tearing apart the if newLine statement I finally found the problem, I was apparently overloading the nested if statement. It couldn't handle getting both sides and still compare a decimal. As soon as I dedicated the var Opt1 to the decimal for the comparison it had no problem.

Thank you again for all of your wonderful assistance Wolph42.

And for any others that are following or may stumble across this in the future, here is a copy of the working default section of this function.

Code: Select all

default: 
{
    [h: newList = '']
    [h: nRoll = (1d10 + (listGet( Parameter, 3) * 10)) / 100]
    [h: tmpList = listGet(skillList, listGet(Parameter, 1), "~*~")]
    [h, foreach( x, tmpList, "", "~"), CODE: 
    {
        [h: Opt1 = listGet( x, 1, ":")]
        [h: newList = newList + if( newList == "", '', '~ ') + if( listGet( x, 0, ":") == listGet(Parameter, 2), listReplace( x, 1, if( Opt1 < listGet(Parameter, 3), listGet(Parameter, 3), Opt1 + nRoll), ":"), x)]
    }]
    [h: skillList = listReplace( skillList, listGet(Parameter, 1), newList, "~*~")]
}]

Post Reply

Return to “Macros”