As you can I'm tell new to this macro/coding thing (but I'm having a blast).
I have what I think is a simple question. I looked but could not find a tutorial for how to use the SELECT option in the list command with textlist.
On my charsheet macro I have a drop down selection list for race. It works fine but is there a way to select the characters race for the SELECT option if the Race variable has previously been selected?
I would like to open the macro to edit other things on the sheet but I have to reselect the race every time otherwise it goes to the 0 selection. It's not really a big deal but I thought I would ask you coding guru's.
List selection help
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: List selection help
there are many examples in the wiki: Wiki: input()
but here's what you're looking for:
which will select the 4th item in the list.
now you probly want the '3' as a variable (last choice you mentioned). Last choice, means that the 'lastChosenRace' variable needs to be stored somewhere. Typically you do this on a lib:Token.
So create a token which is called 'lib:anythingYouLike'. Now you create
in your input
Then before the input you need to defined 'lastChosenRace'
Which will be
I hope you'll understand that this will go wrong the first time as that property will be empty so you need to add:
and after the input you'll need:
o and one more thing, with this kind of code it always goes wrong between the returned value or the selected one. input by default returns a number (e.g. '3' meaning 4th item in the list) but in your character sheet you like to see 'elf' not '3'. hence you can use 'VALUE=STRING' option in the input(). BUT then 'elf' is returned and when you store that in lib:anythingYouLike then 'elf' will also be returned... in which case you get 'SELECT=ELF' which will bug out. Sou you will need listFind to solve that.
but here's what you're looking for:
Code: Select all
"targetNum|put,the,list,here|Select Target|LIST|SELECT=3",
now you probly want the '3' as a variable (last choice you mentioned). Last choice, means that the 'lastChosenRace' variable needs to be stored somewhere. Typically you do this on a lib:Token.
So create a token which is called 'lib:anythingYouLike'. Now you create
Code: Select all
"race|"+raceList+"|Select Target|LIST|SELECT="+lastChosenRace,
Then before the input you need to defined 'lastChosenRace'
Which will be
Code: Select all
[h:lastChosenRace = getLibProperty("lastChosenRace", "lib:anythingYouLike")]
Code: Select all
[h:lastChosenRace = getLibProperty("lastChosenRace", "lib:anythingYouLike")]
[h,if(lastChosenRace==""): lastChosenRace = 0]
Code: Select all
[h:setLibProperty("lastChosenRace", lastChosenRace, "lib:anythingYouLike")]
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: List selection help
Thanks for the help!
I got it working. it's a bit more code than I anticipated but since I already have a variable on the "Basic" token named "Race" this is how I got it working...
I set the default property of "Race" to "Human" to avoid the first time blank "" problem.
So, does anyone think there would be any problems with this code?
I got it working. it's a bit more code than I anticipated but since I already have a variable on the "Basic" token named "Race" this is how I got it working...
Code: Select all
[h:RaceSelected = getProperty("Race")]
[h:RaceNum = 0]
<!-- Assign RacNum for SELECT option -->
[r, if(RaceSelected=="Dragonborn"), CODE: { [h:RaceNum=0] };{}]
[r, if(RaceSelected=="Dwarf"), CODE: { [h:RaceNum=1] };{}]
[r, if(RaceSelected=="Elf"), CODE: { [h:RaceNum=2] };{}]
[r, if(RaceSelected=="Gnome"), CODE: { [h:RaceNum=3] };{}]
[r, if(RaceSelected=="Half-Elf"), CODE: { [h:RaceNum=4] };{}]
[r, if(RaceSelected=="Half-Orc"), CODE: { [h:RaceNum=5] };{}]
[r, if(RaceSelected=="Halfling"), CODE: { [h:RaceNum=6] };{}]
[r, if(RaceSelected=="Human"), CODE: { [h:RaceNum=7] };{}]
[r, if(RaceSelected=="Tiefling"), CODE: { [h:RaceNum=8] };{}]
<!-- The Selection List -->
[h:status=input(
"InputRace|Dragonborn, Dwarf, Elf, Gnome, Half-Elf, Half-Orc, Halfling, Human, Tiefling|Race|LIST|SELECT="+RaceNum)]
[h:abort(status)]
<!-- Saves the new selection as Text -->
[r, if(InputRace==0), CODE: { [h:Race="Dragonborn" ] };{}]
[r, if(InputRace==1), CODE: { [h:Race="Dwarf" ] };{}]
[r, if(InputRace==2), CODE: { [h:Race="Elf" ] };{}]
[r, if(InputRace==3), CODE: { [h:Race="Gnome" ] };{}]
[r, if(InputRace==4), CODE: { [h:Race="Half-Elf" ] };{}]
[r, if(InputRace==5), CODE: { [h:Race="Half-Orc" ] };{}]
[r, if(InputRace==6), CODE: { [h:Race="Halfling" ] };{}]
[r, if(InputRace==7), CODE: { [h:Race="Human" ] };{}]
[r, if(InputRace==8), CODE: { [h:Race="Tiefling" ] };{}]
So, does anyone think there would be any problems with this code?
Re: List selection help
No no problems, but extrmely redundant. You don't need the code option and you can stap all the Ifs for a
[switch:]
But much better ad faster is using the listfind as explained in my earlier post.
Also Now that you assignment it thThe current token only instead of a lib token... What exactly is the use of is?
[switch:]
But much better ad faster is using the listfind as explained in my earlier post.
Also Now that you assignment it thThe current token only instead of a lib token... What exactly is the use of is?
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: List selection help
Ok I think I got what you said working. Well it works for me anyway. lol
Here is what I did...
Here is what I did...
Code: Select all
<!-- Get the tokens exsisting Race -->
[h:RaceSelected = getProperty("Race")]
<!-- Change the selected race to a list number so can use SELECT on InputRace -->
[h:RaceNum = listFind("Dragonborn, Dwarf, Elf, Gnome, Half-Elf, Half-Orc, Halfling, Human, Tiefling",RaceSelected)]
<!-- The selection list -->
[h:status=input(
"InputRace|Dragonborn, Dwarf, Elf, Gnome, Half-Elf, Half-Orc, Halfling, Human, Tiefling|Race|LIST|SELECT="+RaceNum)]
[h:abort(status)]
<!-- Converts selected list number to text and saves it as the new Race -->
[h,switch(InputRace) :
case "0": Race="Dragonborn";
case "1": Race="Dwarf";
case "2": Race="Elf";
case "3": Race="Gnome";
case "4": Race="Half-Elf";
case "5": Race="Half-Orc";
case "6": Race="Halfling";
case "7": Race="Human";
case "8": Race="Tiefling"]
- CoveredInFish
- Demigod
- Posts: 3104
- Joined: Mon Jun 29, 2009 10:37 am
- Location: Germany
- Contact:
Re: List selection help
You might learn something from this ...
You dont have to ... but maybe you want. IMHO in a macro (only) this complex every working code is good enough.
Code: Select all
[h: races = "Dragonborn, Dwarf, Elf, Gnome, Half-Elf, Half-Orc, Halfling, Human, Tiefling"]
<!-- The selection list -->
[h:status=input(
"InputRace|"+races+"|Race|LIST|SELECT="+RaceNum)]
[h:abort(status)]
<!-- Converts selected list number to text and saves it as the new Race -->
[h: Race = listGet(races, InputRace)]