FG Spreadshirt Swag
  1. #1

    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.

  2. #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):

  3. #3
    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

  4. #4
    Quote Originally Posted by frostbyte000jm View Post
    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
    Copy the code - write your own version - mine is called mycombobox - then use that. Then you can just add in the logic you want for it.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  5. #5
    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.

  6. #6
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    if getValue() == "Small" then sDice = "2d4"
    elseif getValue() == "Medium" then sDice = "2d6"
    elseif getValue() == "Large" then sDice = "2d8"
    end

    ??

  7. #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

  8. #8
    Quote Originally Posted by damned View Post
    if getValue() == "Small" then sDice = "2d4"
    elseif getValue() == "Medium" then sDice = "2d6"
    elseif getValue() == "Large" then sDice = "2d8"
    end

    ??
    Thats what I use now.
    I think there was a function getListValue at a time which got removed (and made me wonder a lot why thinks stopped working).

  9. #9
    Quote Originally Posted by damned View Post
    if getValue() == "Small" then sDice = "2d4"
    elseif getValue() == "Medium" then sDice = "2d6"
    elseif getValue() == "Large" then sDice = "2d8"
    end

    ??
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in