maptool
maptool copied to clipboard
[Bug]: setLibProperty only works with integers
Describe the Bug
I am working on an addon for MT and mentioned that since v.1.14 (maybe earlier...) something stopped working. I investigated and mentioned that setLibProperty is not working if you pass a string while integers work.
[h: setLibProperty("myProp", 0)] <- myProp is now 0 [h: setLibProperty("myProp", "0")] <- myProp does not change
To Reproduce
- Create an addon with a property with no default value including the files prop_1.txt and name it using prop_file_map.txt
- call a script that sets this property to 1 using setLibProperty.
- broadcast the property (it should work like expected)
- call another script that sets the same property to "myString" using setLibProperty.
- broadcast the property (it should still remain the value 1)
Expected Behaviour
In my scenario i would expect to see "myString" in the chat because the property was set to this value.
Screenshots
No response
MapTool Info
1.14.3
Desktop
Windows 10
Additional Context
Is important to notice that this is something that was working before. I converted my framework from a libToken to an addon in march 2023. Im pretty sure i tested my feature at the time and everything worked. i have not used this feature a lot and can't tell which MT update caused the problem but i hope you can figure it out.
Here is the discord discussion about this issue with some more infos about what i have tried: https://discord.com/channels/296230822262865920/1191310344568705024
If you have problems testing or need a demo you can try the latest version of my campaign if you like. I currently do not have a smaller demo version of the bug but ill give you a step by step guide to reproduce the issue using this demo DSA5maptool-1.4.0.zip
- open the campaign.
- click on the book-button (2nd button) in the SL-Frame
- Open the handouts tab clicking on the feather-icon
- You now see 30 handouts that should be hidden from the players. By clicking on one of the closed eyes the property "sharedHandouts" (prop_1) changes from the default empty string to the number of the clicked handout.
- Click another eye. The value is now set to a comma separated list of handout numbers. But the value does not change.
I hope this all helps to identify the problem. If you have further questions or need more infos let me know.
Add-ons by design have typed data, so if you set it to 0 originally its an integer and you can't set a string value. Do you have a valid use case for it some times being an integer some times being a string?
In my scenario i have a list of Handouts (1-30) visible for players. The default value is not set (empty string). When sharing a handout this value is set to a comma seperated list of the currently shared handouts using listAppend. When the GM shares the first handout this value changes from "" to e.g. "1", which is probably parsed as an integer... After sharing another handout this value should change from "1" to "1, 2". This will not work because "1" has locked in as an integer causing my handout-system to block.
Thats how my code works right now.
[h: hShared = getLibProperty("SharedHandouts","com.github.lector.dsa5maptool")]
[h: hItem = listFind(hShared, hNum)]
[h,if(hItem == -1), Code:
{
[hShared = listAppend(hShared, hNum)]
...
};
{
[hShared = listDelete(hShared, hItem)]
...
}]
[h: setLibProperty("SharedHandouts", hShared, "lib:com.github.lector.dsa5maptool")]
Maybe the solution could be a way to cast the variable 'hShared' to a string. Im not sure if thats possible in the macro language...
https://wiki.rptools.info/index.php/string_(function)
Can you try if the casting solves your problem?
This works better now. I can share multiple handouts. The only value that is still not accepted is the empty string. I think i will merge from a comma separated list to a json-array to solve my problem. The bad thing is that my addon is already out there and im not sure how it will behave with campaigns that already have a SharedHandouts value...
as a quick fix, you could remove the property; unless I am wrong, these could be accessed via the data.* functions, something like
[h: data.removeData("addon:", "com.github.lector.dsa5maptool", "SharedHandouts")]
and then re-add it with the value changed?
I think i will either do this or rename it to "VisibleHandouts". I will do some testing on this. I still suggest a possibility to predefine the datatype of properties shared in addons.
But thanks for you help.
I think i will either do this or rename it to "VisibleHandouts". I will do some testing on this. I still suggest a possibility to predefine the datatype of properties shared in addons.
Add an issue for a feature request of what you want and I can look at it
here you go: https://github.com/RPTools/maptool/issues/4615