View Full Version : Linking an Iconcycler
Fenloh
December 11th, 2009, 10:56
Hi there,
atm i am working on the SR4 Ruleset again and i am stuck. I have an Iconcycler in the Charsheet and another Iconcycler in the Combattracker.
It just does not link up and i am not sure why. Is it because of the Iconcycler? All other fields work finen, but then again all other fields are Numberfields.
What i am trying to do is to change the Initiative on the fly. Sometimes a Player or NPC switches from Matrix Initiative to Realworld Initiative. I want to click on the Cycler and the data is pulled from the Charsheet and the Initiative is updated.
Maybe someone can give a hint.
Fenloh
Moon Wizard
December 13th, 2009, 23:21
The iconcycler template is something I added to the JPG rulesets. It simply displays a graphic relative to an underlying string field.
If you want to update the icon based on actions of other buttons, you will have to get the databasenode object for that field, and use setValue() function.
Ex: [ window.getDatabaseNode().getChild("iconcyclersourcefield").setValue("newvalue") ]
If you want to update other fields based on the icon changing, then I built in support for an onValueChanged() function into the latest version of the iconcycler template that you can set. Otherwise, you need to create an onInit() handler, start the init handler code with super.onInit(), and then use a [ window.getDatabaseNode().getChild("iconcyclersourcefield").onUpdate = myUpdateFunction ].
Cheers,
JPG
Fenloh
December 14th, 2009, 08:19
Thanks JPG,
I thank you very much JPG, you are a great programer and i dont understand at least 20% of your code. Mostly i can follow what happens, but sometimes i am just lost (expecially if i use bits of your code from the 4ejpg ruleset :)). I tried to get the data Changed and used the onValueChanged handler, but maybe my problem is way before changeing the Value in the iconcycler, since i cant even link the sourcefields of even get the correct Data entered on a newentry....
Example:
if source.getChild("stat.ini.typ").getValue() == "astral" then
newentry.ct_calcforini.setValue("2");
newentry.ct.ini.typ.setValue("astral");
end
ct_calcforini is set to "2"
ct.ini.typ is nil and as you see below not even correctly entered
I was expecting
<ct>
<ini>
<typ type="string">"astral"</typ>
<ini>
<ct>
but only
<ct>
<ini>
<ini>
<ct>
is in the db.xml
The Value i receive is good, since i can print it (astral) and the ct_calcforini is also correctly set (2). In the db.xml file i can also see the data for the ct_calcforini.
The Value for the Source of the Iconcylcler is not there though (as above). The Newentry for setting the Value on ct.ini.typ returns a nil Value and thus creates an error.
Where is the difference between the sourcefield of the iconcycler and the ct_calcforini? It is unclear to me why the data is not correctly stored.
But then again i am also unclear why the iconcyclers standard State "standard" isnt correctly stored either. The Standardvalue seems to be empty, only if i click the iconcycler one time the standardvalue is correctly entered in the database.
Sometimes i just dont get the expected data and then i am lost. Maybe it is also that i dont understand exerything correctly that is written in english.
Mostly my problem is that i expect data and its just not there. (*sigh*)
Thanks again,
Fenloh
unerwünscht
December 14th, 2009, 08:24
I just want to say "moon_wizard is a god", I honestly think he dreams in code.... You know like the green screens from the matrix. That being said, I am lost as well, but I am sure he can get you fixed up.
Moon Wizard
December 15th, 2009, 07:52
Can you post the XML/script code for your iconcycler control definition?
In the example that you quoted, you wrote newentry.ct.ini.typ.setValue("astral"), which I do not think is a valid way to access a datafield.
You either have to access the control directly [i.e. newentry.controlname.setValue("astral") where controlname has a source attribute of "ct.ini.typ"] or you have to access the databasenode directly [i.e. newentry.getDatabaseNode().getChild("ct.ini.typ").setValue("astral")]
If you post the XML/script code for the iconcycler you are building, I might be able to clarify more.
Cheers,
JPG
Fenloh
December 15th, 2009, 09:03
I thank you, great wizard and hero of the forsaken wannabe programmers like me. It worked! Heureka!
But even if it worked, i dont really understand the difference. When do i access the control, and when do i use the Database? I have had my problems in the past with that. Maybe that is the same Problem as with the categoryselection control that i have.
Fenloh
Fenloh
December 15th, 2009, 09:40
Now that the setValue works i want the Link to be established. unfortunatly this does not work with the inconcycler.
newentry.ct_IniPasses.setLink(source.getChild("stat.inipass.score"));
this works
newentry.ct_IniTyp.setLink(source.getChild("stat.ini.typ"));
this returns Erorr "attempt to call global Variable 'setValue' (a nil Value)
Fenloh
Moon Wizard
December 16th, 2009, 17:56
The setLink function is only defined in the ctnumberfield and ctstringfield templates. You will have to build a new setLink function to work for an iconcycler.
An untested example of code to add to template_iconcycler.lua. Make sure to remove the previous onValueChanged function.
locked = false;
linknode = nil;
function onValueChanged()
synch_index();
updateDisplay();
if self.onValueChanged then
self.onValueChanged();
end
if linknode and not isReadOnly() then
if not locked then
locked = true;
linknode.setValue(getSourceValue());
locked = false;
end
end
end
function onLinkUpdated(source)
if source then
if not locked then
locked = true;
setSourceValue(source.getValue());
locked = false;
end
end
if self.onValueChanged then
self.onValueChanged();
end
end
function setLink(dbnode, readonly)
if dbnode then
linknode = dbnode;
linknode.onUpdate = onLinkUpdated;
if readonly == true then
setReadOnly(true);
end
onLinkUpdated(linknode);
end
end
Cheers,
JPG
Fenloh
December 17th, 2009, 17:44
Well it returned a Stack overflow when i changed the Cycler on the charsheet_main.
Well in this Version, that is based on the old Foundation Ruleset, i wont change it anymore. I`d like to start a new version of it based on the 4E_JPG 1.5.1 Ruleset. If you allow it that is, moon_wizard. I understand a lot more of the code than i did in the beginning.
Most likely there will be some more stupid questions hehe.
Fenloh
Moon Wizard
December 18th, 2009, 07:29
A stack overflow usually occurs when there is an endless loop somewhere in the code. Without having the code in front of me, I'm not sure what the problem is exactly. In these situations, I usually comment out or remove any new code/functions until I stop getting the error, then look at the last piece of code I removed before the error went away.
You're welcome to use any of the code in the JPG rulesets given that your work is for community rulesets. If you are going to build a ruleset/mod for sale, then we can chat more about it then.
There are a lot of custom functions and templates in the 4E_JPG ruleset, but I will try to answer any questions that come up. The iconcyler template is from my d20_JPG and 4E_JPG rulesets.
Cheers,
JPG
Fenloh
August 8th, 2011, 11:38
Well it only took some 4 Years to get back to that very same Question :).
I have a "button_iconcycler" on the Charsheet and the same cycler on the CT. I need to link them.
I have tried to implement the setLink and the onLinkUpdated to the "button_iconcycler.lua but i always get different errors like "attempt to call global "getValue" as if it defined this as avariable.
1. Do i need to setup a different Template for the CT or can i use the same Template that i have used for the Charsheet?
2. Well how do i link them. The Code is from the 3.5e Version of the FG.V2.8
Fenloh
Moon Wizard
August 9th, 2011, 00:54
The iconcycler is not a basic field, so it's not directly linked to the database like number or string. However, in the template code for the iconcycler, it automatically creates and monitors the database node specified in the name attribute of the object.
You could potentially reuse the string_ct template to create a hidden stringfield object that is linked to the cycler database node on the character sheet. Then, set the database node for the CT cycler to the database node of the hidden CT string that is linked. To set the source for the cycler, you set a "name" tag within a "source" tag within the cycler's tags.
Cheers,
JPG
Fenloh
August 9th, 2011, 06:08
Hi,
some things can be so easy....
thanks a lot!
Fenloh
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.