PDA

View Full Version : Overriding WindowClass instance attributes from LUA



xelab
September 1st, 2022, 23:45
Hi,

is it possible to change some attributes (e.g. title) of the Window instance from within LUA? Since the change should be dynamic, I do not want to create separate new window templates.

Here is an example of what I am trying to do:


<windowclass name="some_window_class" merge="join">
<script>
function onInit()
Debug.chat(" onInit() called");


------ I would like to change the title of this window instance (depending on some logic)


end
</script>
</windowclass>

Thank you in advance

Moon Wizard
September 2nd, 2022, 00:00
Well, first, you need to call any base window onInit call. Then, it depends on the window class and templates/names being used for that ruleset.

For most windows in the 5E ruleset (but not all), it could be as simple as:


function onInit()
if super and super.onInit then
super.onInit();
end
title.setValue("My Custom Window Title");
end


Regards,
JPG

xelab
September 2nd, 2022, 01:28
Amazing, this works perfectly.

However now I am stuck trying to access subwindow elements of the current window.

EDIT: Figured it out myself: elements of subwindow can be accessed via in the case below "subwin.subwindow.element_name"



<windowclass name="main_window_class">
<sheetdata>
<subwindow_record name="subwin">
<class>subwindow_class</class>
<activate />
<fastinit />
</subwindow_record>
</sheetdata>
</windowclass>

<windowclass name="subwindow_class">
<sheetdata>
<header_column name="element_name">
<static textres="text_to_be_changed" />
<center />
</header_column>
</sheetdata>
</windowclass>

jharp
September 2nd, 2022, 03:22
This may help with a lot of your recent questions...

https://forge.fantasygrounds.com/shop/items/358/view

Jason