PDA

View Full Version : Functions from image.lua disappearing



GKEnialb
May 13th, 2021, 02:39
I override a few functions in image.lua in my token height extension (https://www.fantasygrounds.com/forums/showthread.php?66566-5E-Token-Height-Indicator). Everything typically works just fine, but a couple of users have found that the functions that I don't override "disappear" at some point into their session (even when not changing maps). By "disappear", I mean a call in my extension to getGridSide() starts becoming a nil value and a call to onDrop() outside of my extension becomes a nil value.

Not sure if this is relevant, but a few builds ago I changed the overriding in extension.xml from


<windowclass name="imagewindow" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>


to



<template name="image_record_step">
<imagecontrol name="image" merge="join">
<script file="campaign/scripts/image.lua" />
</imagecontrol>
</template>


I didn't have any such error reports before that switch or for a couple builds after it, but can't think of what else it would be. The change was made because making the map full screen/"sending to background" would revert to the original image.lua for some reason.

Moon Wizard
May 13th, 2021, 04:32
Not sure what is going on; but a couple thoughts.

* Templates do not support merging; so if you re-specify a template, you are overriding completely.
* "image.lua" in CoreRPG is only referenced by template; so overriding that template would prevent the base script from being loaded.

Regards,
JPG

GKEnialb
May 14th, 2021, 03:50
Thanks. I can switch back to the original. Any idea why making the map full screen or sending to back would cause image.lua to no longer being overridden?

bmos
May 14th, 2021, 11:55
Thanks. I can switch back to the original. Any idea why making the map full screen or sending to back would cause image.lua to no longer being overridden?

because each of those have different windowclass names: imagebackpanel and imagefullpanel need to get your changes as well. before I changed from imagewindow to the template override, I had started to do that but the template approach seemed smarter. this is a really important lesson to have learned though and explains some other things I have seen.

GKEnialb
May 14th, 2021, 16:43
Thanks. I'll add those two in.

Actually, one question on that before I confuse things more. :)

Would I replace imagewindow with imagebackpanel or image with imagebackpanel?

So


<windowclass name="imagewindow" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>
<windowclass name="imagebackpanel" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>
<windowclass name="imagefullpanel" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>


or



<windowclass name="imagewindow" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
<image_record name="imagebackpanel">
<script file="campaign/scripts/image.lua" />
</image_record>
<image_record name="imagefullpanel">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>


or something completely different? I can definitely see why the template idea was desirable.

bmos
May 15th, 2021, 03:30
The first one should work.
Too bad templates don't allow merges; at first glance it was a much cleaner approach.
If you want to keep extension.xml from looking too busy, you could move those windowclass changes into an xml file.

GKEnialb
May 15th, 2021, 17:29
Hmmm. That didn't work. When loading the 5E ruleset, an error is thrown on line 14 on image.lua: "attempt to call field 'onCursorModeChanged' (a nil value)" -- must be in that ruleset as there is no 'onCursorModeChanged' call made in my image.lua.

On another bizarre thing, apparently when the functions disappeared in the previous version, it wasn't just the image functions - "Debug" disappeared as well.

bmos
May 15th, 2021, 18:00
Hmmm. That didn't work. When loading the 5E ruleset, an error is thrown on line 14 on image.lua: "attempt to call field 'onCursorModeChanged' (a nil value)" -- must be in that ruleset as there is no 'onCursorModeChanged' call made in my image.lua.

On another bizarre thing, apparently when the functions disappeared in the previous version, it wasn't just the image functions - "Debug" disappeared as well.perhaps this?

<windowclass name="imagewindow" merge="join">
<script file="campaign/scripts/image.lua" />
</windowclass>
<windowclass name="imagebackpanel" merge="join">
<script file="campaign/scripts/image.lua" />
</windowclass>
<windowclass name="imagefullpanel" merge="join">
<script file="campaign/scripts/image.lua" />
</windowclass>


I've seen global packages go missing before too, not sure why that happens. For me it's usually DB that is missing.

EDIT: looks like I'm wrong. Basically the format should be whatever you had before I suggested the template approach (but you should duplicate it for the other windowclasses as well).

Moon Wizard
May 15th, 2021, 18:12
You have to use the sheetdata tag when merging controls on a windowclass.

Regards,
JPG

GKEnialb
May 16th, 2021, 02:02
You have to use the sheetdata tag when merging controls on a windowclass.

Regards,
JPG

Thanks. Should this have worked, then?



<windowclass name="imagewindow" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>
<windowclass name="imagebackpanel" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>
<windowclass name="imagefullpanel" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>


That's what threw the exception...

Moon Wizard
May 16th, 2021, 02:06
You don't have the right window classes. The panel windows you mention are just containers, since they can be swapped in/out.



<windowclass name="imagewindow" merge="join">
<sheetdata>
<image_record name="image">
<script file="campaign/scripts/image.lua" />
</image_record>
</sheetdata>
</windowclass>
<windowclass name="imagepanelwindow" merge="join">
<sheetdata>
<imagepanel_record name="image">
<script file="campaign/scripts/image.lua" />
</imagepanel_record>
</sheetdata>
</windowclass>


Any time that you are merging the window classes, you need to make sure that the control you are trying to merge over actually exists in that definition.

Regards,
JPG

GKEnialb
May 16th, 2021, 02:15
Awesome. Thanks for the help!

GKEnialb
May 24th, 2021, 01:22
Unfortunately, none of that is preventing functions from outside the extension from not being able to be accessed within (or even in one case, outside) of the extension. The latest was CombatManager (called from the extension but not modified by it) after someone drug a token with shift-drag. Previously, Interface has disappeared, along with the functions DB.getValue(), onDrop(), and getGridSize(). I haven't been able to reproduce it myself, but several others have run into these problems at some point into their session (haven't heard that it happens right off the bat - works for a while and then something happens to cause these things).