PDA

View Full Version : .getColor/.setColor



bloodylemming
December 23rd, 2021, 21:27
I'm trying to control the color of labels, dynamically, but I'm not having any luck. Can someone clue me on on the syntax?

damned
December 23rd, 2021, 22:26
Did you do a find in files on 5E?
There are many examples of setColor() (but none of getColor)

Trenloe
December 24th, 2021, 00:11
1) Look in the API guide for details of available API commands. setColor() for a text based control is detailed here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644760/textbasecontrol#setColor As @damned mentions, there's no getColor API function.
2) As @damned mentions, look for examples in existing rulesets. I extract the CoreRPG ruleset and the ruleset I'm working on into directories outside of the FG rulesets directory (so FG doesn't read the extracted data) and then use find in files to get examples of what I'm working on.

bloodylemming
December 24th, 2021, 01:37
1) Look in the API guide for details of available API commands. setColor() for a text based control is detailed here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644760/textbasecontrol#setColor As @damned mentions, there's no getColor API function.
2) As @damned mentions, look for examples in existing rulesets. I extract the CoreRPG ruleset and the ruleset I'm working on into directories outside of the FG rulesets directory (so FG doesn't read the extracted data) and then use find in files to get examples of what I'm working on.

Didn't realize that API was available, thank you. Yup, looks like I was trying to shove the wrong type of data into that method, but even when I corrected it, it's still not working.

Here's the specific error I'm getting.
[ERROR] Script execution error: [string "chkStrength"]:8: attempt to index a nil value

damned
December 24th, 2021, 02:09
That specific error is telling you to look at the script code associated with the object chkStrength on line 8 or line 7.
Please post the whole code you have there.

bloodylemming
December 24th, 2021, 02:55
That specific error is telling you to look at the script code associated with the object chkStrength on line 8 or line 7.
Please post the whole code you have there.

Here's my test code there...


function onValueChanged()

local nodeChar = window.getDatabaseNode();
local colValue = 008000;

nodeChar.getChild("lblStrength").setColor("A3A29D");

end

damned
December 24th, 2021, 03:19
Here's my test code there...


function onValueChanged()

local nodeChar = window.getDatabaseNode();
local colValue = 008000;

nodeChar.getChild("lblStrength").setColor("A3A29D");

end

This looks like you are doing it on a LABEL
Can you try the same commands on a STRING FIELD?
What happens?

bloodylemming
December 24th, 2021, 03:35
This looks like you are doing it on a LABEL
Can you try the same commands on a STRING FIELD?
What happens?

Same error

damned
December 24th, 2021, 04:01
please share your RWP file and the exact window and object that the code is attached to and how to initiate the error

bloodylemming
December 24th, 2021, 04:51
please share your RWP file and the exact window and object that the code is attached to and how to initiate the error

Here's the RWP file. I've pared it down to just the items in question and confirmed it's throwing the error. Just click the checkbox.
Should be attached...

damned
December 24th, 2021, 05:06
nodeChar.getChild("lblStrength")
is referencing DATA in the DATABASE. data doesnt have color.

you need to reference the object that is being displayed on the screen
window.lblStrength.setColor("FF9900");

bloodylemming
December 24th, 2021, 05:48
nodeChar.getChild("lblStrength")
is referencing DATA in the DATABASE. data doesnt have color.

you need to reference the object that is being displayed on the screen
window.lblStrength.setColor("FF9900");



Okay, so I did this, which worked:


function onValueChanged()

local nodeChar = window.getDatabaseNode();
local bValue = nodeChar.getChild("chkStrength").getValue();
local colPro = "049101";
local colNon = "002333";

window.lblStrength.setColor(colPro);

end

Then I did this, which didn't work.


function onValueChanged()

local nodeChar = window.getDatabaseNode();
local bValue = nodeChar.getChild("chkStrength").getValue();
local colPro = "049101";
local colNon = "002333";

if bValue = 1 then
window.lblStrength.setColor(colPro);
else
window.lblStrength.setColor(colNon);
end

end

I must be building the if/then/else statement wrong. Am I mishandling bValue? type() shows it as a number, so I don't think it's miscast...

damned
December 24th, 2021, 06:01
try true instead of 1

psicodelix
December 24th, 2021, 06:47
the equality comparisons in lua are with ==, so try:

if bValue == 1 then

bloodylemming
December 24th, 2021, 08:00
the equality comparisons in lua are with ==, so try:

if bValue == 1 then

Ah, I thought that meant not equal...
That did the trick. Now I can build that into a function and clean up that part of the character sheet. Thank you all very much.

darrenan
December 24th, 2021, 18:10
https://www.lua.org/manual/5.1/ is a good reference for all things LUA.

bloodylemming
December 24th, 2021, 22:14
nodeChar.getChild("lblStrength")
is referencing DATA in the DATABASE. data doesnt have color.

you need to reference the object that is being displayed on the screen
window.lblStrength.setColor("FF9900");

If I were to move this into a function, would I identify the particular window it's to be operated on? for instance window.charsheet_main.setColor();

damned
December 25th, 2021, 23:15
you have to know the window reference.
id leave it where it is.

bloodylemming
December 26th, 2021, 18:15
you have to know the window reference.
id leave it where it is.

Yea, that's basically what I've done. Used the function to get the value (what color to use) and used that return value to set it locally. Works like a charm, and if those colors need to be changed, it's done in one place.