PDA

View Full Version : How do you override a script that is in CoreRPG



lokiare
June 15th, 2014, 07:44
I'm getting an error in my custom ruleset, but it points to a script that is not in my ruleset, but in the CoreRPG ruleset. How do I go about overriding the original script or making FG read my script instead of the default one in CoreRPG?

So far I've tried creating a file in the same location with the same name and making changes, but the function in question doesn't get called. I know this because I echo a string to the console and it doesn't echo and the error is still there even though I fixed it.

lokiare
June 15th, 2014, 08:57
As a temporary fix, I'm editing the .xml files to read my custom script instead of the CoreRPG script, but this requires me to copy the entire script and if CoreRPG gets updated I'll still be using an old version of the script.

Trenloe
June 15th, 2014, 18:35
As a temporary fix, I'm editing the .xml files to read my custom script instead of the CoreRPG script, but this requires me to copy the entire script and if CoreRPG gets updated I'll still be using an old version of the script.
Yep, that's how you do it and, yep, that's what happens when a new release is brought out - you need to compare the current scripts with the old scripts you based yours on and merge the differences into the new scripts to make your extension/ruleset compatible with the new release.

You may be able to work with Moon_Wizard to add in hooks to the base CoreRPG scripts, based on a comment he made in this post: https://www.fantasygrounds.com/forums/showthread.php?21272-Release-v3-0-4&p=178343&viewfull=1#post178343 I'm assuming that comment wasn't just aimed at me... :)

Moon Wizard
June 15th, 2014, 22:34
Yeah, you want to avoid overriding CoreRPG scripts if you can, since these will be evolving over time as more rulesets are migrated. Especially global scripts like ActionsManager, ActorManager, etc. This means that you will need to factor changes into your ruleset with each release, or you may get errors or not pick up fixes or new features.

If you let me see your changes and give me an example of use, I may be able to suggest a solution that doesn't involve overriding CoreRPG scripts or add a way to hook into those scripts.

I just had to help out on the Dark Heresy ruleset a bit for the same reason.

Regards,
JPG

lokiare
June 16th, 2014, 13:59
Well as you remember I swapped out the 4E healing surge number for a dice box that returns a table with a string of dice in it. In one of the scripts that is used in the combat tracker it kept throwing an error, but the file it referenced as having the error was in CoreRPG and not the ruleset I was modifying.

The file was number_crosslink.lua and the line number I had to modify was line 64. For some reason the combat tracker loads up healing surge value when it doesn't use it at all (it uses number of healing surges left).

Anyway I basically overroad the xml to point to my script instead of the CoreRPG script, which was an exact copy of number_crosslink.lua which a slight change to line 64 to check to see if its a table and if it is just send 0 in instead. Without knowing the inner workings of the 4E rule set I can't really tell if there would be a way to fix that. A fix for this would be just to verify the variable type and pass 0 if its not a valid variable type. Here is the original function:


function onLinkUpdated()
if sLink and not bLocked then
bLocked = true;

setValue(DB.getValue(sLink, 0));

if self.update then
self.update();
end

bLocked = false;
end
end

and here is what I did to it:


function onLinkUpdated()
if sLink and not bLocked then
bLocked = true;

if (type(DB.getValue(sLink, 0)) == "table") then
setValue(0);
else
setValue(DB.getValue(sLink, 0));
end

if self.update then
self.update();
end

bLocked = false;
end
end


A simple checking to see if its a valid variable type and then passing 0 in if it isn't would probably fix the problem for me.



Also I was looking around and I read up on some lua. Apparently you can assign a new method to an old methods name so something like:


function Method ()
--old stuff
end

oldMethod = Method

function Method2()
oldMethod();
--new stuff;
end;

Method = Method2()

And apparently that lets you wrap existing functions. Would something like that work? I have another script that I need to add to the end of an existing function and it was also in CoreRPG so I had to do the redefining XML stuff I did above to get it to work (I was adding an escalation die to the combat tracker that needs to be incremented every time the nextRound function was called). What I want to know is would that work or does FG not work that way?

Moon Wizard
June 16th, 2014, 18:45
My initial thought is that you should make a new script for the dice field (say dice_crosslink.lua), instead of replacing the CoreRPG version built for number fields.

My second thought, is whether you even need a linked dice field in the CT though. I would leave the viewing/editing of that field to only when the PC or NPC records are open. When a healing surge is triggered, just look up the dice field in the CT record directly for NPCs or call useHealingSurge for PCs.

Regards,
JPG

lokiare
June 17th, 2014, 01:50
My initial thought is that you should make a new script for the dice field (say dice_crosslink.lua), instead of replacing the CoreRPG version built for number fields.

My second thought, is whether you even need a linked dice field in the CT though. I would leave the viewing/editing of that field to only when the PC or NPC records are open. When a healing surge is triggered, just look up the dice field in the CT record directly for NPCs or call useHealingSurge for PCs.

Regards,
JPG

That's the weird thing. It gets passed in somewhere to the number_crosslink.lua, but as far as I know the healing surge value is never used in the combat tracker (number of healing surges is though). Which is why I just pass 0 and it has no affect on anything. If I knew where it was passed in, I could just skip it or something since it doesn't appear to be used. Then I wouldn't have to override the number_crosslink.lua file at all.

Moon Wizard
June 17th, 2014, 02:47
I'd have to see the code to be sure what is happening. Can you post a link to the current version of your ruleset, or send a link to [email protected]?

Thanks,
JPG

lokiare
June 17th, 2014, 04:09
I'm kind of wondering why 99% of the functions in CoreRPG don't have some sort of callback built in that can be overridden in a derived ruleset. That would be a very useful feature for ruleset and extension programmers to have.

lokiare
June 17th, 2014, 04:32
Actually I just found the line that calls it in ct_entry.lua while I was looking for the ongoing damage stuff (I have to allow stacking). Its line 176, and after I commented it out and returned everything to normal, it works without a problem. This is where documentation would be very very useful.