PDA

View Full Version : SubWindow - issue to find the class inside it.



MadBeardMan
January 1st, 2018, 14:52
SOLVED!

Afternoon,

I'm working on the WOiN Ruleset 1.0.6. update at the moment.

One issues that I can't fine the windowclass inside the subwindow.

I have a Action Tab, It's got 2 SubWindows named as 'Powers' and 'Attributes'


<subwindow name="powers">
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="2" />
<left />
<right />
</anchored>
<class>char_power</class>
<activate />
<fastinit />
<invisible />
</subwindow>

The class is


<root>
<windowclass name="char_power">
<margins control="0,0,0,5" />
<script file="campaign/scripts/char_powerlist.lua" />
<sheetdata>
....
</sheetdata>
</windowclass>
</root>

All works fine, but how to run the 'update' that's in the "char_powerlist.lua"

If I use:

window.contents.subwindow.powers.setVisible(false)

It hides the subwindow, but what I want to do is to run this:

window.contents.subwindow.powers.char_power.update ()

But I get a issue:

Runtime Notice: Reloading ruleset
Script Error: [string "actions_iedit"]:1: attempt to index field 'char_power' (a nil value)

So can anyone tell me how to find the windowclass inside the subwindows.

Cheers
Col

Bidmaron
January 1st, 2018, 18:14
have you tried:

window.contents.subwindow.parentcontrol.char_power .update()
?

Trenloe
January 2nd, 2018, 00:04
char_power is the name of the windowclass used to create the subwindow (all windows need a windowclass). It is not the name of anything within the subwindow. Refer to the subwindow with the name used to create it - which is "powers".

Does window.contents.subwindow.powers.update() work?

MadBeardMan
January 4th, 2018, 01:21
char_power is the name of the windowclass used to create the subwindow (all windows need a windowclass). It is not the name of anything within the subwindow. Refer to the subwindow with the name used to create it - which is "powers".

Does window.contents.subwindow.powers.update() work?

Nope, same error.

Most odd.


<button_iedit name="actions_iedit">
<anchored position="insidebottomright" offset="10,10" />
<tooltip textres="char_tooltip_actionedit" />
<script>
function onValueChanged()
local bEditMode = (getValue() == 1);

window.weapons_iadd.setVisible(bEditMode);
window.powers_iadd.setVisible(bEditMode);

window.contents.subwindow.weapons.update();
window.contents.subwindow.powers.update();
end
</script>
</button_iedit>
......
......
<subwindow name="contents">
<anchored>
<bottom offset="-40" />
<top offset="10" />
<left offset="0" />
<right offset="-45" />
</anchored>
<class>charsheet_actions_contents</class>
<activate />
<fastinit />
</subwindow>



Within 'charsheet_actions_contents'


<subwindow name="powers">
<anchored>
<top parent="columnanchor" anchor="bottom" relation="relative" offset="2" />
<left />
<right />
</anchored>
<class>char_power</class>
<activate />
<fastinit />
<invisible />
</subwindow>

Within 'char_power'


<windowclass name="char_power">
<margins control="0,0,0,5" />
<script file="campaign/scripts/char_powerlist.lua" />
<sheetdata>

Finally within 'char_powerlist.lua'


function update()
print ("update is here");
if window.parentcontrol.window.actions_iedit then
local bEditMode = (window.parentcontrol.window.actions_iedit.getValu e() == 1);
for _,w in pairs(getWindows()) do
w.idelete.setVisibility(bEditMode);
end
end
end

So I find it most odd that window.contents.subwindow.powers.update() doesn't work.

It's almost as if it can't see it.

If I move the script into the 'subwindow' code (ie when it creates the subwindow) it does find it, but brings up another issue...

Cheers

Bidmaron
January 4th, 2018, 04:06
Did you try parentcontrol under sub window like I suggested? (not trying to pass myself off as an expert, but as I understand the pre-defined syntax, that aught to work.

MadBeardMan
January 4th, 2018, 10:40
Did you try parentcontrol under sub window like I suggested? (not trying to pass myself off as an expert, but as I understand the pre-defined syntax, that aught to work.

Apologies, yes I tried that as well. Same that throws up an error telling you that char_power isn't found.

damned
January 4th, 2018, 12:38
Apologies, yes I tried that as well. Same that throws up an error telling you that char_power isn't found.

Did you try parentcontrol with powers instead of char_power?

MadBeardMan
January 4th, 2018, 12:47
window.contents.subwindow.powers.parentcontrol.upd ate();

Script Error: [string "actions_iedit"]:1: attempt to index field 'parentcontrol' (a nil value)


window.contents.subwindow.parentcontrol.powers.upd ate();

Script Error: [string "actions_iedit"]:1: attempt to index field 'powers' (a nil value)

It just doesn't like me.

Trenloe
January 4th, 2018, 18:03
So, it looks like you have two subwindows? powers which is within contents?

I think the best way for you to work out the exact hierarchy is use Debug.console commands using <control hierarchy name>.getName() for controls: https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#getName and <window name>.getClass() for window instances: https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getClass

Try starting at window.getClass() and see where that starts. Then you can string together the hierarchy and subwindow commands to try to work out the exact hierarchy. Subwindow info here: https://www.fantasygrounds.com/refdoc/subwindow.xcp


A reference to the contained windowinstance object is available from the script environment of the parent subwindow control through the variable subwindow. In the other direction, a reference to the parent subwindow control is available from the contained windowinstance object through the parentcontrol variable.

MadBeardMan
January 4th, 2018, 21:36
At the top:

Windowclass "charsheet_actions"
--> Subwindow "contents"
----> Windowclass "charsheet_actions_contents"
------> Windowlist "Weapons"
------> Subwindow "Powers"
--------> Windowclass "Char_power"*
----------> Windowlist "powerslist"**
------> Subwindow "Attributes"

* Char_power - is where I link the script that has the 'update' function (campaign/scripts/char_powerlist.lua)
** Powerslist is the list that shows their spells/powers - it has Idelete buttons against each item, and it's these I'm trying to show/hide.

This is why I thought that I could use but thanks to making me work out the hierarchy I've solved it :)

The 'script' needed to be added to the 'Windowlist "Powerlist" and the correct code to call it:

window.contents.subwindow.powers.subwindow.powersl ist.update();

So cheers for all the help here, it's helped and now I just need to sort the update function then I'm done with this major part of the WOiN ruleset update!

Cheers
MBM

damned
January 4th, 2018, 22:27
because of these sorts of issues - its always been recommended to me that I update the DB wherever possible rather than the window control... :)

MadBeardMan
January 4th, 2018, 22:29
because of these sorts of issues - its always been recommended to me that I update the DB wherever possible rather than the window control... :)

Ha, well erm, this has taught me, draw the parent tree out (oddly like I do at work in my head) but on paper and then it dawns on you....

It's all working now, super stuff.