Issues with tables in 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
Ego Archive
Cave Troll
Posts: 26
Joined: Thu Apr 16, 2009 4:12 pm

Issues with tables in a macro

Post by Ego Archive »

So I'm trying to build a "Topic/NPC responses" macro, to ease my need to type out story information-responses during a game. Basically I'm trying to build something that will allow me to choose a story hook, and an NPC, and send the response to a connected player.

What I have so far is:

Code: Select all

/w

[h: Player = getAllPlayerNames()]
[h: NPC = input(
"SelectNPC |Salvana Wrafton,Eilias,Valthrun the Prescient|Choose an NPC| LIST",
"topicSelect |Kobolds,Shadowfall Keep,Burial Ground| Choose a topic to respond to | LIST| VALUE=STRING",
"playerSelect |"+ Player +" | Choose a Player | LIST | VALUE=STRING"
)]
[h: Response=table(topicSelect,selectNPC)]

{playerSelect + " " + Response}
Then I have responses in each table listed in the "topicSelect", that correspond to the NPC value of "SelectNPC".

What I would prefer, is to generate a list of NPC's by doing something like a Get on a "NPC" table for values, akin to how the player list is generated. However the only way I can think of doing that would be to recursively build a string by appending to the string with table calls, and I'm not really sure how you would do that...

So my questions are, is this the most effiecient way of going about this? Is there a way to dynamically build the NPC, and Topic lists from reference tables? do you see any gotcha's with the existing code?

I attempted to originally code this with properties on tokens. Where I would have a collection of NPC tokens that had properties corresponding to the various topics, with a value that was the response that NPC would give, but I had too many headaches with calling the tokens from other maps. That said I may go back to that method, as tables look to be problematic also.
Towndale: A user generated fantasy town for any game system.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Issues with tables in a macro

Post by Rumble »

If you create one table with just a list of NPC names, and in another table have those names correspond to speech/text items, you can do this.

The first part would be just a table like:


1 Salvana
2 Georg the Hearty
3 Slith the Quick
4 Some Old Farmer Guy
5 The Town Fool

And then you can use a count() loop to go through the table and assemble a list of NPC names.

Code: Select all

[h:npcList = ""]
[h,count(5): npcList = listAppend(npcList, table("NPCNames", roll.count+1))]
 
After that loop runs, you'd have a variable npcList that looked like:

Code: Select all

"Salvana,George the Hearty,Slith the Quick,Some Old Farmer Guy,The Town Fool"
 
Then, you just embed that list in your code, like so:

Code: Select all

/w

[h: Player = getAllPlayerNames()]
[h: NPC = input(
"SelectNPC |"+npcList+"|Choose an NPC|LIST",
"topicSelect |Kobolds,Shadowfall Keep,Burial Ground| Choose a topic to respond to | LIST| VALUE=STRING",
"playerSelect |"+ Player +" | Choose a Player | LIST | VALUE=STRING"
)]
[h: Response=table(topicSelect,selectNPC)]

{playerSelect + " " + Response} 

Ego Archive
Cave Troll
Posts: 26
Joined: Thu Apr 16, 2009 4:12 pm

Re: Issues with tables in a macro

Post by Ego Archive »

Rumble wrote:If you create one table with just a list of NPC names, and in another table have those names correspond to speech/text items, you can do this.

The first part would be just a table like:


1 Salvana
2 Georg the Hearty
3 Slith the Quick
4 Some Old Farmer Guy
5 The Town Fool

And then you can use a count() loop to go through the table and assemble a list of NPC names.

Code: Select all

[h:npcList = ""]
[h,count(5): npcList = listAppend(npcList, table("NPCNames", roll.count+1))]
 
After that loop runs, you'd have a variable npcList that looked like:

Code: Select all

"Salvana,George the Hearty,Slith the Quick,Some Old Farmer Guy,The Town Fool"
 
Then, you just embed that list in your code, like so:

Code: Select all

/w

[h: Player = getAllPlayerNames()]
[h: NPC = input(
"SelectNPC |"+npcList+"|Choose an NPC|LIST",
"topicSelect |Kobolds,Shadowfall Keep,Burial Ground| Choose a topic to respond to | LIST| VALUE=STRING",
"playerSelect |"+ Player +" | Choose a Player | LIST | VALUE=STRING"
)]
[h: Response=table(topicSelect,selectNPC)]

{playerSelect + " " + Response} 
That is exactly what I am looking for, I can use that to build tables>strings for both the npcList, and the topicList. Thank you very much, I wasn't even aware you could structure a statement like that.

I'm just learning the macro language as I go, is this based off of a common coding language I could research? I ask because, I have been adding the

Code: Select all

[h:
(hidden), before commands, and I have seen

Code: Select all

[r:
and

Code: Select all

[e:
I think [e: does an emit, and the [r: a reply but I don't really know what other statement types there are, and I can't seem to find any reference in the wiki (but I may have admittedly missed it).

The point is, while I can see what your doing with the

Code: Select all

[h,count(5):
(essentially a 5 count loop), I wouldn't have ever made the leap to doing that myself, without your example, and I'd like to correct that. ;)
Towndale: A user generated fantasy town for any game system.

Ego Archive
Cave Troll
Posts: 26
Joined: Thu Apr 16, 2009 4:12 pm

Re: Issues with tables in a macro

Post by Ego Archive »

Ok, so now I have it as:

Code: Select all

/w

[h: Player = getAllPlayerNames()]
[h:npcList = ""]
[h,count(3): npcList = listAppend(npcList, table("NPCNames", roll.count+1))]
[h:topicList = ""]
[h,count(3): topicList = listAppend(topicList, table("Topics", roll.count+1))]

[h: Popup = input(
"SelectNPC |" +  npcList + "|Choose an NPC| LIST",
"topicSelect |" +  topicList + "| Choose a topic to respond to | LIST| VALUE=STRING",
"playerSelect |"+ Player +" | Choose a Player (Not a Token) | LIST | VALUE=STRING"
)]
[h:SelectNPC=SelectNPC+1]
[h: Response=table(topicSelect,selectNPC)]
[h: NPC = table("NPCNames",selectNPC)]
{playerSelect + " " +NPC+ " Says - " + Response}

My next question, of course, is:

Is there a way to do something akin to a "For Each" loop, like what what you would do in VBscript; where it will loop until it's finished with an array?

For my personal use, changing the count to whatever is the number of elements in each table is easy enough, but if someone uses this code, they may run into issues.
Towndale: A user generated fantasy town for any game system.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Issues with tables in a macro

Post by Rumble »

Ego Archive wrote:Ok, so now I have it as:

Code: Select all

/w

[h: Player = getAllPlayerNames()]
[h:npcList = ""]
[h,count(3): npcList = listAppend(npcList, table("NPCNames", roll.count+1))]
[h:topicList = ""]
[h,count(3): topicList = listAppend(topicList, table("Topics", roll.count+1))]

[h: Popup = input(
"SelectNPC |" +  npcList + "|Choose an NPC| LIST",
"topicSelect |" +  topicList + "| Choose a topic to respond to | LIST| VALUE=STRING",
"playerSelect |"+ Player +" | Choose a Player (Not a Token) | LIST | VALUE=STRING"
)]
[h:SelectNPC=SelectNPC+1]
[h: Response=table(topicSelect,selectNPC)]
[h: NPC = table("NPCNames",selectNPC)]
{playerSelect + " " +NPC+ " Says - " + Response}

My next question, of course, is:

Is there a way to do something akin to a "For Each" loop, like what what you would do in VBscript; where it will loop until it's finished with an array?

For my personal use, changing the count to whatever is the number of elements in each table is easy enough, but if someone uses this code, they may run into issues.
Okay, to answer a couple questions: no, it's not based off of any existing language so far as I know. It has structures common to many languages and some things might be similar, but it's its own thing.

Two, you can do [foreach:] on arrays and lists, as you expect. I recommend you look into the tutorials on the wiki (linked in my sig) as well as the information on Roll Options (located in the MapTool wiki). There's a lot to the language, so it's may be helpful to go to the reference source, as it were.

Post Reply

Return to “Macros”