gloot icon indicating copy to clipboard operation
gloot copied to clipboard

Getting a JSONItemPrototype from an ItemProtoset.

Open SkyTheGreatOne opened this issue 3 years ago • 1 comments

Apologies for the inconvenience, but I was running some code to dynamically create an ItemProtoset and found that when receiving a JSONItemPrototype, the received data is incorrect.

Here is some of my code that I used for it:

var item_set = ItemProtoset.new() #Create ItemProtoset

var item_dict = {"id":"TEST"} #Create Item with an id using a dictionary.
item_set.add_prototype(JSON.stringify(item_dict)) #Add JSONItemPrototype to ItemProtoset by converting the dictionary to JSON format.
print(JSON.stringify(item_dict)) #Print Item as JSON.
print(item_set.has_prototype(JSON.stringify(item_dict))) #Print 'true' if item exists.
print(item_set.get_prototype(JSON.stringify(item_dict))) #Print Item received from ItemProtoset.

The output is:

{"id":"TEST"}
true
{ "id": "{\"id\":\"TEST\"}" }

I'm not sure if this is an error of the plugin or an error of my code, but I've tried multiple different methods to get the data and this is the only way that I could find that didn't return an error.

SkyTheGreatOne avatar Jun 12 '23 17:06 SkyTheGreatOne

I just now found out that it was because it was still considered a string, and when converted to a dictionary, fixes itself. Closing issue.

SkyTheGreatOne avatar Jun 15 '23 22:06 SkyTheGreatOne