Feature Request: `entity:get_property()` could convert numbers or booleans automatically
It would just be a nice quality of life feature if entity:get_property()
could automatically recognize numbers and booleans and return them properly.
Right now, if you set a property like entity:set_property("property", 2)
or entity:set_property("property", true)
, then these are returned from entity:get_property("property")
as String types. This is not a bug, as it's the described behavior, but it is a small inconvenience to wrap these get_property
calls in a to_number(entity:get_property(...))
.
A common use I have for entity properties is to set values for custom entities such as "speed" or "damage", which are usually numbers. It's a small conversion to catch them, but it would be nice if it were automatic. It's not a big deal! Just a small quality feature to consider : )
This test for it currently fails:
local test_entity = map:create_custom_entity({x=0, y=0, layer=0, width=16, height=16, direction=0})
test_entity:set_property("number", 2)
local num = test_entity:get_property("number")
assert(type(num) == "number", "Property is not a number")