PDA

View Full Version : Access controls inside Windowlist



MadBeardMan
June 29th, 2020, 17:22
Hey All,

Got a bit of a brain twizzler going on.

I've got a frame inside which I had some labels, after the labels I have a windowlist inside I have some controls.

When I drag something to that windowlist, it accepts it, I know what it is and I add it to the databasenode, all good stuff.

Now what I want to do, is to show/hide a field that's inside that windowlist, using the script that's part of the windowlist.

If I want to show hide the labels, that's all good I use 'window.label_ammo_rof.setVisible(bVisible)' - that also all works perfectly.

If I use 'Debug.console(self.getName())' it returns to me 'damageactions' which again is perfect.

I have a control called 'ammorateoffire' (it's a stringcycler) but I can't hide/show it, it can't find it.

I've tried:

self.ammorateoffire.setVisible(bVisible);
ammorateoffire.setVisible(bVisible);

And neither do anything except throw an error `attempt to index field 'ammorateoffire' (a nil value)`

Any thoughts, it's driving me insane, should be simple.

Cheers,
MBM

Trenloe
June 29th, 2020, 19:32
I'm not sure I'm completely clear on your control hierarchy, so I'm going to make some assumtions...

Each entry within a windowlist is it's own window.

You need to get a LUA table of all the windows: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist#getWindows

Then step through each window (using for.. in ipairs .. do) and set the control in each window returned as part of the for loop.

Have a look at the toggleVisibility function in CoreRPG ct\scripts\ct.lua as an example - "v" is the window variable.

MadBeardMan
June 30th, 2020, 10:23
I'm not sure I'm completely clear on your control hierarchy, so I'm going to make some assumtions...

Each entry within a windowlist is it's own window.

You need to get a LUA table of all the windows: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist#getWindows

Then step through each window (using for.. in ipairs .. do) and set the control in each window returned as part of the for loop.

Have a look at the toggleVisibility function in CoreRPG ct\scripts\ct.lua as an example - "v" is the window variable.

Morning Chap,

That's not it, I don't want to iterate through the windowlist.

Here's some code. This gets called when a child has been added to the windowlist, in this case a new type of Ammo has been dragged/dropped.


function updateRofFields()

local sTraits = window.traits.getValue():lower() --Fetches the traits from the parent window
local showrateoffire = false;

if string.find (sTraits, "auto", 0, true) then
showrateoffire = true;
end

window.label_ammo_rof.setVisible(showrateoffire); -- This hides the label
self.ammorateoffire.setVisible(showrateoffire); -- This errors

if (showrateoffire) then
if ammorateoffire.getValue() == "" then
self.ammorateoffire.setStringValue("single");
end
end
end

To put this into context on the actions tab you have weapon actions, each weapon action may have ammo actions (so a windowlist inside a windowlist).

I just can't seem to 'hide/show' one field on the ammo actions window.

I'll continue with this tonight, cheers,
MBM

Trenloe
June 30th, 2020, 10:38
Without seeing the XML I’m just guessing here...

"self" is a variable usually pointing to a control - I’m guessing the windowlist control in this case. This isn’t a container for other controls, it’s a control itself. window is a variable pointing at an instance of a windowclass - which is a container for controls.

So if you want to access a control you’ll need the window instance that it’s in.

Not knowing the GUI hierarchy, nor knowing exactly where the LUA you post above is running, I can’t give specific recommendations. Some of the script scope variables may help: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4128914/Ruleset+-+Scripting#Script-Block-Scope

MadBeardMan
June 30th, 2020, 14:52
Changed my way completely.

I added a DB.addHandler to fire off an event call when the traits field got updated.

This then was enough for me to know if I needed to show the Rate of Fire field or not.

Still like to know if it's possible using .dot notation to access fields but that can wait, fixed the bug I had.

Cheers,
MBM

Ampersandrew
July 7th, 2020, 11:25
When I get this it's usually some stupid spelling mistake, usually I've defined ammoRateofFire and I'm trying to change ammoRateOfFire or something.

I was also really pleased when I figured out I could do window.windowlist.window to access controls on window holding the window list holding the window I just activated a control in.