PDA

View Full Version : Dropdown List not populating



bloodylemming
December 29th, 2021, 17:23
When I bring up the character sheet, I get the error
[ERROR] Script execution error: [string "comClass"]:31: attempt to index a nil value

comClass is a Dropdown List
Here's the code, in comClass that seems to be causing the error.

function onValueChanged()
local nodeChar = window.getDatabaseNode();
local isMagic = nodeChar.getChild("isMagic").getValue();
if isMagic == "false" then
nodeChar.getChild("subSlots").setInvisible(true);
else
nodeChar.getChild("subSlots").setInvisible(false);
end
end

When I comment this out, I don't get the error, but I dont' see anything inherently wrong with the code.

isMagic is a holder for a value, either true or false, and it holds it as a string, not a bool. I've confirmed this is actually happening on initialization.
So, I'm just trying to set the visibility of subSlots, based on whether the character class is a magic user or not...

Trenloe
December 29th, 2021, 17:49
The error is at line 31 - which line is line 31 within the code for that control? Look at that line and check the various components - one of them is not valid (nil) - if it's code that contains multiple API functions then separate them out onto individual lines (or write some debug for each API function) to help identify what is nil.

bloodylemming
December 29th, 2021, 20:08
The error is at line 31 - which line is line 31 within the code for that control? Look at that line and check the various components - one of them is not valid (nil) - if it's code that contains multiple API functions then separate them out onto individual lines (or write some debug for each API function) to help identify what is nil.

That item only has 27 lines of code in it...

I comment out the if/then statement and I don't get the error, so I know it's in that block. Only think I can think of is I'm not using the correct operator to turn the object invisible... Searching files for setInvisible yields nothing, but I'm not sure if there are any instances of dynamically setting the visibility of objects in CoreRPG...

Trenloe
December 29th, 2021, 20:18
Review the window control API reference here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644833/windowcontrol

There's no setInvisible, look at setVisible.

I'd recommend you familiarize yourself with the API guide and don't assume an API function exists, only use functions that are documented.

bloodylemming
December 29th, 2021, 20:36
Review the window control API reference here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644833/windowcontrol

There's no setInvisible, look at setVisible.

I'd recommend you familiarize yourself with the API guide and don't assume an API function exists, only use functions that are documented.

I've also been trying isVisible(), too see if I could get a return value, and still no luck...
I just threw a button on my sheet as a debug.


function onClickRelease(button, x, y)

local nodeChar = window.getDatabaseNode();
local sValue = nodeChar.getChild("notes").isVisible();

Debug.chat("from local ", sValue);

end

With this code, I would expect a return of bFALSE, as notes is not visible by default, but I get an error.
[ERROR] Script execution error: [string "Button1"]:5: attempt to index a nil value

Line 5 is empty. If it ignores empty lines, then end is on line five. If it starts on line 0, then the Debug.chat() has a problem...

Trenloe
December 29th, 2021, 21:14
As mentioned by @damned in a previous thread (https://www.fantasygrounds.com/forums/showthread.php?71803-getColor-setColor&p=632240&viewfull=1#post632240) - you can't do GUI operations against database nodes. The link I provided was to the API reference for the windowcontrol object - that page says "This is a base class for all elements that are contained in windows and panels."

nodeChar.getChild returns a database node - which is not a GUI window control, so you can't use the isVisible() API function - which is what is causing your error. Information on the databasenode object here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644722/databasenode - there are no API functions in the databasenode object that act against the GUI - because a databasenode acts on the underlying data. Whereas GUI controls frequently are tied to database nodes (and you can get the database node from the windows control) there reverse is not true - you can't specifically do GUI actions against a database node, because there could be multiple controls that are tied to that database node.

Trenloe
December 29th, 2021, 21:19
If you haven't already, I recommend you familiarize yourself with the concepts detailed in the Wiki Developer Guide - Create a Ruleset: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644401/Developer+Guide+-+Create+a+Ruleset

It covers the main concepts of ruleset developer and will hopefully help you understand the various aspects of the FG ruleset code and architecture.

Trenloe
December 29th, 2021, 21:46
function onClickRelease(button, x, y)

local nodeChar = window.getDatabaseNode();
local sValue = nodeChar.getChild("notes").isVisible();

Debug.chat("from local ", sValue);

end
[ERROR] Script execution error: [string "Button1"]:5: attempt to index a nil value

Line 5 is empty. If it ignores empty lines, then end is on line five. If it starts on line 0, then the Debug.chat() has a problem...

I assume this is in XML and so the first line of the code would be <script>?



Line 1<script>
Line 2 function onClickRelease(button, x, y)
Line 3
Line 4 local nodeChar = window.getDatabaseNode();
Line 5 local sValue = nodeChar.getChild("notes").isVisible();
...
Debug.chat("from local ", sValue);

end
</script>

bloodylemming
December 29th, 2021, 23:59
I assume this is in XML and so the first line of the code would be <script>?



Line 1<script>
Line 2 function onClickRelease(button, x, y)
Line 3
Line 4 local nodeChar = window.getDatabaseNode();
Line 5 local sValue = nodeChar.getChild("notes").isVisible();
...
Debug.chat("from local ", sValue);

end
</script>

I'm working in Ruleset Wizard, but that's likely what's going on with the numbering.

bloodylemming
December 30th, 2021, 00:27
As mentioned by @damned in a previous thread (https://www.fantasygrounds.com/forums/showthread.php?71803-getColor-setColor&p=632240&viewfull=1#post632240) - you can't do GUI operations against database nodes. The link I provided was to the API reference for the windowcontrol object - that page says "This is a base class for all elements that are contained in windows and panels."

nodeChar.getChild returns a database node - which is not a GUI window control, so you can't use the isVisible() API function - which is what is causing your error. Information on the databasenode object here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644722/databasenode - there are no API functions in the databasenode object that act against the GUI - because a databasenode acts on the underlying data. Whereas GUI controls frequently are tied to database nodes (and you can get the database node from the windows control) there reverse is not true - you can't specifically do GUI actions against a database node, because there could be multiple controls that are tied to that database node.

So, should I be using, something like window.notes.isVisible(); ?

damned
December 30th, 2021, 01:14
So, should I be using, something like window.notes.isVisible(); ?

yes something like that.

bloodylemming
December 30th, 2021, 02:06
yes something like that.

Is that an absolute reference or a relative one? It works when I have it in the object I want to be invisible, but not from another object on a different window...

damned
December 30th, 2021, 03:09
Window is your windowclass. If you are in the same windowclass it is
window.controlname.function()

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644833/windowcontrol
If its in a different windowclass I suggest that you dont start your learning there - move on to other parts and come back to it once more familiar with the overall interface

bloodylemming
December 30th, 2021, 03:50
Window is your windowclass. If you are in the same windowclass it is
window.controlname.function()

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644833/windowcontrol
If its in a different windowclass I suggest that you dont start your learning there - move on to other parts and come back to it once more familiar with the overall interface

I figured out a workaround. I passed the value to the window in question, and then used that objects state to update things locally. A little more work, but works like a charm.

I think I have a little beter understanding of what's going on and how things are organized, so thank you all.

damned
December 30th, 2021, 04:01
I do personally prefer to do things via the DB as you can always know the correct path to the data no matter where you are running your code from.
Window controls can be changed based on what is in the DB but you still make the change to the control and not to the data.

Keep plugging away at it - its a process of a hundred small learns and a hundred mistakes.

bloodylemming
December 30th, 2021, 04:09
I do personally prefer to do things via the DB as you can always know the correct path to the data no matter where you are running your code from.
Window controls can be changed based on what is in the DB but you still make the change to the control and not to the data.

Keep plugging away at it - its a process of a hundred small learns and a hundred mistakes.

Only a hundred, eh? !)

damned
December 30th, 2021, 04:11
Learns is learns, mistakes we reset the count every day!