Thread: Loading variables ><
-
May 12th, 2011, 04:52 #1
- Join Date
- Feb 2009
- Location
- Jacksonville, Florida
- Posts
- 153
Loading variables ><
Hey, I'm back to work on my system, and I'm loading a bunch of variables from the "inventory" page to the main page. Problem is when you create a new character, the variables aren't created yet. So they all bug in the scripting
How can I make it so these variables are all created upon character creation? Put them on the main page and hide them perhaps? Is there a less ghetto way?"Tis better to die on your feet, then live on your knees."
-
May 12th, 2011, 08:27 #2
Super-keen to help, but feel I need some code snippets here ! That said, I've been coding all day, so maybe others are a little more alert that I right now.
-
May 12th, 2011, 11:33 #3
I would suggest that you have your initial lookup for the databasenode use createChild instead of getChild. They function exactly the same only with createChild, if it doesn't exist yet, then it creates an empty databasenode instead of throwing an error. That or if you have a specific default value you want in it if there is nothing in the node then make a function that your wrap around createChild that says if the return value of getting the information from the database node is nil, create the node with createChild and then set the default value. Otherwise just get it.
- Trying to find a community Ruleset, Extension or Information on how to complete a process? Try FGRepository.
- PM Myself if you have new or updated community Rulesets, Extensions or Information that you'd like added to FGRepository.
-
May 12th, 2011, 16:57 #4
- Join Date
- Feb 2009
- Location
- Jacksonville, Florida
- Posts
- 153
I put it as createChild, and then it gave me a bunch of arithematic errors. I'll try to figure out how to createChild 0 but won't that result in reseting my variables to 0 each time the charsheet loads?
"Tis better to die on your feet, then live on your knees."
-
May 12th, 2011, 17:03 #5
- Join Date
- Feb 2009
- Location
- Jacksonville, Florida
- Posts
- 153
Code:<!--Agility--> <abilityscore name="agility" source="stats.agility"> <anchored> <to>vitality</to> </anchored> <noreset /> <readonly /> <script> function update() Tagi = source.getValue() Ragi = source2.getValue() Bagi = source3.getValue() setValue(Tagi+Ragi+Bagi) end function onInit() source = window.trueagility.getDatabaseNode() source2 = window.raceagility.getDatabaseNode() source3 = window.agility_bonus.getDatabaseNode() source.onUpdate = update source2.onUpdate = update source3.onUpdate = update update() end </script> </abilityscore> <abilityscore5 name="trueagility" source="trueagility"> <noreset /> <readonly /> </abilityscore5> <abilityscore name="raceagility" source="stats.race.agility"> <noreset /> <readonly /> <script> function update() raceagibase = Globals.raceagi(source) setValue(raceagibase) end function onInit() setVisible(false); source = window.getDatabaseNode().getChild("race") source.onUpdate = update update() end </script> </abilityscore> <abilitylabel> <anchored> <to>agility</to> </anchored> <static>AGI</static> </abilitylabel> <abilityscore2 name="agility_bonus" source="stats.agility_bonus"> <anchored> <to>agility</to> </anchored> <noreset /> <script> function update() head_agi_bonus = source.getValue() torso_agi_bonus = source1.getValue() legs_agi_bonus = source2.getValue() feet_agi_bonus = source3.getValue() shoulders_agi_bonus = source4.getValue() rightarm_agi_bonus = source5.getValue() leftarm_agi_bonus = source6.getValue() ring1_agi_bonus = source7.getValue() ring2_agi_bonus = source8.getValue() ring3_agi_bonus = source9.getValue() ring4_agi_bonus = source10.getValue() necklace_agi_bonus = source11.getValue() charm_agi_bonus = source12.getValue() weapon1_agi_bonus = source13.getValue() weapon2_agi_bonus = source14.getValue() weapon3_agi_bonus = source15.getValue() weapon4_agi_bonus = source16.getValue() setValue(head_agi_bonus + torso_agi_bonus + legs_agi_bonus + feet_agi_bonus + shoulders_agi_bonus + rightarm_agi_bonus + leftarm_agi_bonus + ring1_agi_bonus + ring2_agi_bonus + ring3_agi_bonus + ring4_agi_bonus + necklace_agi_bonus + charm_agi_bonus + weapon1_agi_bonus + weapon2_agi_bonus + weapon3_agi_bonus + weapon4_agi_bonus) end function onInit() source = window.getDatabaseNode().createChild("stats.equipment_head_agi_bonus") source1 = window.getDatabaseNode().createChild("stats.equipment_torso_agi_bonus") source2 = window.getDatabaseNode().createChild("stats.equipment_legs_agi_bonus") source3 = window.getDatabaseNode().createChild("stats.equipment_feet_agi_bonus") source4 = window.getDatabaseNode().createChild("stats.equipment_shoulders_agi_bonus") source5 = window.getDatabaseNode().createChild("stats.equipment_rightarm_agi_bonus") source6 = window.getDatabaseNode().createChild("stats.equipment_leftarm_agi_bonus") source7 = window.getDatabaseNode().createChild("stats.equipment_ring1_agi_bonus") source8 = window.getDatabaseNode().createChild("stats.equipment_ring2_agi_bonus") source9 = window.getDatabaseNode().createChild("stats.equipment_ring3_agi_bonus") source10 = window.getDatabaseNode().createChild("stats.equipment_ring4_agi_bonus") source11 = window.getDatabaseNode().createChild("stats.equipment_necklace_agi_bonus") source12 = window.getDatabaseNode().createChild("stats.equipment_charm_agi_bonus") source13 = window.getDatabaseNode().createChild("stats.equipment_weapon1_agi_bonus") source14 = window.getDatabaseNode().createChild("stats.equipment_weapon2_agi_bonus") source15 = window.getDatabaseNode().createChild("stats.equipment_weapon3_agi_bonus") source16 = window.getDatabaseNode().createChild("stats.equipment_weapon4_agi_bonus") source.onUpdate = update source1.onUpdate = update source2.onUpdate = update source3.onUpdate = update source4.onUpdate = update source5.onUpdate = update source6.onUpdate = update source7.onUpdate = update source8.onUpdate = update source9.onUpdate = update source10.onUpdate = update source11.onUpdate = update source12.onUpdate = update source13.onUpdate = update source14.onUpdate = update source15.onUpdate = update source16.onUpdate = update update() end </script> </abilityscore2> <diescore2 name="Agility Check"> <anchored> <to>agility</to> </anchored> <script> function onClickDown(button, x, y) setDice({"d20"}); end </script> </diescore2> <modbox name="Agility CheckMod"> <bounds>1,1,1,1</bounds> <script> function update() AgiCheck = source.getValue() setValue(AgiCheck) end function onInit() setVisible(false); source = window.getDatabaseNode().getChild("stats.agility") source.onUpdate = update update() end </script> </modbox> <genericcontrol> <bounds>366,143,18,17</bounds> <icon>stat_up</icon> <script> function onClickDown(button, x, y) trueagility = window.getDatabaseNode().getChild("trueagility"); statpoints = window.getDatabaseNode().getChild("statpoints"); if statpoints.getValue() > 0 then trueagility.setValue(trueagility.getValue()+1); statpoints.setValue(statpoints.getValue()-1); end end </script> </genericcontrol>
"Tis better to die on your feet, then live on your knees."
-
May 12th, 2011, 17:47 #6
What createChild does is creates a databasenode at the location if it doesn't exist, otherwise it gets the data fro the existing node per getChild. When it is initially created, the databasenode has nothing in it. Its an empty value. You then have to either setValue something to it, OR set your code so that it can recognize that its an empty node and process the data from it accordingly.
- Trying to find a community Ruleset, Extension or Information on how to complete a process? Try FGRepository.
- PM Myself if you have new or updated community Rulesets, Extensions or Information that you'd like added to FGRepository.
-
May 12th, 2011, 17:57 #7
- Join Date
- Feb 2009
- Location
- Jacksonville, Florida
- Posts
- 153
Could you give me an example as how to do this? How do I tell the code to process accordingly? I really don't want createChild to SetValue every time the charsheet is opened because a few pages down the enchantments are saved.
"Tis better to die on your feet, then live on your knees."
-
May 12th, 2011, 18:41 #8
createChild doesn't set anything. It merely creates a blank databasenode if it doesn't exist.
For example:
Code:<abilityscore name="agility" source="stats.agility"> <anchored> <to>vitality</to> </anchored> <noreset /> <readonly /> <script> function onInit() agi = window.getDatabaseNode().createChild("stats.agility"); agiValue = agi.getValue(); if agiValue ~= nil then else setValue(10); end end </script> </abilityscore>
I would also consider adding this code into the abilityscore template instead of having it here. Instead having it be something line this:
Code:<template name="abilityscore"> <numberfield> <anchor information> <other information and layout data> <statname mergerule="replace"> <script> function onInit() statNode = window.getDatabaseNode().createChild("stats." .. statname[1]); statValue = statNode.getValue(); if statValue ~= nil then else setValue(10); end end </script> </numberfield> </template> <abilityscore name="agility" source="stats.agility"> <anchored> <to>vitality</to> </anchored> <noreset /> <readonly /> <statname>agility</statname> </abilityscore>
Does this help explain what I mean?- Trying to find a community Ruleset, Extension or Information on how to complete a process? Try FGRepository.
- PM Myself if you have new or updated community Rulesets, Extensions or Information that you'd like added to FGRepository.
-
May 12th, 2011, 22:03 #9
- Join Date
- Feb 2009
- Location
- Jacksonville, Florida
- Posts
- 153
This definitely explains what you mean but the structure is completely foreign to me.
Code:<statname mergerule="replace"> <script> function onInit() statNode = window.getDatabaseNode().createChild("stats." .. statname[1]); statValue = statNode.getValue(); if statValue ~= nil then else setValue(10); end end </script>
So;
statNode = window.getDatabaseNode().createChild("stats." .. statname[1]);
This would pull all the stats.agility.whatever and pool them together? I might have to restructure my entire ruleset to accomadate this... I also don't see an update() command. Does it update automatically in this structure?"Tis better to die on your feet, then live on your knees."
-
May 12th, 2011, 23:05 #10
<statname mergerule="replace"> passes into the code as statname[1].
This will create a single node stats.agility
statNode = window.getDatabaseNode().createChild("stats." .. statname[1]);
This is a relatively basic process that, when the control is initialized, it runs this code. It doesn't have an onUpdate applied to it, but the information within this is easily adaptable for that purpose. I just wrote out the example in the simplest process so speeds.- Trying to find a community Ruleset, Extension or Information on how to complete a process? Try FGRepository.
- PM Myself if you have new or updated community Rulesets, Extensions or Information that you'd like added to FGRepository.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks