PDA

View Full Version : Replacing scripts on desktop button



ApesAmongUs
September 7th, 2020, 02:58
<edit - my fix was wrong - do not ignore>
OK, I know this is a common question since I've read several threads on the subject, but I can't get it to work.

I am attempting to replace 2 functions in a file named modifierstack_damageraise.lua (SavageWorlds ruleset). This file is only referred to in the template_desktop.xml file -

<template name="desktop_damageraise_toggle">
<genericcontrol>
<anchored width="40" height="40" />
<icon>damageraise_off</icon>
<script file="desktop/scripts/modifierstack_damageraise.lua" />
</genericcontrol>
</template>

As I understand it, I can't just replace one element in a script, but would need to make a copy of that file and make my changes and then load it. But since the "script" tag doesn't have a name, I'm not sure I'm overwriting it correctly. In fact, I know I'm not, since nothing happens. I tried this -

<template name="desktop_damageraise_toggle" merge="replace">
<genericcontrol merge="replace">
<anchored width="40" height="40" />
<icon>damageraise_off</icon>
<script file="/desktop/scripts/modifierstack_damageraise_replace.lua" />
</genericcontrol>
</template>

But nothing happens - I haven't even written a working script yet, I just made an obvious change that (switching out one screen icon for another after the button is pressed), but it does nothing. After searching I started to wonder if the fact that it was a template mattered and maybe I needed to also override the creation of the element using the new template, so I tried this -

<windowclass name="modifierstack" merge="replace">
<sheetdata>
<desktop_damageraise_toggle name="damageraise" merge="replace">
<anchored>
<top offset="45" />
<right offset="-45" />
</anchored>
</desktop_damageraise_toggle>
</sheetdata>
</windowclass>

There are no changes in that beyond the merge="replace", since I'm just try9ing to get it to create it exactly the same, only with the new button functioning. But still nothing - or at least, I'm getting the message that it loaded. The ext is loading and I'm still getting nothing. Is there any additional step needed to replace the functioning of a button on the desktop?

superteddy57
September 7th, 2020, 05:39
To force the system to use your custom code of that script, you would also need to make a clone of the element that calls that script as well. Only global scripts are given names.

ApesAmongUs
September 7th, 2020, 09:06
I'm not sure I understand the answer. The script in question is part of a handler and the onInit of that lua file registers the handler -

function onInit()
ModifierStack.registerDamageRaiseObserver(damageRa ise)
setHoverCursor("hand")
end

That is the only place the function is ever referenced. But maybe I'm not understanding what you mean.

superteddy57
September 7th, 2020, 10:12
For the function you have linked is in a lua file that is called using this template:

<template name="desktop_damageraise_toggle">
<genericcontrol name="damageraise">
<icon>damageraise_off</icon>
<script file="desktop/scripts/modifierstack_damageraise.lua" />
</genericcontrol>
</template>

So, if you make changes to the lua file and want it to be called in your extension, I would clone this template and place it in my extension. This will then call my new lua file with the changes since the extension has now replaced the template. If it's not placed in your extension, it will continue to call the base lua file instead of the changed one. I see you used the merge="replace", I would skip that for now and just copy the template into your extension for it to be over written and use your new lua file.

ApesAmongUs
September 7th, 2020, 13:21
But that's already what I did. The only thing I didn't do is add a name to the generic control. That second block of code I originally posted is sitting in my extension.xml file. I see 3 differences in what I have and what you have, so I will try making those changes, but can you explain why each of those is needed.

1. the original does not have a name attribute associated with the generic control, so why is one needed to replace it?
2. all the other examples I have seen (and gotten working for other extensions) have required the merge. For instance, I changed -

<template name="npc_traitdiebase">
<traitdiebase merge="replace">

and that required a merge="replace" and worked fine, so why doesn't this one?
3. when I copied the modifierstack_damageraise.lua file to make changes, I changed the name to modifierstack_damageraise_replace.lua. I then proceeded to change the script assignment t0 <script file="desktop/scripts/modifierstack_damageraise_replace.lua" />. Since it should be completely replacing the scripting in this element with the new file, I don't see why the name change would cause a problem. Does that matter?

ApesAmongUs
September 7th, 2020, 15:44
I made those changes in my extension.ext file and it didn't make a difference. And just to be certain, I added an edit of a global function in the same extension (using a different method of merging) and that change is working fine. So, it's definitely not that the extension isn't working at all, just that the override of the controls for that template>button isn't happening.

While I've made several changes, this is the first one that really changes the UI much, so it is very, very likely that I'm missing some basic element of that. Is there a really basic document/video anywhere that shows overriding desktop button controls? Better yet, does anyone have an example of an ext that modifies a desktop button that I could look at to emulate?

Moon Wizard
September 8th, 2020, 23:48
Can you post a copy of your extension so far that is not working?

JPG

ApesAmongUs
September 9th, 2020, 00:05
Sure. This includes a copy of template_desktop.xml that is not being used. I was thinking that maybe the changes needed to be in a separate file instead of included directly in extension.xml. That file is not currently being included in extension.xml, because when I did include it, nothing happened. The change that is failing is simple, it should just be changing the icon when the "+damage" button on the desktop is presses. It's trying to change it to obviously the wrong icon (shaken), but that was just me trying to test if it is doing anything at all.

This should match what superteddy57 suggested.

I'm sure I'm missing something really basic.

Moon Wizard
September 10th, 2020, 00:48
It's because all of your overrides are defined under the "root" tag; but all extension modifications must be under "root.base" path.

Once you fix that, you'll also get an error about merge="replace" being invalid for windowclasses. If you want to replace, don't use a merge tag; otherwise, use merge="join" to combine with already defined version.

Regards,
JPG

ApesAmongUs
September 10th, 2020, 02:49
Well, at least I was correct in saying that it was something basic. Thank you.

Out of curiosity, why does it need that? If it's not inside <base> tags in the ruleset file, why does it need to be in the extension file? Is that kind of like doing a "parent."?

Moon Wizard
September 10th, 2020, 04:27
It was that way before my time; so it's backward compatibility issue at this point.

Regards,
JPG