Commands within tables, from a macro?

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
CyberRiot
Kobold
Posts: 8
Joined: Thu Apr 30, 2020 9:07 pm

Commands within tables, from a macro?

Post by CyberRiot »

So, my question is: Is there a way to run the table, from a macro, in a way that the table will run commands from its own results?

Let me explain:

So I have an "Attack Roll" macro for my GURPS game. (pasted below)
The idea is that this macro does almost everything we need for an attack roll:
1. Asks player what their skill level is ("Effective_Skill_Level")
2. Rolls 3d6
3. Compares the 3d6 roll to the skill level,
4. Tell the player if the result is a hit, miss, critical hit, or critical miss,
5. If the result is a hit (or a critical hit) it runs the hit-location table.
Attack Skill:
[T: Skill = Effective_Skill_Level]
, Roll:
[T: Roll = 3d6]
-
[t,if(Roll <= 4): output = "CRITICAL"; output = ""]
[t,if(Roll == 5 && Skill >= 15): output = "CRITICAL"; output = ""]
[t,if(Roll == 6 && Skill >= 16): output = "CRITICAL"; output = ""]
[t,if(Roll <= Skill): output = "HIT!"; output = ""]
[t,if(Roll <= Skill): output = ", Hit Location: "; output = ""]
[t,if(Roll <= Skill): tbl("HitLocation"); output = ""]


[t,if(Roll == 18): output = "CRITICAL"; output = ""]
[t,if(Roll == 17 && Skill <=15): output = "CRITICAL"; output = ""]
[t,if(Roll >= Skill+10 && Roll <=16): output = "CRITICAL"; output = ""]
[t,if(Roll > Skill): output = "MISS!"; output = ""]
The problem I am having is that this table has certain entries that lead to other tables. But since the table function doesn't actually run the table the same as if you run the table directly, it doesn't access the secondary tables, but just outputs the command from that line as text.

As an example: One of the entries on the table is
9-10 | /tbl Torso

So if a torso hit is indicated by the roll, it goes to the second table which has a 1/6 chance to hit vitals.
But the output from the macro doesn't run the second table. It just looks like this:
Attack Skill: 12 , Roll: 6 - HIT! , Hit Location: /tbl Torso
Again: Is there a way to run the table, from a macro, in a way that the table will run /tbl commands from its own results?

Thanks

taustinoc
Dragon
Posts: 518
Joined: Mon Aug 03, 2015 6:30 pm

Re: Commands within tables, from a macro?

Post by taustinoc »

I'm not the expert on this by any means, but I think you want to look into evalMacro()

https://lmwcs.com/rptools/wiki/evalMacro

CyberRiot
Kobold
Posts: 8
Joined: Thu Apr 30, 2020 9:07 pm

Re: Commands within tables, from a macro?

Post by CyberRiot »

Thanks, taustinoc.

At your suggestion, I have tried replacing the line:
[t,if(Roll <= Skill): tbl("HitLocation"); output = ""]
with both:
[t,if(Roll <= Skill): evalmacro(tbl("HitLocation")); output = ""]
and
[t,if(Roll <= Skill): execmacro(tbl("HitLocation")); output = ""]

However, they all return the same result, showing the command from within the table as a text string, instead of running the followup table.
Effective Skill: 14 , Roll: 12 = HIT! , Hit Location: /tbl Torso
Am I missing something else in the formatting?

taustinoc
Dragon
Posts: 518
Joined: Mon Aug 03, 2015 6:30 pm

Re: Commands within tables, from a macro?

Post by taustinoc »

I'm pretty sure the function name is case sensitive, so instead of evalmacro, it has to be evalMacro

I'd also be inclined to put the table result into a variable instead of running it directly, but I have no idea if that's required. It just makes it easier for me to debug (because I can show the contents of the macro to make sure it's what I think it is).

CyberRiot
Kobold
Posts: 8
Joined: Thu Apr 30, 2020 9:07 pm

Re: Commands within tables, from a macro?

Post by CyberRiot »

Same result. It seems that this is by design.

From the "Introduction to Tables" page:
Using macro script.

The table() function will display only the value of a random or specific row.
The tableImage() function will display only the Image asset value of a random or specific row. This can be then used as the 'src' attribute in HTML image tags.
So, what I'm hoping now is that someone knows a way to trigger a table, from within a macro, that is equivalent to double-clicking directly on the table.

For now, I'm just going to re-write my table as a series of If() roll options within the macro.

Thanks again for trying.

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Commands within tables, from a macro?

Post by bubblobill »

You probably want to explore the Table Functions instead of using /tbl
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

CyberRiot
Kobold
Posts: 8
Joined: Thu Apr 30, 2020 9:07 pm

Re: Commands within tables, from a macro?

Post by CyberRiot »

Thanks bubblobilll,
I have looked through the table functions, but there doesn't seem to be anything there that does what I want. They are mostly about creating or manipulating tables.

My tables are already created. I just want to roll on Table A, and then, if the result of the first table is Table B, I want to execute a roll on that table. This works fine if I just double-click the first table. But if I execute Table A from within a macro, the result is always a text string, and will not run be a command (such as executing another table roll). It's possible I'm just not seeing it there. But I've gone another route, and it's working for me.

I have removed the "tbl(HitLocation)" from my AttackRoll macro, and translated it into a roll-option list:
[t,if(Roll <= Effective_Skill): output = " Hit Location: "; output = ""]
[t:HitLocationRoll = 3d6]
[t,if(HitLocationRoll == 3 || HitLocationRoll == 4): output = "Skull (DR2, All damage types use wounding multiplier of x4. Knockdown rolls are at -10)"; output = ""]
[t,if(HitLocationRoll == 5): output = "Face (Knockdown Roll -5. Corrosion damage gets a wounding mod of 1.5, and blinds one eye.)"; output = ""]
[t,if(HitLocationRoll == 6 || HitLocationRoll == 7): output = "RightLeg (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 8): output = "RightArm (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 9 || HitLocationRoll == 10): tbl("Torso"); output = ""]
[t,if(HitLocationRoll == 11): output = "Groin (Wounding multiplier as per weapon)"; output = ""]
[t,if(HitLocationRoll == 12): output = "LeftArm (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 13 || HitLocationRoll == 14): output = "LeftLeg (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 15): tbl ("Hand"); output = ""]
[t,if(HitLocationRoll == 16): tbl ("Foot"); output = ""]
[t,if(HitLocationRoll == 17 || HitLocationRoll == 18): tbl ("Neck"); output = ""]
The secondary tables don't branch any further, so I have left them as tables.

I have also added critical hits/misses, and their tables. It's one click, type in your skill level, and presto.
Next step is to associate it with a token, and automatically retrieve their attack skill. :)
Thanks again, guys.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Commands within tables, from a macro?

Post by Full Bleed »

CyberRiot wrote:
Wed May 20, 2020 10:14 am
[t,if(Roll <= Effective_Skill): output = " Hit Location: "; output = ""]
[t:HitLocationRoll = 3d6]
[t,if(HitLocationRoll == 3 || HitLocationRoll == 4): output = "Skull (DR2, All damage types use wounding multiplier of x4. Knockdown rolls are at -10)"; output = ""]
[t,if(HitLocationRoll == 5): output = "Face (Knockdown Roll -5. Corrosion damage gets a wounding mod of 1.5, and blinds one eye.)"; output = ""]
[t,if(HitLocationRoll == 6 || HitLocationRoll == 7): output = "RightLeg (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 8): output = "RightArm (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 9 || HitLocationRoll == 10): tbl("Torso"); output = ""]
[t,if(HitLocationRoll == 11): output = "Groin (Wounding multiplier as per weapon)"; output = ""]
[t,if(HitLocationRoll == 12): output = "LeftArm (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 13 || HitLocationRoll == 14): output = "LeftLeg (Wounding multiplier for Pi+, Pi++, and Imp is x1; Otherwise as per weapon. Damage => 1/2 of HP cripples the limb. Excess damage is lost.)"; output = ""]
[t,if(HitLocationRoll == 15): tbl ("Hand"); output = ""]
[t,if(HitLocationRoll == 16): tbl ("Foot"); output = ""]
[t,if(HitLocationRoll == 17 || HitLocationRoll == 18): tbl ("Neck"); output = ""]
PS: You should be using the CODE tag, not the QUOTE tag to share code snippets.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “Macros”