[1.4 BUG - Resolved] switch

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
User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

[1.4 BUG - Resolved] switch

Post by wolph42 »

Im probly overseeing something massively in my face...

Here's the code:

Code: Select all

[h:'<!-- ------------------------------------ addBevel() ------------------------------------------------- -->']
[h:dungeon    = getLibProperty("DB3.dungeon","lib:DB3Test")]
[h:Field    = getLibProperty("DB3.tField","lib:DB3Test")]

[h,foreach(tile, Field), CODE:{
    <!-- create x and y coord of current Centre -->
    [coord    = json.get(dungeon, roll.count)]
    [varsFromStrProp(json.toStrProp(coord))]
    
    <!-- turn tile into separate variables -->
    [varsFromStrProp(replace(
        tile,
        "t(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
        "E=\$1;NE=\$2;N=\$3;NW=\$4;W=\$5;SW=\$6;S=\$7;SE=\$8;"
    ))]

    <!-- EAST EDGE CHECK -->
    [test="t"+SE+E+NE]
    [switch(test), CODE:
        case "t000":{
            <!-- EV -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
        };
        case "t001":{
            <!-- EV CO(S) -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord,"useDistance",0,facing,-90))]

        };
        case "t010":{
            <!-- EV CO(N) -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord, "y", json.get(coord,"y")-1,"useDistance",0,facing,0))]

        };
        case "t011":{
            <!-- EV CO CO -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,-90))]
            [copyToken("bevelCO",1,"",json.set(coord, "y", json.get(coord,"y")-1,"useDistance",0,facing,0))]

        };
        default{<!-- ignore -->}
    ]

    <!-- NORTH EAST CORNER CHECK --><!-- IC ONLY --> 
    [h,if(NE+N+NW == 0): copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,??))]

    <!-- OTHER SIDES TO BE DONE LATER AFTER THOROUGHT TESTING -->
    [r:"t"+N+NW+W]
    [r:"t"+NW+W+SW]
    [r:"t"+W+SW+S]
    [r:"t"+SW+S+SE]
    [r:"t"+S+SE+E]

}] 
with the following error

Code: Select all

2016-05-21 16:36:04,286 [client.MapToolLineParser:1265] DEBUG - '<!-- ------------------------------------ addBevel() ------------------------------------------------- -->'
2016-05-21 16:36:04,288 [client.MapToolLineParser:1265] DEBUG - dungeon    = getLibProperty("DB3.dungeon","lib:DB3Test")
2016-05-21 16:36:04,288 [client.MapToolLineParser:1265] DEBUG - Field    = getLibProperty("DB3.tField","lib:DB3Test")
2016-05-21 16:36:04,288 [client.MapToolLineParser:1265] DEBUG - Field
2016-05-21 16:36:04,303 [client.MapToolLineParser:1265] DEBUG - coord    = json.get(dungeon, roll.count)
2016-05-21 16:36:04,377 [client.MapToolLineParser:1265] DEBUG - varsFromStrProp(json.toStrProp(coord))
2016-05-21 16:36:04,393 [client.MapToolLineParser:1265] DEBUG - varsFromStrProp(replace(
        tile,
        "t(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
        "E=\$1;NE=\$2;N=\$3;NW=\$4;W=\$5;SW=\$6;S=\$7;SE=\$8;"
    ))
2016-05-21 16:36:04,393 [client.MapToolLineParser:1265] DEBUG - test="t"+SE+E+NE
2016-05-21 16:36:04,393 [client.MapToolLineParser:1265] DEBUG - test
2016-05-21 16:36:04,408 [client.MapToolLineParser:1265] DEBUG - 
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]

        
2016-05-21 16:36:04,408 [client.MapToolLineParser:1280] DEBUG - net.rptools.parser.ParserException: line 1:25: unexpected char: '['
 
what the hell am I missing?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.4 BUG?] switch

Post by aliasmask »

What's this:

[h,if(NE+N+NW == 0): copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,??))]

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.4 BUG?] switch

Post by aliasmask »

You may want to verify the data in coord when you set it as well. Make sure it's a json object.

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

Re: [1.4 BUG?] switch

Post by wolph42 »

aliasmask wrote:What's this:

[h,if(NE+N+NW == 0): copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,??))]
Thnx overlooked that one might be the cause. Did check the coord , it's a json

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

Re: [1.4 BUG?] switch

Post by wolph42 »

alas that was not the issue. Here the 'corrected code' same error:

Code: Select all

[h:'<!-- ------------------------------------ addBevel() ------------------------------------------------- -->']
[h:dungeon    = getLibProperty("DB3.dungeon","lib:DB3Test")]
[h:Field    = getLibProperty("DB3.tField","lib:DB3Test")]

[h,foreach(tile, Field), CODE:{
    <!-- create x and y coord of current Centre -->
    [coord    = jons.get(dungeon, roll.count)]
    [coord='{"x":0,"y":0}']
    [varsFromStrProp(json.toStrProp(coord))]
    
    <!-- turn tile into separate variables -->
    [varsFromStrProp(replace(
        tile,
        "t(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
        "E=\$1;NE=\$2;N=\$3;NW=\$4;W=\$5;SW=\$6;S=\$7;SE=\$8;"
    ))]

    <!-- EAST EDGE CHECK -->
    [switch("t"+SE+E+NE), CODE:
        case "t000":{
            <!-- EV -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
        };
        case "t001":{
            <!-- EV CO(S) -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord,"useDistance",0,facing,-90))]
        };
        case "t010":{
            <!-- EV CO(N) -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord, "y", json.get(coord,"y")-1,"useDistance",0,facing,0))]
        };
        case "t011":{
            <!-- EV CO CO -->
            [copyToken("bevelEV",1,"",json.set(coord,"useDistance",0))]
            [copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,-90))]
            [copyToken("bevelCO",1,"",json.set(coord, "y", json.get(coord,"y")-1,"useDistance",0,facing,0))]
        };
        default{<!-- ignore -->}
    ]

    <!-- NORTH EAST CORNER CHECK --><!-- IC ONLY --> 
    [h,if(NE+N+NW == 0): copyToken("bevelCO",1,"",json.set(coord, ,"useDistance",0,facing,90))]

    <!-- OTHER SIDES TO BE DONE LATER AFTER THOROUGHT TESTING -->
    [r:"t"+N+NW+W]
    [r:"t"+NW+W+SW]
    [r:"t"+W+SW+S]
    [r:"t"+SW+S+SE]
    [r:"t"+S+SE+E]
}] 
Im really starting to get the feeling that its an mt bug. But need be sure before I call it.

e.g. this

Code: Select all

[h:Field    = "1,2,3,4"]

[h,foreach(tile, Field), CODE:{
    [switch("t000"), CODE:
        case "t000":{};
        case "t001":{};
        case "t010":{};
        case "t011":{};
        default{}
    ]
}] 
results in an NPE: "Unexpected token 'null' "

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.4 BUG?] switch

Post by aliasmask »

Ah, default: {}


User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: [1.4 BUG - Resolved] switch

Post by RPTroll »

I never get switch right the first time. I've resorted to copy and pasting a working version then editing.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.4 BUG - Resolved] switch

Post by aliasmask »

RPTroll wrote:I never get switch right the first time. I've resorted to copy and pasting a working version then editing.
There's nothing wrong with using switch, but I generally avoid it finding other methods that work better. The thing that the java switch doesn't do that traditionally the switch would do in other languages is ranges.

Post Reply

Return to “Macros”