View Full Version : Merge Rules Question
Bidmaron
December 14th, 2016, 02:36
OK, there is a template (string_tableresult in record_table.xml if you want to know) that has the following tag:
<script file="common/scripts/list_textitem.lua" />
While this code can remain unaltered, I need to add an onValueChanged handler to this code.
To improve my extension's resilience with respect to future code base mods, I want to avoid duplicating this file.
The best way I can think of to add the handler without duplicating the file is to add a level of indirection whereby I add a new version of string_tableresult that has its own script tag like so:
<script>
function onValueChanged()
....
end
</script>
So, to add this function without replacing all the code in the original script file, what kind of merge rule would I use? I think the default merge would work, but I was hoping the demigods here can confirm that.
Moon Wizard
December 14th, 2016, 17:05
Templates do not support merge rules at the top level, because they inherently merge with any included tags.
If you want to change this template, you would need to override the template, and create an intermediate template.
<template name="string_tableresult_step">
<stringfield>
<stateframe>
<keyedit name="fieldfocus" offset="7,5,7,5" />
</stateframe>
<font>sheettext</font>
<multilinespacing>20</multilinespacing>
<empty> -- </empty>
<nohighlight />
<script file="common/scripts/list_textitem.lua" />
</stringfield>
</template>
<template name="string_tableresult">
<string_tableresult_step>
<script>
function onValueChanged()
....
end
</script>
</string_tableresult_step>
</template>
Regards,
JPG
Bidmaron
December 14th, 2016, 19:20
Fantastic. That is what I thought.
Bidmaron
December 15th, 2016, 03:51
Is there an accepted coding standard for what we should display in the chat window if a script encounters an error (in my case right now, I am inquiring because if a user tries to make a table column too wide for the current window width or tries to make it smaller than a defined minimum, I need to advise the user of their error)?
In my search for addChatMessage, I have found the following error messages:
ps_message_itemdistributeempty generated when user tries to distribute empty parcel manager_ps_loot.lua msgfont and with portrait_gm_token
ps_message_itemsellcostmissing self-explanatory " systemfont
ps_message_itemsellcostlow self-explanatory " systemfont
There is a SystemMessage routine in the chat manager, which uses systemfont and no portrait. Is this an attempt to standardize what we should be using for error messages? It is called in these example circumstances in the loot manager:
manager_ps_loot.lua ps_message_itemfailtoomanyassign; ps_message_itemfailcharmissing; ps_message_itemfailcreate
But it is also used to pass messages that are not errors (list of standard slash commands, e.g.)
To standardize, it seems we should have an error message displaying routine in the Comm library or in the Chat Manager that uses a unique font and a special icon.
For the time-being, I guess I will use SystemMessage.
Moon Wizard
December 15th, 2016, 17:08
ChatManager.SystemMessage() is used in the CoreRPG rulesets.
Regards,
JPG
Bidmaron
December 17th, 2016, 02:24
I have a button that is context sensitive and needs to know the control that previously had the focus. Is there a convenient way to do this through the interface without setting some kind of global when the previous control is clicked? I looked in windowControl and interface but see nothing that returns the previously-focused control.
Moon Wizard
December 17th, 2016, 07:24
No, there is nothing in the API to do that. You would have to add a global onLoseFocus to each other control in the window you wanted to track.
Alternately, you could just add database change handlers for those fields, if you were just concerned about values changing.
What are you trying to build?
JPG
Bidmaron
December 17th, 2016, 16:48
MW, I am working on some usability improvements to the wonderful built-in tables. First, I am adding the ability to specify the column width in tables using the scroll wheel while you are in any column heading (in doing this, I am, as you suggested earlier, switching from a windowlist for table row cells to a subwindow with dynamically-created controls). But I also noticed that you can only delete columns in a lifo kind of way. I thought it would be useful to be able to delete the column that the cursor is currently in.
Moon Wizard
December 20th, 2016, 18:56
You could possibly do this, but you would have to rename all the data. (i.e. if you delete column 2, you would need to rename the label and column data for columns 3 and higher to column 2 and higher.) Just be careful that you don't drop any data when you do this.
Regards,
JPG
Bidmaron
December 20th, 2016, 23:42
Got it, MW. Will be careful.
Bidmaron
December 24th, 2016, 14:48
Trenloe, in your basic card extension, in the <root> node, you have a 'logo' attribute. I cannot locate that in the documentation or the xml definitions. Just what is that please?
Bidmaron
December 24th, 2016, 15:17
Also, you have an <announcement> element that I cannot find documented?
Andraax
December 24th, 2016, 15:37
Those are dumped into the chat box when the ruleset loads the extension.
Bidmaron
December 24th, 2016, 16:02
Okay, Andraax, but shouldn't that be documented somewhere?
One last point: Trenloe has a file in his extension titled "record_table - Reference CoreRPG v3.1.7.xml" which is not referenced in the extension.xml file or anywhere else in the extension. It is my belief that the only files that will get loaded with an extension is anything that is an 'include file' or any script file called out in the xml definitions. I would just like to confirm that this file is informational only and not actually used when the extension runs. (i.e. am I looking at another undocumented feature of some kind?)
Andraax
December 24th, 2016, 16:20
Also, ruleset files and files in base rulesets are loaded. Plus any other extensions, if this extension relies on another being loaded.
Bidmaron
December 24th, 2016, 16:22
Also, ruleset files and files in base rulesets are loaded. Plus any other extensions, if this extension relies on another being loaded.
Of course. But that file I mentioned is not loaded, right?
Andraax
December 24th, 2016, 16:25
Don't think so, but I would have to experiment to verify.
Bidmaron
December 24th, 2016, 16:44
Thanks, Andraax.
Trenloe
December 24th, 2016, 16:55
One last point: Trenloe has a file in his extension titled "record_table - Reference CoreRPG v3.1.7.xml" which is not referenced in the extension.xml file or anywhere else in the extension.
It isn't loaded. In my extensions I include a copy of the original files I modify. This makes checking for needed changes after future FG ruleset updates much easier. Just do a compare between the new and original files and see if the extension needs updating.
Bidmaron
December 24th, 2016, 16:57
Thanks, Trenloe.
Trenloe, what about my other questions above? Are those features documented somewhere? (announcement and logo). You don't have a logo file in your extension, so I'm not sure what that is doing anyway.
Trenloe
December 24th, 2016, 16:58
MW documented it in a thread somewhere. You can probably find that in a search.
Trenloe
December 24th, 2016, 17:01
All it does is output text to the chat window when the extension is loaded. Using the usual message format: https://www.fantasygrounds.com/refdoc/Comm.xcp I don't know if all options are available, I've only used text, font and icon.
Bidmaron
December 26th, 2016, 03:07
As I am working on my table extension, I am getting into lua patterns for the first time, and this world is new to me for sure.
This code is in the onTableRoll function in the manager_table.lua file of the Core rule set:
....
local sPattern2 = "%[" .. Interface.getString("table_tag") .. "%] [^[]+%[(%d) %- ([^)]*)%]";
local sColumn = string.match(rRoll.sDesc, sPattern2)
if sColumn then
nColumn = tonumber(sColumn) or 0;
end
...
The code is designed to parse out a table column number, it seems, but I cannot figure out how the pattern does that. The Lua 5.1 reference manual says this about sets:
[set]: represents the class which is the union of all characters in set. A range of characters can be specified by separating the end characters of the range with a '-'. All classes %x described above can also be used as components in set. All other characters in set represent themselves. For example, [%w_] (or [_%w]) represents all alphanumeric characters plus the underscore, [0-7] represents the octal digits, and [0-7%l%-] represents the octal digits plus the lowercase letters plus the '-' character.
The interaction between ranges and classes is not defined. Therefore, patterns like [%a-z] or [a-%%] have no meaning.
[^set]: represents the complement of set, where set is interpreted as above.
So, my first question is the set after "TABLE". According to the 5.1 documentation, you are not supposed to be able to use the magic characters (^$()%.[]*+-?)) without escaping them with a '%'. So, I am really confused on what that set is.
damned
December 26th, 2016, 04:10
https://www.lua.org/manual/5.2/manual.html#6.4.1
https://www.lua.org/pil/20.2.html
LUA patterns do my head in!
example %d is all characters
the () brackets around (%d) it mean to return that result
the [] brackets are creating a set including the characters above and the next piece...
Id love to nut it all out for you but Id probably get it wrong and send you off on a goose chase...
Bidmaron
December 26th, 2016, 15:53
Thanks for trying, damned, but that second extract above was from the 5.1 Lua manual, which is the official version used by Fantasy Grounds. I can find the syntax, but just trying to work through how it is working in the ruleset.
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.