PDA

View Full Version : ct_entry.lua



Stv
June 4th, 2020, 18:41
I'm not seeing a reference to his file in the base.xml file.
I need to add to one of the functions in the ct_entry.lua file, what's the best/preferred way of doing this?

Cheers, Steve.

Trenloe
June 4th, 2020, 18:53
If it's not referenced in the base.xml file then it isn't a global script. It will be a script that is assigned to a <script> entry within a control or windowclass XML. Do a find in files for that filename to see where.

Exactly what is the best way to do things depends on exactly what you're changing. You'll essentially need to have a "stub" of the windowclass (or control) that the script is assigned to (it may be multiple window classes or controls) to be able to add in a custom .lua file.

Here is an example where I'm adding to a script file in CoreRPG in the PFRGP2 ruleset:


<!--Included so that the custom ref_groupedlist_groupitem.lua is used-->
<windowclass name="reference_groupedlist_groupitem" merge="join">
<script file="ref/scripts/ref_groupedlist_groupitem.lua" />
</windowclass>

As this is merging the windowclass, what it does is setup a script hierarchy - the original script functions are available through the script super variable. Some original code you're not changing needs to be called within your new .lua file.

Here's an example of the override script from above. The original file in CoreRPG had 3 functions, but I'm only changing one. So I call the relevant super function from within the same function name (and arguments) within my new custom file:


function setItemRecordType(sRecordType)
if super and super.setItemRecordType then
super.setItemRecordType(sRecordType);
end
end

function setItemClass(sDisplayClass)
if super and super.setItemClass then
super.setItemClass(sDisplayClass);
end
end

function setColumnInfo(aColumns, nDefaultColumnWidth)
... all of the custom code here, so no super call...
end

As I'm changing the code in setColumnInfo I don't call the original function using super and have all of my custom code there.

So, in this script I'm overriding one function and keeping the original ones by calling them. The issue you may have in the long run is if the original script at some point adds extra functions or calls functions within it's own super scope.

Note: it's possible to have more than two levels if an extension modifies a windowclass/control script that is already layered on top of CoreRPG - you now have 3 layers! And each layer can access the previous one via super.

Stv
June 4th, 2020, 19:02
OK, that looks like it could be a lot of work.
I'll take a little time and get my head around that.
All this 'cos I wanted to add some checkboxes to the combat tracker :P

Thanks for the info Trenloe.

Cheers, Steve.

Stv
June 4th, 2020, 19:19
And just to make sure I have this right....
In 5e, ct_entry.lua is referenced in 2 files : ct_host.xml and ct_client.xml.
I would need to add in the reference to my new lua file with a merge="join" in 2 replacement files (one for ct_host, and one for ct_client)
Then use 'super' calls in my new ct_entry.lua file for functions I'm not changing, and re-write the functions I need to edit.

Hope that's the gist of it, and thanks again for your help.

Cheers, Steve.

Trenloe
June 4th, 2020, 19:34
In 5e, ct_entry.lua is referenced in 2 files : ct_host.xml and ct_client.xml.
I would need to add in the reference to my new lua file with a merge="join" in 2 replacement files (one for ct_host, and one for ct_client)
Then use 'super' calls in my new ct_entry.lua file for functions I'm not changing, and re-write the functions I need to edit.
Yep, that's it.

If you're really clever, you could even call the super function of the function you're changing - and just include the code you need to change in your custom function - either before or after the super call. Sometimes it's not possible, but sometimes it is...

Stv
June 4th, 2020, 19:38
Oh thanks,
Just as I thought I had it straight in my head you come up with something else :P

Seriously though, thank you again. I'll buy you a pint next time I'm in Newcastle ^^

Cheers, Steve.

Stv
June 5th, 2020, 10:24
Hi again Trenloe :P
I am once again in need of some assistance.
I've setup my extension to point to my new instance of ct_host.xml, which it does fine.
In my new version, if I just copy the entirety of the xml file into my new one everything works fine (as I'd expect it to).
But when I add the 'merge ="join"' to the windowclass definition strange things occur, like the small reaction button on the character sheet stops working.

Any idea why ?

Cheers, Steve.

Trenloe
June 5th, 2020, 10:43
It could be a bubnch of things.

Please post your ct_host.xml and the ct_entry.lua file that you've created/modified.

Stv
June 5th, 2020, 11:00
I've attached all the files for brevity Trenloe, hope that's ok.
If you run this ext you'll see that the react button doesn't work.
But it will if you remove the merge="join" tag in the XML file.

Thanks for looking.

Cheers, Steve.

Trenloe
June 5th, 2020, 11:27
Thanks for the extension, that helped a lot.

Like I mentioned in post #2 - if all you're doing is custom code in the attached <script> file, then you just need a "stub" windowclass to call the custom script file. My example code in post #2 is all you need.

In your example, new_ct_host.xml should just be:


<root>
<windowclass name="ct_entry" merge="join">
<script file="ct/scripts/new_ct_entry.lua" />
</windowclass>
</root>

Stv
June 5th, 2020, 11:33
But I also would like to add some new buttongroups into the combattracker, and I think the ct_host.xml is where to add them.
So I'd need to encapsulate my new buttongroups in the /sheetdata tags wouldn't I?
And when I use the sheetdata tags alongside the merge="join" that's when my problems start :P

XML is so new to me, it's very frustrating.
I must be barking up the wrong tree I think.

Cheers, Steve.

Trenloe
June 5th, 2020, 11:42
OK, so you want to add new stuff into the GUI.

So, just include the changes that you want. Don't include the original controls - this is what is breaking the original control functionality.

Use the insertbefore="<control name>" as part of your merged windowclass.

For example, if you want to ibnsert a string control in the ct_entry XML before the control called "nonid_name" then use the following:



<windowclass name="ct_entry" merge="join">
<script file="ct/scripts/new_ct_entry.lua" />
<sheetdata>
<stringcontrol name="my_new_control" insertbefore="nonid_name">
{stuff you need in your new control}
</stringcontrol>
</sheetdata>
</windowclass>

Stv
June 5th, 2020, 11:44
Ok, so wierdness is happening (or at least seems weird to me)
If I leave in the sheetdata tags with nothing inside and have the merge="join" in, then everything works.
If I leave EVERYTHING in place as per the original xml file and have merge="join", the react button stops working.
I have no idea what is going on there, but it *may* work out for me, if I am able to just add my new controls inside the new 'blank' sheetdata tags.

Stv
June 5th, 2020, 11:45
Lol, I think I just posted about what you did, around the same time :D

Thanks again for your input Trenloe, you've been a massive help again.

Cheers, Steve.

Trenloe
June 5th, 2020, 12:01
If I leave EVERYTHING in place as per the original xml file and have merge="join", the react button stops working.
This is because you are merging the controls with the same name as the original controls on top of each other. Adding a layer for each control. So you'd then have to look at each of the original controls and see if they would need super code to make them work properly.


If I leave in the sheetdata tags with nothing inside and have the merge="join" in, then everything works.
If you have a blank sheetdata tag then you're not merging anything new and the original controls remain as is (no super reference) and their original code works too.

Moral of the story - only "merge" things that or new or that are changing.

Stv
June 10th, 2020, 13:12
Guess what, more XML related (probably stupid) questions :)


I need to change a value in template_ct.xml. But the data in this xml file is not in a windowclass, it's in a template.
Does merge="join" work for templates also, or would I just overwrite the full template in a sperate xml file and keep the same template name ?

Cheers, Steve.

Trenloe
June 10th, 2020, 13:24
Yes you can merge templates. The syntax is slightly different.

Info on templates, and template merging, here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063459/Ruleset+-+Templates+for+code+re-use

Stv
June 10th, 2020, 13:25
Awesome, thanks for the quick reply and the link.

Cheers, Steve.