PDA

View Full Version : onInit and Control Drawing Order



PneumaPilot
November 30th, 2008, 21:17
I am working on a ruleset that needs to have the character sheet look different depending on which type of template is selected. Currently, I have a number of beads (modified checkboxes) that, when selected, will change the appearance of the character sheet. I have had an easy time of getting the sheet to change color and getting various icons to change, but now I am actually wanting to start swapping out control elements depending on which bead is selected.

I am starting small with this endeavor. Currently, I only want to change one labeledstring. The problem I am running into is that the label of the labeled string doesn't draw. I can get the user-entered-info on the control to swap out when a different bead is selected, but the labels (which are all different) never show up. Once, I tried using the bringToFront() method to see if that would draw it, but I only ended up blanking out all of the controls that were drawn afterword. What am I doing wrong?

PneumaPilot
November 30th, 2008, 23:01
Well, I got the thing to work by copying the onInit function from the labeledstring template and modifying it. I forgot that my local onInit would take precedence over the template one.

Now I have a new problem, though. I have the thing drawing all of the text labels properly, but there is always an error message when I open a character sheet that says it tries to access labelwidget: a nil value. This doesn't stop the thing from working properly, but I just can't have an error message every time I open a sheet. Yes, labelwidget is a local variable that is set to nil at the top of the script block. How can I work around that, though? Is there a way that I can retrieve the textwidget object in my onInit and update functions? I don't see anything like that in the textwidget specification.

Foen
December 1st, 2008, 06:10
I'm not close enough to your script to be sure, but you might be having a problem with your local code over-riding the template code (and hence the template malfunctions).

When adding script to a template-based control, it is usually good practise to invoke any parent template event handlers explicitly (via the 'super' object). So you might typically code an onInit as follows:


function onInit()
if super and super.onInit then
super.onInit();
end
... rest of your local onInit goes here ...
end

This code checks to see if it is running in a context inherited from a template (in which case super is defined and points to the parent context), and whether that template has its own onInit function (so that super.onInit is non-nil), in which case it invokes the parent version of onInit first before trying to do anything locally.

You can access parent context objects using 'super', and local context objects using 'self'.

Hope that helps.

Foen

PneumaPilot
December 1st, 2008, 16:00
Yeah, I was thinking that it had to do with that and I was wondering if lua had a way of invoking the inherited function. I was actually going to try the super. prefix today. I wonder...the labeledstring template looks at the <label> element in the XML; is there a way to change this value programmatically? I know there is a section in the documentation that talks about how the XML is represented in lua. I'll check that out and see if there would be an easy way to write an update() function to pass a different label value.

Thanks again for the help, Foen. I'm glad to see that you have been made a sage. I was actually going to suggest that they make you one.

Moon Wizard
December 1st, 2008, 18:41
You could take an approach similar to the one that Tenian and I put together for the Personalities and Items in the 4E_JPG ruleset.

Example: We made a window that contained controls for all personality types (creature, trap, vehicle). Because of the stats for traps and vehicles in 4E, it made since to bundle them as a personality for easy CT use and shared fields. Whenever the GM changes the radio button for the personality type, the various fields in the window are hidden or shown to match the type desired. The other fields are still stored with all their data, but now invisible.

Cheers,
JPG

PneumaPilot
December 1st, 2008, 18:52
Yes, that's exactly what I'm trying to do. I'll have to look at how you did that for your ruleset. I suppose the thing is easy enough to obtain?

Griogre
December 1st, 2008, 20:31
Go over to FUM (https://www.fouruglymonsters.com/) and look for the 4E Developement Group. There will be a link in the forum to the download.

PneumaPilot
December 1st, 2008, 20:43
Great, I'm picking it up now. Thanks for the help.