PDA

View Full Version : How to replace a built in script or modify it



rmilmine
May 9th, 2020, 22:58
How would I go about replacing a script without completely replacing the xml/lua files.
I want to make the damage section of the item window show up for shields, and I don't want to replace the entire xml file to do so.
I use other extensions that add fields to items so I don't want to break them.
I'm new to this so still figuring out how to do things.

Thanks.

damned
May 10th, 2020, 04:47
you start talking about xml/lua and then reference only xml but your topic is about a script (lua)

use merge="join" or merge="replace" in xml

rmilmine
May 10th, 2020, 07:31
so if I use merge join in the xml doing
<script file="my name.lua"/> can I name functions by the same name replacing them, or how do I go about ensuring my script gets called after the original one is?
So that I can make something normaly not visible is visible?

damned
May 10th, 2020, 11:09
You can merge against any xml element that is named. If its not named (it probably should be) then you cant merge against it.
Rulesets load before extensions.
Extensions load somewhat randomly unless you set a load order.

rmilmine
May 10th, 2020, 13:43
So I could instead of putting merge="join" in the windowclass I could put <script merge="replace" file="myfile.lua" /> to replace just that part of the windowclass?

Thanks.
I'll try that out.

rmilmine
May 10th, 2020, 14:26
bah, misread that, since the <script> isn't named it can't be replaced? or is this only for template and windowclass elements?

damned
May 10th, 2020, 14:37
Example:


<template name="chatwindow_step" merge="join">
<chatwindow name="chat" merge="join">
<modeframe mode="damned" name="chatframe_spell" offset="20,11,20,9" mergerule="replace" />
<modeframe mode="chat" name="chatframe_chat" offset="15,5,5,5" mergerule="replace" />
<modeframe mode="story" name="chatframe_story" offset="15,10,15,10" mergerule="replace" />
<modeframe mode="whisper" name="chatframe_whisper" offset="15,5,5,5" mergerule="replace" />
<linkcolor>0000FF</linkcolor>
<linkicon normal="button_link" pressed="button_link_down" />
<droptypes>
<type>dice</type>
<type>number</type>
<type>string</type>
</droptypes>
<script file="desktop/scripts/chat_window.lua" />
</chatwindow>
</template>

the template and chatwindow are named so Im merging at that point.

rmilmine
May 10th, 2020, 20:30
Thanks for your help.
So I did the following:

<windowclass name="item_main" merge="join">
<script file="campaign/scripts/item_main_ACIM.lua" />
<sheetdata>
<line_column name="divider10" insertbefore="ac_label" />
</sheetdata>
</windowclass>
I get an error saying the script can't be loaded. Now there is a file in that location with that file name, so I've no idea why I'm getting the error.
If I change iremove the "_ACIM" the error goes away. Again no idea why.

As for the script I did the following:
I copied the script from item_main.lua and changed it.

function onInit()
update();
end

function VisDataCleared()
update();
end

function InvisDataAdded()
update();
end

function update()
Debug.console("Been here");
end
It doesn't do anything. I don't get a message in the console.
Again no idea why it's doing this.

damned
May 10th, 2020, 23:55
The error goes aay when you remove the _ACIM because it is then loading the CoreRPG version of the script.
There must be something wrong with the file naming, path or file content maybe?

Sterno
May 14th, 2020, 21:59
Trying to do this same sort of thing. I can get my new script called, but is there any way for my new script to reference the old one and tell it to do it's update(), or some other way to have that old update() method run? I just have like 3 lines of code that I need to run in the update() method, and I don't want to replace the entire item_main.lua file with a copy and pasted one that has my 3 lines of code added, since then I'd have to make constant extension updates if the ruleset ever updates that file.

Trenloe
May 14th, 2020, 22:43
Trying to do this same sort of thing. I can get my new script called, but is there any way for my new script to reference the old one and tell it to do it's update(), or some other way to have that old update() method run? I just have like 3 lines of code that I need to run in the update() method, and I don't want to replace the entire item_main.lua file with a copy and pasted one that has my 3 lines of code added, since then I'd have to make constant extension updates if the ruleset ever updates that file.
If your script is in a merged XML file and defined via the <script> tag, then in your new update function have:

if super and super.update then
super.update();
end