PDA

View Full Version : My extension based on OldSchoolEssentials/MoreCore/CoreRPG question



Varsuuk
July 12th, 2020, 23:44
I have to run to dinner and then more Taxes, so figured toss this out to see if anyone had a tip for me so when get back to it very late tonight, I might be able to blow past it.


Whenever I hit the icons for modifiers or effects in sidecar (used all MCOSR_Theme (copied in) big sidecar buttons but for now CoreRPG for the small ones) I get:



Script Error: [string "list"]:1: attempt to call field 'onInit' (a nil value)
Database Notice: Campaign saved.
Ruleset Warning: window: Anchored static height ignored for control (pcclasslink) in windowclass (charsheet)
Ruleset Warning: window: Anchored static height ignored for control (pcclasslink) in windowclass (charsheet)
Ruleset Warning: window: Anchored static height ignored for control (pcclasslink) in windowclass (charsheet)
Script Error: [string "list"]:1: attempt to call field 'onInit' (a nil value)



The respective windows open, but the console pops up as such. (I haven't coded anything relating to modifiers or effects so if there needs to be base calls - haven't done them yet).

damned
July 13th, 2020, 01:52
have you named anything list or onInit?

Varsuuk
July 13th, 2020, 02:17
Found it - has nothing to do with anything anyone but me would have done wrong ;) but when I understand it Morel and the fix later on today - will update this post.

Varsuuk
July 13th, 2020, 02:20
Ah Thanks Damned, (I posted mine before seeing your reply) - No, it was my override of list_text. I was about to try to find and trace what happens when those two buttons are called but decided to do more hit and miss testing and commented out my override and the problem went away.


So, realized my assumption that it "works" was wrong and realize what did wrong too I think - I had thought it tested since I tried two different controls one with and one without the field I added and both worked right. But it's a mistake in merge= option. I needed "join" I think, checking now.

EDIT: Nope, hairier than that. Grrr... will be bit longer ;)

Varsuuk
July 13th, 2020, 02:35
I'm guessing this is a big "nope" but gonna toss it out there.

So, I tried to change sort by and it worked, but I didn't want to do it via sortby because even if I did:


<script name="alt_sort_order">
function onSortCompare(w1, w2)
return DB.getValue(w1.getDatabaseNode(), "alt_sort_order", DB.getValue(w1.getDatabaseNode(), "name", ""))
> DB.getValue(w2.getDatabaseNode(), "alt_sort_order", DB.getValue(w2.getDatabaseNode(), "name", ""))
end


This allows for the case where for some reason w1 has the proper alt_sort_order set and w2 doesn't - so it would compare alt_sort_order field against name field.

And since I did not know a way (yet) to change one specific instance of list_text into using a different sort, I tried updating list_text itself to using my onSortCompare which apparently, since it is a "<script" will hide the earlier assigned list_text.lua script (which has onInit() for example) so I am LUCKY this bug reared right here early on.

My two choices as I see it (so far) are:
1. Copy entire list_text.lua code from CoreRPG into my own with the new sortCompare (depending on how called elsewhere it MIGHT work)
2. Find a way to take an "instance" of list_text defined in MoreCore (for example, cliroller) and modify it with just the sortby change which in the case that I know it SHOULD have alt_sort_by, it is OK to missort if it is missing.

probably more, but it's a new thing I am looking at for me.

Varsuuk
July 13th, 2020, 02:50
So, if I step back from my attempts at implementation and describe the problem more generally:

I have a control in MoreCore, (e.g., <list_text name="cliroller1"> ) where I would like to have it sort on a field, alt_sort_order IF and only if the field is present (preferably in both, but "works" as long as one of them has it. And to sort (as is usual default) on "name" field if the sort field is not present.


Like, I want Str, Dex, Con...Char order vs Char,Con,Dex,...Wis order. And in later case, the OSE example "damage" rolling list to put d10 at end instead of top (where d10 < d4 lexically...)

I'd LOVE to ask more in chat if anyone is on discord and can chat and who understands what I mean and might have tips on what I should read?

Varsuuk
July 13th, 2020, 03:11
Tested #1, copying:


function onSortCompare(w1, w2)
local node1AltSortOrder = DB.getValue(w1.getDatabaseNode(), "alt_sort_order")
local node2AltSortOrder = DB.getValue(w2.getDatabaseNode(), "alt_sort_order")

if node1AltSortOrder ~= nil and node2AltSortOrder ~= nil then
return node1AltSortOrder > node2AltSortOrder
else
return DB.getValue(w1.getDatabaseNode(), "name") > DB.getValue(w2.getDatabaseNode(), "name")
end
end


into text_list.lua copy in my extension directory. As expected this works... but is a HORRIBLE way to go since it means I need to keep updating it each time CoreRPG is updated.

Basically, I am trying to either add a method or <script> entry without obliterating the existing script (which does not define onSortCompare() so no issues) or I want to just modify <sortby> on a specific instance of a MoreCore object. Perhaps on my extension's init.

Varsuuk
July 13th, 2020, 03:18
have you named anything list or onInit?


Interestingly, the control is called list_text, which comes from windowlist - but "list" is what the error message prints.

Varsuuk
July 13th, 2020, 04:19
37667
Above shows attributes not sorting automatically in alpha, i.e. Char, Con, Dex, etc instead it is Str, Dex, Con, etc.
Also, you will see that D10 in damage section is last instead of the default, first, on the list.


[EDIT: Note, not seeing the errors on the sidebar and it is sorting properly, so for now assuming I got it right - if I find a reason why it isn't working or any side-effects, I will update this thread so I do not give misinformation.]


OK - Figured out how to update the sortby for a specific named instance in my extension:

(I'm sure it's trivially obvious, but I had never worked on modifying this sort of generic all purpose control before, putting here in case helps anyone)



<root>
<!-- New WindowClass "charsheet_more" -->
<windowclass name="charsheet_more" merge="join">
<sheetdata>

<!-- Customize sorting for the Attributes list -->
<list_text name="cliroller1" mege="join">
<script>
function onSortCompare(w1, w2)
local node1AltSortOrder = DB.getValue(w1.getDatabaseNode(), "alt_sort_order")
local node2AltSortOrder = DB.getValue(w2.getDatabaseNode(), "alt_sort_order")

if node1AltSortOrder ~= nil and node2AltSortOrder ~= nil then
return node1AltSortOrder > node2AltSortOrder
else
return DB.getValue(w1.getDatabaseNode(), "name") > DB.getValue(w2.getDatabaseNode(), "name")
end
end
</script>
</list_text>

<!-- Customize sorting for the Melee Damage list -->
<list_text name="cliroller2a" mege="join">
<script>
function onSortCompare(w1, w2)
local node1AltSortOrder = DB.getValue(w1.getDatabaseNode(), "alt_sort_order")
local node2AltSortOrder = DB.getValue(w2.getDatabaseNode(), "alt_sort_order")

if node1AltSortOrder ~= nil and node2AltSortOrder ~= nil then
return node1AltSortOrder > node2AltSortOrder
else
return DB.getValue(w1.getDatabaseNode(), "name") > DB.getValue(w2.getDatabaseNode(), "name")
end
end
</script>
</list_text>

<!-- Customize sorting for the Ranged Damage list -->
<list_text name="cliroller3a" mege="join">
<script>
function onSortCompare(w1, w2)
local node1AltSortOrder = DB.getValue(w1.getDatabaseNode(), "alt_sort_order")
local node2AltSortOrder = DB.getValue(w2.getDatabaseNode(), "alt_sort_order")

if node1AltSortOrder ~= nil and node2AltSortOrder ~= nil then
return node1AltSortOrder > node2AltSortOrder
else
return DB.getValue(w1.getDatabaseNode(), "name") > DB.getValue(w2.getDatabaseNode(), "name")
end
end
</script>
</list_text>

<!-- Change Health to HP -->
<string_useredit name="pc_label_health" merge="join">
<default>Hit Points</default>
</string_useredit>

gamerhawaii
July 13th, 2020, 20:31
Just FYI in your code, several of the items have the word "merge" spelled wrong:


mege="join"

instead of


merge="join"

Varsuuk
July 13th, 2020, 21:40
Thanks so much for the eagle eye :)
When I retyped it I flubared it.

Quick question, it worked, so

1. Is merge="join" default? Would explain why it still merged it in (I suppose I can go back to WIKI to find this out ;) but not working on this until if lucky late tonight - still "at work" and after that... more tax time.)
2. IF not, is it inherited via the merge="join" (PROPERLY spelled) above in the <windowclass> tag?