I've been reading through the input() function on the wiki, but I cannot seem to find out how to specify specific values for the choices. An example of what I am trying to do:
Choose one: Weapon1,Weapon2, or Weapon3.
I want the vales for them to be something like:
Weapon1=Wep1, Weapon2=Wep2, Weapon3=Wep3
I think I have seen this somewhere, but I cannot find the macro I saw it in, nor can I find it on the wiki.
How do I set specific values in the input() function?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- Shadowfireomega
- Giant
- Posts: 218
- Joined: Thu Dec 23, 2010 12:12 am
- Location: San Antonio, Texas
How do I set specific values in the input() function?
"I love being wrong, for if I was always right, there would be nothing left to learn, and that would be a world I would not want to live in."
-Benjamin Fisher
"Knowledge is knowing a tomato is a fruit; wisdom is not putting it in a fruit salad."
-Miles Kington
"Space is his favorite thing in the world!"
-Kayla Kros
"Anything times 1 is 1"
-Kayla Kros
-Benjamin Fisher
"Knowledge is knowing a tomato is a fruit; wisdom is not putting it in a fruit salad."
-Miles Kington
"Space is his favorite thing in the world!"
-Kayla Kros
"Anything times 1 is 1"
-Kayla Kros
Re: How do I set specific values in the input() function?
You want the LIST option of the input function:Shadowfireomega wrote:I've been reading through the input() function on the wiki, but I cannot seem to find out how to specify specific values for the choices. An example of what I am trying to do:
Choose one: Weapon1,Weapon2, or Weapon3.
I want the vales for them to be something like:
Weapon1=Wep1, Weapon2=Wep2, Weapon3=Wep3
I think I have seen this somewhere, but I cannot find the macro I saw it in, nor can I find it on the wiki.
here:
http://lmwcs.com/rptools/wiki/input
an example:
Code: Select all
[h: chk = input ( "weaponchoice | Weapon1, Weapon2, Weapon3 | Weapon | LIST | SELECT=STRING VALUE=NUMBER" )]
Code: Select all
[h, SWITCH ( weaponchoice ) :
case "Weapon1": { [mappedchoice = "Wep1" ] };
case "Weapon2": { [mappedchoice = "Wep2" ] };
case "Weapon3": { [mappedchoice = "Wep3" ] };
default: { [mappedchoice = "" ] }]
Re: How do I set specific values in the input() function?
I don't have enough information to know exactly what you're tring to do. It would help to know what the function is for, or to post the code you have already tried.
That said, I know one thing that confused me initially when using inputs was the fact that the value returned is not the selected item, but the selected item's position in the list of items.
For example, here's a simple input:
That said, I know one thing that confused me initially when using inputs was the fact that the value returned is not the selected item, but the selected item's position in the list of items.
For example, here's a simple input:
Code: Select all
<!-- first, create a list of weapons that will be shown to the user -->
[h:weaponList = "Pistol, Shotgun, Assault Rifle"]
<!-- now display that form.
when the user selects a weapon, the variable indexOfWeapon will be set:
it will equal the weapons position in the list.
So if the user picks pistol, indexofWeapon = 0; if user pics Assault Rifle, indexOfWeapon = 2 -->
[h:status=input(
"indexOfWeapon|"+weaponList+"|Which Weapon?|RADIO|SELECT=0"
)]
[h:abort(status)]
<!--
<!-- now need to use the numerical index to find the name of the weapon chosen. -->
[H: chosenWeaponName = listGet(weaponList,whichWeapon)]
MapTools Forks: Thread
Re: How do I set specific values in the input() function?
Ninja's by Ditto
Note that if you use the LIST option
You can change the VALUE=NUMBER to VALUE=STRING, and the variable will be saved with the text value of the chosen item. You don't need to then do the "get from list" method I used in my last post. Generally though, I think using that list method I suggest is a bit more robust - it's easier to keep updated with code changes, and make the code portable.
Note that if you use the LIST option
Code: Select all
[h: chk = input ( "weaponchoice | Weapon1, Weapon2, Weapon3 | Weapon | LIST | SELECT=STRING VALUE=NUMBER" )]
MapTools Forks: Thread
- Shadowfireomega
- Giant
- Posts: 218
- Joined: Thu Dec 23, 2010 12:12 am
- Location: San Antonio, Texas
Re: How do I set specific values in the input() function?
@Ditto: This will work thanks!
@MeMeMe: This is what I tried: That is just a quick scratch macro, but in the same format I tried. I abandoned this method for something else for the macro I was making so I don't have the original. But if there is a way to do it with just the input, that would be good to know for the future ^.^
@MeMeMe: This is what I tried:
Code: Select all
[h:input("bang|Hi, low, Medium|How big?|list|value=8, 1, 4")]
[bang]
"I love being wrong, for if I was always right, there would be nothing left to learn, and that would be a world I would not want to live in."
-Benjamin Fisher
"Knowledge is knowing a tomato is a fruit; wisdom is not putting it in a fruit salad."
-Miles Kington
"Space is his favorite thing in the world!"
-Kayla Kros
"Anything times 1 is 1"
-Kayla Kros
-Benjamin Fisher
"Knowledge is knowing a tomato is a fruit; wisdom is not putting it in a fruit salad."
-Miles Kington
"Space is his favorite thing in the world!"
-Kayla Kros
"Anything times 1 is 1"
-Kayla Kros
Re: How do I set specific values in the input() function?
I often will use 2 arrays. The first array is the output I want to show for the selection. The second array is the value I want to use for the selection. They are connected by their position in the array. This is useful to do when I have fancy formatting for my input. Another method is to make it a single json object where the key is what is displayed and the value is what I want to save. In that case, I would want to return the value with VALUE=STRING and then use json.get to get the value.
edit: fixed code in method 2
Code: Select all
<!-- method 1 -->
[H: inputOptions = "dagger,shortsword,longsword"]
[H: inputValues = "1d4,1d6,1d8"]
[H: abort(input(strformat("weaponChoice|%{inputOptions}|Choose a weapon|LIST")))]
[H: result = listGet(inputValues,weaponChoice)]
[H: damage = eval(result)]
[R: strformat("%{result} = %{damage}")]
Code: Select all
<!-- method 2 -->
[H: inputObj= json.set("{}","<html><b>dagger</b>: 1d4</b></html>","1d4",
"<html><b>shortsword</b>: 1d6</b></html>","1d6",
"<html><b>longsword</b>: 1d8</b></html>","1d8"
)]
[H: inputOptions = json.fields(inputObj)]
[H: abort(input(strformat("weaponChoice|%{inputOptions}|Chose a weapon|LIST|VALUE=STRING")))]
[H: result = json.get(inputObj,weaponChoice)]
[H: damage = eval(result)]
[R: strformat("%{result} = %{damage}")]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: How do I set specific values in the input() function?
I thought of that, but didn't see any real benefit ... (see aliasmask's post, though .. having 2 arrays could make it simpler to make them ... ) But just showing the principal of how to use the LIST option in input .. I'll stick with my initial exampleMeMeMe wrote: You can change the VALUE=NUMBER to VALUE=STRING, and the variable will be saved with the text value of the chosen item. You don't need to then do the "get from list" method I used in my last post. Generally though, I think using that list method I suggest is a bit more robust - it's easier to keep updated with code changes, and make the code portable.