1. #1

    [programming] Activate Character Sheet Values

    Hey guys! I’m back with yet another question. Probably a simple answer out there.

    In my AlienRPG ruleset, if you open a character sheet, and do not go to the “abilities” tab first, but instead try to toggle the “stressed” button (which checks the values of numbers in the abilities tab) you get an error about a “nil value”. Basically, the numbers don’t exist until the “abilities” tab has been opened.

    This flows over to the combat tracker as well. If I have a PC in the combat tracker when I start up the campaign, and open the combat tracker before the character sheet has been opened, it fails to find/index the “radsmin” value on charsheet_main2 (the one with all the fancy graphics)

    How can I activate those values or that tab upon starting the combat tracker or opening the character sheet?
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  2. #2
    In those cases, you need to have the stressed button or combat tracker options use the DB.setValue() functions to set the data on the numbers; or use DB.getValue() to query those numbers. In that way, if the fields don't exist, then DB.setValue() will create them when it sets the value, and DB.getValue() allows you to specify a default value if a field doesn't exist yet.

    Regards,
    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    In those cases, you need to have the stressed button or combat tracker options use the DB.setValue() functions to set the data on the numbers; or use DB.getValue() to query those numbers. In that way, if the fields don't exist, then DB.setValue() will create them when it sets the value, and DB.getValue() allows you to specify a default value if a field doesn't exist yet.

    Regards,
    JPG
    I will try this out. Do I need to include any kind of getDataBaseNode or getChild() functions? Or should DB.getValue() all that’s needed to set that value?
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,677
    Quote Originally Posted by pr6i6e6st View Post
    I will try this out. Do I need to include any kind of getDataBaseNode or getChild() functions? Or should DB.getValue() all that’s needed to set that value?
    setValue() will set the value. But DB.getValue() does allow you to specify a default, which will be returned if the node doesn't already exist - this will avoid the nil error, but may not give you what you need.

    But, how are you trying to get the data? Via the GUI controls or via the database? It's always best to go via the database, so that you're not relying on controls being activated (e.g. tabs opened) before you access them. But, even this is not 100% fool-proof, as database fields won't be created unless the controls have been activated or code written to create the fields. Some info on a related issue: https://www.fantasygrounds.com/forum...l=1#post453491

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    Register at www.fg-con.com for all the latest info.

    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    Quote Originally Posted by Trenloe View Post
    setValue() will set the value. But DB.getValue() does allow you to specify a default, which will be returned if the node doesn't already exist - this will avoid the nil error, but may not give you what you need.

    But, how are you trying to get the data? Via the GUI controls or via the database? It's always best to go via the database, so that you're not relying on controls being activated (e.g. tabs opened) before you access them. But, even this is not 100% fool-proof, as database fields won't be created unless the controls have been activated or code written to create the fields. Some info on a related issue: https://www.fantasygrounds.com/forum...l=1#post453491
    here is what i have for the stressed button on the character sheet main page
    Code:
    <buttongroup_counter name="isstressed">
    				<anchored to="dateframe" width="20">
    					<right anchor="right" offset="-10" />
    					<top offset="40" />
    				</anchored>
    				<sourcefields>
    					<current>hiddenstress</current>
    				</sourcefields>
    				<values>
    					<maximum>1</maximum>
    				</values>
    				<tooltip text="Unchecked = automatic Stress reduction / Checked = no automatic Stress reduction" />
    				<script>
    					function onValueChanged()
    						local Hungry = window.getDatabaseNode().getChild(".hungry").getValue();
    						local Thirsty = window.getDatabaseNode().getChild(".thirsty").getValue();
    						local Sleepy = window.getDatabaseNode().getChild(".sleepy").getValue();
    						local Cold = window.getDatabaseNode().getChild(".cold").getValue();
    						
    						if window.hiddenstress.getValue() == 0 and Hungry == 0 and Thirsty == 0 and Sleepy and Cold == 0 then
    							window.stressroll.onToggleon();
    							window.hiddenstress.setValue(0);
    						end
    						if window.hiddenstress.getValue() == 1 or Hungry == 1 or Thirsty == 1 or Sleepy == 1 or Cold == 1 then
    							window.stressroll.onToggleoff();
    							window.hiddenstress.setValue(1);
    						end
    						
    						
    					end
    				</script>
    			</buttongroup_counter>
    			<number_ct_crosslink name="hiddenstress" source="hiddenstress">
    				<anchored to="isstressed" position="above" offset="30,-40" width="30" height="20" />
    				<invisible />
    			</number_ct_crosslink>

    and here's the code for the hungry number to link with the combat tracker and toggles the stressed button above.

    Code:
    <number_ct_crosslink name="hiddenstress" source="hiddenstress">
    				<anchored to="conditionsframe" position="insidetopright" offset="30,0" width="30" height="20" />
    				<invisible />
    				<script>
    					function ToggleOn()
    						setValue(1);
    					end
    					function ToggleOff()
    						setValue(0);
    					end
    				</script>
    				<invisible />
    			</number_ct_crosslink>
    
    (labels and other stuff between here)
    
    
    <number_ct_crosslink name="hungry" source="hungry">
    				<anchored to="conditionsframe" position="insidetopleft" offset="73,15" width="13" height="15" />
    				<invisible />
    				<script>
    					function onValueChanged()
    						nHungry = getValue();
    						nThirsty = window.thirsty.getValue();
    						nSleepy = window.sleepy.getValue();
    						nCold = window.cold.getValue();
    						local StateTime = CalendarManager.getCurrentTimeString();
    						local ActName = window.getDatabaseNode().getChild(".name").getValue();
    						
    						if nHungry == 0 then
    							local msg = {font = "chatfont", text = "" .. StateTime .. ": " .. ActName .. " is no longer Hungry.", secret = false};
    							Comm.deliverChatMessage(msg);
    							if nThirsty == 0 and nSleepy == 0 and nCold == 0 then
    								if window.hiddenstress.getValue() == 1 then
    									window.hiddenstress.ToggleOff();
    								end
    							end
    						end
    						if nHungry == 1 then
    							window.hiddenstress.ToggleOn();
    							local msg = {font = "chatnpcfont", text = "" .. StateTime .. ": " .. ActName .. " is Hungry.", secret = false};
    							Comm.deliverChatMessage(msg);
    						end
    					end
    				</script>
    			</number_ct_crosslink>
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  6. #6
    i might have fixed the error messages? i'm not entirely sure but i can't replicate it anymore.
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,677
    Like I said in the post I linked - if the database fields are on another tab, that isn’t the main tab so the fields aren’t created until you go to that other tab for the first time (just once after creating the character), don’t use getChild but use createChild.

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    Register at www.fg-con.com for all the latest info.

    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in