View Full Version : Overriding CoreRPG functions
MadBeardMan
May 2nd, 2018, 09:36
Morning All,
Been working on the Party Sheet this morning and one thing I need to get to grips with in CoreRPG is overriding functions.
For example, CoreRPG has a function called 'buildPartyCoins'. That's perfect, but it's based on a list of coins that Traveller doesn't have, so I want to repoint it towards a single node within the character sheet.
So how do I tell my ruleset to override just that function?
I've tried adding it into my code, but the CoreRPG function always runs, and I'd rather not copy the entire 'ps_manager_loot.lua', incase CoreRPG gets any updates in this area (inventory etc).
Thanks,
MBM
drvolk
May 2nd, 2018, 10:10
You could try to do it like this:
Add a own manager for replacing global functions to your base.xml or extension.xml:
<script name="replaceFuncManager" file="scripts/manager_func_replace.lua" />
To replace a function do something like this in you replace manager script:
local oldRef;
function onInit()
-- save the old ref, maybe you need it
oldRef = PartyLootManager.buildPartyCoins;
-- replace the function reference with you own one
PartyLootManager.buildPartyCoins = buildPartyCoinsReplace;
end
function buildPartyCoinsReplace()
-- your own code
-- you could still execute the "old" function by the oldRef , if you need to (if the old function calls other global function within the same script, you have to wrap them all in you manager also)
...
...
end
MadBeardMan
May 2nd, 2018, 10:13
You could try to do it like this:
Add a own manager for replacing global functions to your base.xml or extension.xml:
<script name="replaceFuncManager" file="scripts/manager_func_replace.lua" />
To replace a function do something like this in you replace manager script:
local oldRef;
function onInit()
-- save the old ref, maybe you need it
oldRef = PartyLootManager.buildPartyCoins;
-- replace the function reference with you own one
PartyLootManager.buildPartyCoins = buildPartyCoinsReplace;
end
function buildPartyCoinsReplace()
-- your own code
-- you could still execute the "old" function by the oldRef , if you need to (if the old function calls other global function within the same script, you have to wrap them all in you manager also)
...
...
end
That sounds perfect, thanks for making the time to answer this!
Cheers,
MBM
MadBeardMan
May 2nd, 2018, 10:33
And it worked a treat!
Ace, thanks very much I can now override the splitting of coins over the party.
Cheers,
MBM
drvolk
May 2nd, 2018, 11:39
Gladly, especially if the development of your great ruleset could be helped a little bit :)
MadBeardMan
May 2nd, 2018, 11:46
Gladly, especially if the development of your great ruleset could be helped a little bit :)
This is one of the reasons I love FG so much, the community really is superb, and I love learning new stuff every day even though I'm an old hand when it comes to coding!
The ruleset is pretty much there, this is something one of the testers found. I can't wait to get into all the new Starship stuff once the SFRPG has it all finished!
Moon Wizard
May 3rd, 2018, 05:08
Why not just update the game system coins that the function is expecting? You need to do that for the other currency functions anyway (parcel, party sheet, etc).
JPG
MadBeardMan
May 3rd, 2018, 09:13
Why not just update the game system coins that the function is expecting? You need to do that for the other currency functions anyway (parcel, party sheet, etc).
JPG
Traveller has the universal 'Credit' but Cash on Hand is the one that's affected by normal transactions. It's not in a list of currencies as such, still it's all done and I learned how to override things which is important I think.
Cheers
Tielc
June 1st, 2018, 16:33
From what I understand I can do this when loading my scripts with extension.xml. Can I do the replace function on a per-control basis as well? Can I just change my lua on say onHealthChanged for a single box or other instances like that?
celestian
June 1st, 2018, 16:44
Are you just trying to add a new coin type? like CRD where normally it uses GP?
Trenloe
June 1st, 2018, 17:01
From what I understand I can do this when loading my scripts with extension.xml. Can I do the replace function on a per-control basis as well? Can I just change my lua on say onHealthChanged for a single box or other instances like that?
Overriding functions is only possible with Global script packages (https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Global_Script_Packages) because they are ran during initialization of the ruleset code. You can't override individual functions in a control script. You need to overwrite the whole control script LUA file or <script> element.
Tielc
June 1st, 2018, 19:04
Overriding functions is only possible with Global script packages (https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Global_Script_Packages) because they are ran during initialization of the ruleset code. You can't override individual functions in a control script. You need to overwrite the whole control script LUA file or <script> element.
Okay, thanks for the heads up!
celestian
June 1st, 2018, 19:53
If you want to add the new coin type something like this should work.
table.insert(GameSystem.currencies,"CR");
I was mucking about with this for a friend running Darksun. I'll attach the extension. I didn't test it other than look that the coin type worked.
GEONE
June 1st, 2022, 06:54
You could try to do it like this:
Add a own manager for replacing global functions to your base.xml or extension.xml:
<script name="replaceFuncManager" file="scripts/manager_func_replace.lua" />
...
function onInit()
-- replace the function reference with you own one
PartyLootManager.buildPartyCoins = buildPartyCoinsReplace;
end
How would this work for scripts that don't have a "script name" like charwizard.lua?
charwizard.lua is only 'included' in the base.xml for the 5E ruleset and doesn't have a '<script name="...' so I cannot override the function by doing ScriptName.function = newfunction
Specifically, I'm trying to override calcSummaryStats() in charwizard.lua.
damned
June 1st, 2022, 13:53
The character wizard is very complex and is always being updated.
SW recommend that you dont overwrite anything in that area.
ronnke
June 10th, 2022, 14:04
Is there a way to override a single global variable/constant in a CoreRPG script file?
Eg.
In the scripts/manager_language.lua, I want to change the following global constant:
CHAR_LANGUAGE_LIST = "languagelist";
to
CHAR_LANGUAGE_LIST = "traits.languagelist";
Presently I do this by copying the manager_language.lua file from CoreRPG into my ruleset, I make the above change, and then overwrite the <script name="LanguageManager" file="scripts/manager_language.lua" /> in my base.xml file.
Is there a better way to do this with respect to layering?
GEONE
June 10th, 2022, 14:17
Is there a way to override a single global variable/constant in a CoreRPG script file?
Eg.
In the scripts/manager_language.lua, I want to change the following global constant:
CHAR_LANGUAGE_LIST = "languagelist";
to
CHAR_LANGUAGE_LIST = "traits.languagelist";
Presently I do this by copying the manager_language.lua file from CoreRPG into my ruleset, I make the above change, and then overwrite the <script name="LanguageManager" file="scripts/manager_language.lua" /> in my base.xml file.
Is there a better way to do this with respect to layering?
I think you can just put LanguageManager.CHAR_LANGUAGE_LIST = "traits.languagelist"; inside an onInit() anywhere. Or more preferably create a new LanguageManager script file (something like NewLanguageManager) with only an onInit() that does the same thing and also stores the old CHAR_LANGUAGE_LIST in its own variable called something like OLD_CHAR_LANGUAGE_LIST.
Then make sure to include it in the base xml <script name="NewLanguageManager" file="scripts/new_manager_language.lua" />
ronnke
June 10th, 2022, 16:01
I think you can just put LanguageManager.CHAR_LANGUAGE_LIST = "traits.languagelist";
Worked like a charm. :)
Thanks!
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.