PDA

View Full Version : Changing Default Values in a script.



Blackfoot
May 22nd, 2016, 05:07
Is it possible to change the default value for a numbercontrol using a script? I don't see a function for it on the wiki.

Trenloe
May 22nd, 2016, 05:18
In the onInit function for the control use setValue()?

Moon Wizard
May 22nd, 2016, 05:31
The problem is that the default value is used before the onInit function is called, which only happens after all controls are instantiated.

To set default values dynamically, you would have to use a numbercontrol, check for existence of node, set to default if node does not exist, link to the node's value change event to update number control.

Regards,
JPG

Blackfoot
May 22nd, 2016, 19:25
The situation I am trying to handle actually happens after the control exists.
Clearing the damage field on the combat tracker (rather than setting it) returns that field to it's default value... I want to set that default to equal a specific number but that specific number can be different for every character.. and is based on one of the character's stats.
I'm looking at trying something like this:
function update()
local node = window.getDatabaseNode();
DB.setValue(node, "default", window.stun.getValue());
window.onHealthChanged();
end
Where I want to set the default temporary of nonlethal to the permanent value of stun.

Blackfoot
May 22nd, 2016, 19:42
So.. that doesn't work.
<default>20</default>
sets the default value to 20 for that control in the xml... but you I'm having trouble altering the default value once it is set using a script.
I'm trying to follow Moon Wizard's comment but it sorta sounds like he's talking about something not quite the same as what I'm trying to do.
Ultimately, I want to do something like:
<default>nStunVal</default>
Where nStunVal = window.stun.getValue();
Obviously I'm going about this wrong... but I can't seem to find the way to get at it.

Blackfoot
May 22nd, 2016, 20:01
Hrm. This 'kinda' worked... except now it the value can't be changed at all:
function update()
local nStunVal = window.stun.getValue();
Debug.chat(nStunVal);
setValue("default", nStunVal);
Debug.chat(getValue("default") .. "!");
window.onHealthChanged();
endIt seems to be setting the value of nonlethal to the value of stun... instead of just setting the default for nonlethal. Hrm.

Moon Wizard
May 22nd, 2016, 21:01
Yeah, I was responding to a different default scenario.

How are you "clearing" the field?

Can you trigger off whatever event is triggering the clearing of the field to set the value specifically?

JPG

Blackfoot
May 22nd, 2016, 22:21
Backspace or delete clears it. It is actually pretty cool.. if I can get it to work with the correct default value.

Blackfoot
May 24th, 2016, 01:10
How are you "clearing" the field?

Can you trigger off whatever event is triggering the clearing of the field to set the value specifically?

JPGI can't seem to locate what triggers the number edit function .. onValueChanged() seems to be called AFTER the default has already been found.
I am working with the template <number_ct_crosslink> from CoreRPG.. which seems to tie back through a few things.. but doesn't seem to have any specific code for editing. So I'm guessing that it's more deeply rooted than that.

Blackfoot
May 24th, 2016, 02:27
What if I come at this from another tack... is there a way to set the default to a variable rather than an actual number? Seems like the xml code is a lot more limited than the lua so I'm thinking no... which may be the issue with this whole concept. Currently I'm setting the defaults to 10 body and 20 stun (standard for a 'normal' person) but I should know the actual values of these 95% of the time before they are actually added to the combat tracker.. the problem is that I don't know how to set them on the fly rather than in the code.
Currently I do:
<default>10</default>
and I can't really see any other way to do that.
I'd like to do:
<default>nBodyVal</default>

Trenloe
May 24th, 2016, 02:43
You can't use variables in the XML config - it's not code, it's just config that is used to create the controls. How about not setting default at all in the XML config? Then using onInit/onValueChanged events to set a value if the current value is 0/blank/cleared?

Blackfoot
May 24th, 2016, 03:20
Unfortunately, 0 is a valid value for the field... if it returned to full every time it went to 0 it would be a problem... That does make for an interesting thought though.. what if I set it to a value that it 'couldn't' be.. something like -1000 or something. Hmm.. I'll try that.

Blackfoot
May 24th, 2016, 03:23
Sweet. That totally worked. :)