Reserved Words

Is there a list of reserved words we should avoid using in code?

I’ve been caught out more than once trying to use particular words that yield confusing error messages. For example:

msg.post(".", "create")

Generates error message “Field position not specified in table”

1 Like

msg.post(".", “reload”)

I remember I was asking it someday, but can’t find it. Here is my list so far:

-- SYSTEM MESSAGES:
CONTACT = hash("contact_point_response"),-- defold msg sent on one point collision of kinematic and dynamic objects
COLLISION = hash("collision_response"),	-- defold msg sent on collision
TRIGGER = hash("trigger_response"),		-- defold msg sent on trigger collision
ANIM_DONE = hash("animation_done"),		-- defold msg sent when a sprite animation is done
SET_PARENT = hash("set_parent"),		-- defold msg to change parent for a game object
RAY_CAST = hash("ray_cast_response"),	-- defold msg sent as a response to a raycast
WIN_RESIZE = hash("window_resized"),	-- defold msg sent on window resize event
ENABLE = hash("enable"),				-- defold msg to enable game object or component
DISABLE = hash("disable"),				-- defold msg to disable game object or component
LOAD = hash("load"),					-- defold msg to load a proxy collection
UNLOAD = hash("unload"),				-- defold msg to unload a proxy collection
PROXY_LOADED = hash("proxy_loaded"),	-- defold msg sent when a proxy is loaded
PROXY_UNLOADED = hash("proxy_unloaded"),-- defold msg sent when a proxy is unloaded
INIT = hash("init"),					-- defold msg to call init
RELOAD = hash("reload"),                -- defold msg to call reload 
FINAL = hash("final"),					-- defold msg to call final
SET_TIME = hash("set_time_step"),		-- defold msg to set time step of the collection

We can also play/stop particlefxs, play/stop sounds, set gain etc. We can now also set/get gravity with a message, set/get cursor and playback rate of an animation :wink:
There is plenty of messages reserved. Some of them are described in documentation below components, but I think we need such list in one place, somewhere in Defold’s documentation.

1 Like

I will make sure to document this somewhere in our manuals or in the API reference. There is a difference between the various messages:

  • Some are public and you are supposed to either send them or respond to them in on_message(). These are messages such as “contact_point_response” or “enable”
  • Other messages are internal to the engine, like the “create” message mentioned above, and they should never be sent by the game. I guess it is mainly these messages that we need to document somehow.
7 Likes

Preferably, we should be able to “hide” the internal messages by prefixing them with “_” or something.

8 Likes

It is a great idea! :wink:

When you would change the naming of internal, private messages, it’s the others that, at least me, want to have somewhere wraped up.

Actually, @Pkeod released DefRS with useful constants module, check out: https://github.com/subsoap/defrs/blob/master/defrs/utils/constants.lua

3 Likes

This could be very useful.

4 Likes