PDA

View Full Version : windowcontrol updates



drahkar
December 23rd, 2010, 01:52
Does anyone have any suggestions on how I would implement the monitoring of a control from another control to see when it was updated?

For example:

a numbercontrol in one window needs to know when a genericcontrol in another window is updated so it can fire a series of functions.

Does anyone have any thoughts or suggestions how that might be implemented? I suppose i could create an intermediary process through a database node. But frankly I don't like that idea.

Bidmaron
December 23rd, 2010, 02:23
The database node is the only way I know of, but I am not an expert on fg2 coding quite yet. The onupdate triggers for the database doesn't sound like such a bad way to go to me. In fact, as long as the control IS persistent, it's hard to imagine intercontrol events being any more graceful than the database update events.

StuartW
December 23rd, 2010, 06:29
The only other way is to put code in the generic control's script that updates the number control, but that can be at least as ugly and only works if the controls share the same top window (so you can reach one from the other via script).

Stuart

Ikael
December 23rd, 2010, 06:30
If you want to play with controls that are associated with databasenode (ie. stringfield, numberfield, etc.) I would recommend to implement the monitoring using databasenode's onUpdate() handler. If monitored control is genericcontrol then I believe this is the only way, if and only if that genericcontrol is associated with databasenode. Otherwise it could get very tricky.

drahkar
December 23rd, 2010, 08:04
Thats what I was afraid of. Was just trying to sort things out for possible solutions.

Thanks everyone for their thoughts.

Moon Wizard
December 23rd, 2010, 15:08
You can do it through controls, but then you have to ensure that both controls exist. You essentially catch the onValueChanged event of the triggering control, then navigate the window/control namespace to the control you want to update.

I've done both, and the database approach is actually simpler and less error-prone.

Cheers,
JPG

drahkar
December 23rd, 2010, 16:09
Which is less resource intensive? As thats actually the primary concern I have.

Moon Wizard
December 23rd, 2010, 22:43
The database approach is actually less resource intensive, since the controls don't need to exist to use that approach and the database nodes are always available.

Regards,
JPG

drahkar
December 24th, 2010, 01:41
Well alright then! :) Perfect.

drahkar
December 24th, 2010, 12:22
Along this line of work then.... Why would this be throwing an 'attempt to index a nil value' error?


local modstackEdit = ModifierStack.control.getDatabaseNode().createChil d("modstack.edit.status");

Moon Wizard
December 24th, 2010, 15:57
You would have to check each step in the chain to be sure. (i.e. check ModifierStack, then ModifierStack.control, then ...)

However, I believe in this case that the modifier stack is actually a control that is not tied to the database. (i.e. the stack does not need to be remembered between sessions.) Thus, the getDatabaseNode() call would return a nil value.

I had assumed that you were modifying that character sheet or combat tracker, in which all numerical and non-label string fields are tied to the database.

Perhaps you can give me an overview of what you are trying to accomplish exactly, and I can give you a better answer.

Regards,
JPG

drahkar
December 24th, 2010, 16:12
*facepalms* I'll bet you are exactly right.

What I'm doing is building a means of allowing my diepool code to recognize when the modstack code has changed it's value.

Moon Wizard
December 25th, 2010, 00:00
In that case, you will need both the modifier stack and the dice pool to be global scripts, which can be accessed from anywhere inside the LUA code.

In most rulesets, this has already been done with the modifier stack (i.e. ModifierStack). You would just need to do it for the die pool management. Then, you would need to add an onValueChanged event handler in the relevant modifier stack control, which in turn would call the correct die pool manager code function.

Cheers,
JPG

drahkar
December 25th, 2010, 08:29
Ok. I'm almost entirely there. But I've run into a snag. There are multiple controls that need to be updated. Unfortunately the registerControl() function when used on the control itself doesn't work because it only registers the last control. And setting it on the underlying window would work, but then I'd have to create a list of all of the low and high pools on the entire sheet so that it can properly loop through and updated them each time. That just doesn't seem efficient to me.

Any thoughts on a good solution?

StuartW
December 25th, 2010, 10:57
Modify the registerControl function so that it adds the control to a Lua table, and then iterate over that table whenever the value changes?

StuartW
December 25th, 2010, 10:58
BTW Happy Christmas!

drahkar
December 25th, 2010, 15:26
Ooo. Thats an excellent idea!

Merry Christmas! :)

drahkar
December 25th, 2010, 17:08
That idea worked perfectly. Thank you Stuart. :)