5E Product Walkthrough Playlist
  1. #1
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,620

    Combobox troubles...

    Well it has been a while since I bothered with my questions now.

    I am currently trying to add a wizard's lab option to the Ars Magica ruleset to simplify for new players when they create their own spells.

    I have the basic functions in place but they look somewhat lacking and still confusing. So I have decided to make use of a drop-list for ranges, durations etc.

    ... this is where I run full tilt into problems.

    HOW do I populate the combobox that is offered in the CoreRPG? And how do I get a value back from it once it has been changed?

    I am frankly stumped.

    - Obe
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  2. #2
    You can find the code in the CoreRPG ruleset under:
    * common/scripts/combobox*.lua
    * common/template_combobox.xml

    You can add items to the combobox using the add or addItems functions:
    * The add function accepts a value parameter, with an optional display parameter. The value parameter is what is saved to the database as a string database value. If no display parameter is supplied, the value will also be used as the text to show in the combo box.
    * The addItems function accepts a table as a parameter. It assumes a table of strings, and will add each one as a value. You can not override display text with this function.

    You can get/set the value of the selected item by using the getListValue and setListValue functions.

    Regards,
    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    You can find the code in the CoreRPG ruleset under:
    * common/scripts/combobox*.lua
    * common/template_combobox.xml

    You can add items to the combobox using the add or addItems functions:
    * The add function accepts a value parameter, with an optional display parameter. The value parameter is what is saved to the database as a string database value. If no display parameter is supplied, the value will also be used as the text to show in the combo box.
    * The addItems function accepts a table as a parameter. It assumes a table of strings, and will add each one as a value. You can not override display text with this function.

    You can get/set the value of the selected item by using the getListValue and setListValue functions.

    Regards,
    JPG
    Sorry to necro this but I'm having some issues with the description above.

    I am using .add(node.getPath(),sName) to the combobox and this is what I see.



    It does show the "string" value on the drop down but the selected section shows the currently selected node.getPath() and not the sName. Is that to be expected?

    It does work other than that, this is a visual issue but I'd like to correct it if I can.

    If it matters, here is the code I use to fill the combobox.

    Code:
    -- fill in the drop down list values
    function setProfList(nodeChar)
        clear(); -- (removed existing items in list)
        -- sort through player's list of profs and add them
        -- proficiencylist
        for _,v in pairs(DB.getChildren(nodeChar, "proficiencylist")) do
          local sName = DB.getValue(v, "name", "");
          add(v.getPath(),sName);
        end
    end
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  4. #4
    Perhaps. The original combo box code was written by another community developer many years ago, and I have just been incorporating and slowly refining the template to work better and for more situations. I can almost guarantee that it was not designed for as many "use cases" as it has seen.

    In this case, this is a limitation of the original design, which uses a stringfield as the base control. This means that whatever database value is stored will be what is displayed in the base value box.

    I think you'll need to define a custom input template/control to do what you need.

    Regards,
    JPG

  5. #5
    Quote Originally Posted by Moon Wizard View Post
    Perhaps. The original combo box code was written by another community developer many years ago, and I have just been incorporating and slowly refining the template to work better and for more situations. I can almost guarantee that it was not designed for as many "use cases" as it has seen.

    In this case, this is a limitation of the original design, which uses a stringfield as the base control. This means that whatever database value is stored will be what is displayed in the base value box.

    I think you'll need to define a custom input template/control to do what you need.

    Regards,
    JPG
    Understood. I suspected as much. Thanks for the information.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  6. #6
    So, I have a working solution. It's not my favorite but I think for the return on investment it works well.

    I replaced the combobox.lua with my own. First I tweaked the combo template to use my version of the combobox.lua

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    
    <!-- 
      Please see the license.html file included with this distribution for 
      attribution and copyright information.
    -->
    
    <root>
    	<template name="combobox" merge="join">
    		<simplestring>
    			<script file="common/scripts/combobox_adnd.lua" mergerule="replace"/>
    		</simplestring>
    	</template>
    </root>
    And added getListText() and changed selectItem() (see inline)

    Code:
    -- grab text of this selection option
    function getListText()
    	if wListItemSelected then
    		return wListItemSelected.Text.getValue();
    	end
    	return "";
    end
    
    function selectItem(wNewSelection)
    	if not ctrlList then
    		return;
    	end
    	if wListItemSelected == wNewSelection then
    		return;
    	end
    	
    	if wListItemSelected then
    		wListItemSelected.setSelected(false);
    	end
    	
    	if wNewSelection then
    		wNewSelection.setSelected(true);
    	end
    	wListItemSelected = wNewSelection;
    	
      local sListValue = getListValue();
      local sListText = getListText();
      if getValue() ~= sListText then
        -- set source selected, since visible version is not the same
        -- get the name of this node, create a entry with same name_selected
              local sSourceNode = getName() .. "_selected";
              local node = getDatabaseNode();
    	  DB.setValue(node.getParent(),sSourceNode,"string",sListValue);
              setValue(sListText);
    	end
    end
    This creates a value you can reference in your code that uses the name of the entry and append "_selected". In my case the combobox control was called "prof" so it adds the "source" to "prof_selected". The "source" is the value you pass in the add(value,string) for each entry.

    add("charsheet.id-00001.proficiencylist.id-00001","Weapon Proficiency with Long Sword")
    add("charsheet.id-00001.proficiencylist.id-00002","Weapon Proficiency with Short Sword")
    add("charsheet.id-00001.proficiencylist.id-00003","Weapon Proficiency with Dagger")

    It displays the "Weapon Proficiency with *" string but lets you access the "value" (node path) programmatically.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

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
  •  
STAR TREK 2d20

Log in

Log in