Thread: Combobox add(blah,blah)
-
March 24th, 2021, 23:02 #1
- Join Date
- Jul 2015
- Posts
- 143
Combobox add(blah,blah)
Good afternoon, I am attempted to learn more about all the objects that I don't use a lot of in FG so I may think of them when designing new rulesets/extensions.
Last night I was pulling my hair out trying to figure this one out.
When you create a combobox you fill it will data by using
add("value", "text")
so I thought "ok I will make this section that is Small, Medium, and Large. Their values will be 2d4, 2d6, 2d8 so it looked psydocode:
add("2d4","Small");
add("2d6","Medium");
add("2d8","Large");
Adding them wasn't the issue. The issue is how do I use the Value?
I tried everything I could think of to get there, but I can't figure out how to pull back out the value. I can pull out the Text all night long, but I can't figure out how to access the Value.
I was pulling the text out by doing
local test = window.cbWeaponType.getValue();
Debug.chat(test);
is this missing? Or was it never intended to use the value? If it wasn't intended, what does it do?
Thanks in advance.
-
March 24th, 2021, 23:59 #2
The .lua code for combobox looks to have a list of indexes - which you are calling your value - and a list - which is the text values. The display will show the text values. The getValue() will return the list value which is text. I don't see anyway to get the list of index values out except through getValues() which will return the ordered table list of them.
I've only ever added one value - and that was the one I wanted. You have two - so not sure what will happen. Look at common/scripts/combobox.lua for the actual code. I've had to make my own version for other reasons in my extensions.Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
March 25th, 2021, 00:26 #3
- Join Date
- Jul 2015
- Posts
- 143
adding one value, that makes sense.
(Inserted below is the add function from the combobox.lua)
the second if in that function will check if the second argument is a string, if it is not, it will dup the first argument.
So you enter add("bob") it will correct it to act as tho you added add("bob", "bob").
I see what you mean with the getValues(). Unfortunately, I don't think helps, unless I had a way to tell which index I am on and I can't really find how to pull that.
function add(sValue, sText)
if not sValue then
return;
end
if type(sText) ~= "string" then
sText = sValue
end
if type(sValue) == "string" then
if ctrlList then
ctrlList.add(sValue, sText);
else
if not aItems[sValue] then
table.insert(aOrderedItems, sValue);
aItems[sValue] = sText;
end
end
end
end
-
March 25th, 2021, 01:05 #4Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
March 25th, 2021, 01:20 #5
- Join Date
- Jul 2015
- Posts
- 143
That sounds like work, but I don't hate it. Maybe a really nice person who develops in Core will come along and see my woes and give me a function that allows me to pull both the Value and the Text.
-
March 25th, 2021, 06:08 #6
if getValue() == "Small" then sDice = "2d4"
elseif getValue() == "Medium" then sDice = "2d6"
elseif getValue() == "Large" then sDice = "2d8"
end
??
-
March 25th, 2021, 08:01 #7
in my opinion the CoreRPG combobox template should have some method of getting the value related to the selected item, or the list index of the selected item.
Ruleset Wizard
The Ruleset Development Environment
www.rulesetwizard.com
Ruleset Wizard Tutorials
Damned's Ruleset Wizard Tutorials
-
March 25th, 2021, 08:44 #8
- Join Date
- Sep 2018
- Posts
- 75
-
March 25th, 2021, 14:52 #9
- Join Date
- Jul 2015
- Posts
- 143
That will work, and if I was working on something like this, that would be my workaround. Actually that is what my version is doing right now.
My point here is that when you create a dropdown, you add two arguments, even if you only add one. I have an idea for a ruleset and I would like to have a dropdown that returns a stored value that is different than what is displayed. It would be nice to house those values together rather than doing a big IF(Else()) table or I would probably do LUAs version of a lookup table (wish they had switch statements, but I digress).
Since we set those values anyway, all I am asking is:
1) is there a way to get the sValue that I, and others, are not seeing? (I know how to get the sText).
2) If there is NOT a way, how can I go about requesting this fix (I am going to call it a "fix" because the code looks like that was the intent)?Last edited by frostbyte000jm; March 25th, 2021 at 14:53. Reason: clarification
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks