Dynamically selecting Lib tokens?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Chimera245
Cave Troll
Posts: 29
Joined: Thu Oct 09, 2014 6:39 pm

Dynamically selecting Lib tokens?

Post by Chimera245 »

Is it possible to reference the macros/properties of a Lib token without knowing in advance which lib token?

My usual Maptool practices are to have each token randomly generate itself upon being dropped into the world. (Or rather, upon being moused over for the first time, but it's nearly impossible to NOT mouse over a token you just dragged onto the map with the mouse...)
Each token property has a default value that goes something like:

*Strength:[r:Strength=3d6]
or
*Race:[r:Race=listGet("human, elf, dwarf, halfling", 1d4-1)]

Could I, for example, rig up my "Race" token property default to somehow reference a Lib token that has a list of the proportions of different races for different areas?

Like, if I throw down a token in Humansburg, the Stereotypical Average City, its "Race" property will randomize slightly more humans, and an even mix of everything else, but in Dwarfheim, you'll get mostly dwarves, no elves, a handful extra humans, and the remainder split between everything else.

I see this as having a Lib Token associated with every location, with different variables for their token properties that the tokens can use reference in THEIR properties.

But is there a way to do that without knowing which Lib token to use ahead of time? Like to "use whichever Lib token is closest" or "use whichever Lib token is on this map" or something along those lines?

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

Re: Dynamically selecting Lib tokens?

Post by taustinoc »

I would think it'd be easier to do this with tables than with a lib token.

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Dynamically selecting Lib tokens?

Post by Phergus »

Some random thoughts that may or may not be useful.

Will probably need to use user-defined functions (Wiki: defineFunction()) to get what you need.

On each map you could have a token with the same name as the map. The Map token has a property like libTokenToUseForNPCs which you have set to the name of the lib:token you want used for that map. Use Wiki: getCurrentMapName() and then you can read the property from the Map token with something like [token(mapname):foo = getProperty(libTokenToUseForNPCs)] then build your macro call to the correct lib token.

Or on each map, again use the Map token to store info like the % distribution of the races for that map and pass the info to your NPC generator macro.

As taustinoc says, tables may be helpful in this as well.

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

Re: Dynamically selecting Lib tokens?

Post by wolph42 »

what you want (in the end) is what I created in my (more or less) in my framework. I didn't do it through lib tokens tough. I created separate token property types for each type of token I have. And yes you can randomize that.

the way you want it is possible but a lot more hassle more so because its not easy to determine on which map a lib:token resides... (IRC).

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Dynamically selecting Lib tokens?

Post by Phergus »

Wow. How many Campaign Property types do you have? Hundreds? More than a thousand?

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

Re: Dynamically selecting Lib tokens?

Post by wolph42 »

no of course not. not sure though, 20 or so? but those 20 are all randomized rolls within certain parameters. The 'hard' work though is not done within those types, but in a macro. After all, you can fire off a macro and put everything you need in there or retrieve it from tables. I certainly wouldn't create a lib token for each 'area'. What I would do is create an 'area token' with all the required info and have the macro look for the areaToken, they can be called the same on each map so the macro will always grabs the relevant one and uses the info on that token to generate the character.

(the 20 or so types i have is for a wide diversity on different types of tokens, e.g. ship, car, space marine, eldar, human etc.).

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

Re: Dynamically selecting Lib tokens?

Post by Full Bleed »

Chimera245 wrote:Is it possible to reference the macros/properties of a Lib token without knowing in advance which lib token?

My usual Maptool practices are to have each token randomly generate itself upon being dropped into the world. (Or rather, upon being moused over for the first time, but it's nearly impossible to NOT mouse over a token you just dragged onto the map with the mouse...)
Each token property has a default value that goes something like:

*Strength:[r:Strength=3d6]
or
*Race:[r:Race=listGet("human, elf, dwarf, halfling", 1d4-1)]

Could I, for example, rig up my "Race" token property default to somehow reference a Lib token that has a list of the proportions of different races for different areas?

Like, if I throw down a token in Humansburg, the Stereotypical Average City, its "Race" property will randomize slightly more humans, and an even mix of everything else, but in Dwarfheim, you'll get mostly dwarves, no elves, a handful extra humans, and the remainder split between everything else.

I see this as having a Lib Token associated with every location, with different variables for their token properties that the tokens can use reference in THEIR properties.

But is there a way to do that without knowing which Lib token to use ahead of time? Like to "use whichever Lib token is closest" or "use whichever Lib token is on this map" or something along those lines?
I would be looking to do something along the lines of what Phergus mentioned. This is not the way I'd do this in normal practice since I don't really like using the auto-evaluate method of populating new tokens... but if you want the token to react to where you're dropping it you could do something like this:

1) Make the first property on the token be "Area". The default value of "Area" be geCurrentMapName(). This assumes the map name is the area you're dropping the token.

2) Then create UDFs for all of the things you want to react to the "Area" token.

So, under the default Race property you'd have [r: autoRace(Area)].

Then you'd just need one Lib Token with all the autoCalc UDFs you want to create using the Area as a factor. Those UDFs would handle the different "cases" you want to be taken into consideration.

Just did a quick test and this works.

The Test Campaign is attached. Anything you drop on Humansburgh will be made Human, Elfland will produce Elves... an unknown map will default to your original random formula.
Attachments
Auto Calc Area.cmpgn
(32.26 KiB) Downloaded 13 times
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Dynamically selecting Lib tokens?

Post by Phergus »

wolph42 wrote:no of course not. not sure though, 20 or so? but those 20 are all randomized rolls within certain parameters. The 'hard' work though is not done within those types, but in a macro.
It sounded like you had one for every type of creature and D&D has hundreds at the least.
wolph42 wrote:What I would do is create an 'area token' with all the required info and have the macro look for the areaToken, they can be called the same on each map so the macro will always grabs the relevant one and uses the info on that token to generate the character.
Pretty much what I suggested.
wolph42 wrote:(the 20 or so types i have is for a wide diversity on different types of tokens, e.g. ship, car, space marine, eldar, human etc.).
Ah. I do the same.

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Dynamically selecting Lib tokens?

Post by Phergus »

Full Bleed wrote:Just did a quick test and this works.

The Test Campaign is attached. Anything you drop on Humansburgh will be made Human, Elfland will produce Elves... an unknown map will default to your original random formula.
I new if I fumbled around with a suggestion that someone good at macros would chime in. :lol:


Chimera245
Cave Troll
Posts: 29
Joined: Thu Oct 09, 2014 6:39 pm

Re: Dynamically selecting Lib tokens?

Post by Chimera245 »

First of all, I had no idea you could dynamically change a token's property type. That is awesome, and my mind is already buzzing with possibilities.

For everything else, I know my noob is showing, but I don't fully understand, and/or don't get how it would be an advantage.

Tables:
"table" on the wiki is a redlink. I could more-or-less figure from context how they work while looking at the functions that use them, but digging a little deeper, it seems that Maptool can *use* them but not *create* them. Or at least not easily and intuitively? Either way, I'm not positive on how they'd be any easier or better for what I want to do, but I'm likely just missing something somewhere that would make them click for me.

User Defined Functions:
I've never really understood these. I get they're essentially supposed to be shorthand for a longer bit of code that you frequently use. (I once heard it said "If you type the same bit of code twice, turn it into a UDF instead.") And I totally get that for coding in general, but in Maptool, it seems to basically link to a macro somewhere. (Ideally using a macro called "onCampaignLoad" on a lib token somewhere) But if you're associating a UDF with a macro, wouldn't it be easier to just call the macro normally? Am I understanding this right, or missing something?

getCurrentMapName() and "Area Tokens":
This is more-or-less what I was asking about in the first place. But I'm not sure what advantage there'd be to having them be normal tokens and not Lib tokens.

I took a look at the campaign file, and it does 99% of what I want, but it looks like i'd have to manually go add new code to the macro on the lib token every time I made a new area. Specifically a new "case" line under the "switch:" option for the new possible value of the "area" variable.

Right now, my Grand-Scheme-Ambitious-Idea(TM) flows something like this:
There is a Main Map. It serves as a "World Map" each square being several miles, and with each town, dungeon, or other interesting location PCs would go being a dot. That dot is a Lib token with all the area's important information-to-be-called-in-a-macro-during-play. On each area map, there is the normal one-square-is-five-feet representation of the area that PCs would explore, fight monsters and talk to NPCs in.
The default token property type, the type you get with a newly created token, would only have one property on it: Area. Its default value would be "getCurrentMapName, then change token property type". If deployed on the World Map, it changes to "Area Lib Token" property type. One the "Area Lib Token" properties includes a "Name = 'Lib:' + Name" command. Any token created on any other map goes "getCurrentMapName" then looks to "Lib:(CurrentMapName)" for further instruction. If it's a town, it'll likely turn into an NPC of some sort, if it's a dungeon, it'll likely be a monster, etc.
As long as the DM always creates a new map with the name of the newly created area lib token, everything should work. Or maybe the lib token uses "copyMap" to make the new map on its own from some base "new map" map set aside for that purpose.

I might even get ambitious and have a Cosmology Map, with Lib tokens for different planes, then World Maps for each plane with Lib tokens for towns/dungeons/etc.

...

Would this work as I imagine it? Would one of the other ideas already mentioned make it easier if I understood it better? Is there some fatal flaw that I don't see?

Post Reply

Return to “MapTool”