maptool icon indicating copy to clipboard operation
maptool copied to clipboard

[Bug]: setLibProperty only works with integers

Open Lector opened this issue 1 year ago • 10 comments

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

  1. Create an addon with a property with no default value including the files prop_1.txt and name it using prop_file_map.txt
  2. call a script that sets this property to 1 using setLibProperty.
  3. broadcast the property (it should work like expected)
  4. call another script that sets the same property to "myString" using setLibProperty.
  5. 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

  1. open the campaign.
  2. click on the book-button (2nd button) in the SL-Frame
  3. Open the handouts tab clicking on the feather-icon
  4. 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.
  5. 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.

Lector avatar Jan 01 '24 12:01 Lector

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?

cwisniew avatar Jan 01 '24 13:01 cwisniew

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.

Lector avatar Jan 01 '24 15:01 Lector

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...

Lector avatar Jan 01 '24 17:01 Lector

https://wiki.rptools.info/index.php/string_(function)

Can you try if the casting solves your problem?

emmebi avatar Jan 02 '24 10:01 emmebi

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...

Lector avatar Jan 02 '24 11:01 Lector

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?

emmebi avatar Jan 02 '24 11:01 emmebi

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.

Lector avatar Jan 02 '24 12:01 Lector

But thanks for you help.

Lector avatar Jan 02 '24 12:01 Lector

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

cwisniew avatar Jan 02 '24 12:01 cwisniew

here you go: https://github.com/RPTools/maptool/issues/4615

Lector avatar Jan 03 '24 13:01 Lector