PDA

View Full Version : Manipulating Sources..



Blackfoot
April 27th, 2020, 15:59
So I'm working on this problem where a primary number value can be reduced by a source value, but only if the primary value remains greater than a given number.

I tried setting up an onValueChanged() function in the primary value to check if it goes under the number and it works but when I do a setValue() on the source to remove it, it fails to updated the primary value, leaving the primary value adjusted. I'm guessing that I'm doing the wrong call to make that happen and thus avoiding the source adjusting code.

function onValueChanged()
local nodeWeapon = getDatabaseNode().getChild("....");
if getValue() < 50 then
DB.setValue(nodeWeapon, source[3]["name"][1], "number", 0);
end
endAnyone have some suggestions?

darrenan
April 27th, 2020, 18:03
Why don't you just add <min>50</min> to the number control?

darrenan
April 27th, 2020, 18:06
Also, if the control is a numberfield (i.e. linked to a node in the database) then you probably want to be setting the value on the control, not directly on the node? Maybe? Or does that set up an infinite recursion through onValueChanged?

I still think you're better off just setting the min and max values you allow in the control, unless I misunderstand what the logic needs to be.

Blackfoot
April 27th, 2020, 19:12
Is that min value going to work if the control is being changed by a source?

celestian
April 27th, 2020, 19:47
So I'm working on this problem where a primary number value can be reduced by a source value, but only if the primary value remains greater than a given number.

I tried setting up an onValueChanged() function in the primary value to check if it goes under the number and it works but when I do a setValue() on the source to remove it, it fails to updated the primary value, leaving the primary value adjusted. I'm guessing that I'm doing the wrong call to make that happen and thus avoiding the source adjusting code.

function onValueChanged()
local nodeWeapon = getDatabaseNode().getChild("....");
if getValue() < 50 then
DB.setValue(nodeWeapon, source[3]["name"][1], "number", 0);
end
endAnyone have some suggestions?


DB.setValue(nodeWeapon, source[3]["name"][1], "number", 0);

What is "source" there? Have you output that in debug to see what it actually is?

Blackfoot
April 27th, 2020, 19:52
Sure.. it is the info for the sources for that control... it inherits number_linked from CoreRPG... source is a variable in that template.

celestian
April 27th, 2020, 19:59
Sure.. it is the info for the sources for that control... it inherits number_linked from CoreRPG... source is a variable in that template.

If you're certain that is correct... What is the "primary" value you are talking about and what is the Source you are changing.

If they are the same, have you tried and use the "minimum" setting mentioned above?

Sorry, the smallish clip of code is making it difficult for me to get a handle on what you're trying to do.

Blackfoot
April 27th, 2020, 20:27
If you don't work with the number_linked template then you probably won't have the answer I'm looking for here.
'number_linked' is the 'common' template that allows CoreRPG controls to talk to each other and share data behind the scenes.
You can set a <source> in a control and tell it how that source relates to your control, then that second value will be added or subtracted from your initial control. I was kinda hoping to talk with someone who worked with this template a good bit and was familiar with it's nuances.
In my situation.. the primary value is your 'skill', it could be a number between 0% and 200% or more, and the secondary value is based on how you want to split your skill up... assuming you can keep at least 50% in the primary skill... so I'm subtracting the 'source'.. which is the number you want to reduce your skill by in order to increase a 3rd number, your 'split' value. The check I'm working on is the one that prevents you from taking 151 from your skill of 200... 150 would be ok.. but 151 is right out. My plan is to bounce those entries entirely... which my code snip does.. kinda. What it doesn't do is undo what the number_linked code does... that is.. if you tell the primary value to reset itself... which honestly.. I assumed would happen when the source changed.