Skip to main content
GameDev.net gamedev.net
🔒 Locked

[C++, Lua] Entity Logic

Started by Silvo Feb 16, 2007 at 6:10 PM 2 replies 1.5k views
Original Post
Silvo
Silvo
G'day! I am intending to implement my entity logic in Lua scripts, but I have come to a problem. Originally I was intending to have a separate lua_State for each entity, each with the script of the entity logic loaded; however, some entities may use my GUI (also written in Lua), but there can only be one instance of that, and if each entity is in a different VM, then they could not all access the same GUI, just their own local versions of it (which would not work). My next idea was to make each entity an object in a Lua Table, all in the same VM, which would allow them to use the GUI. Basically what I am asking is what would be a good way to do this? Is my latter option a good way, or are there other tips and tricks that I am not aware of? How would you do it?
dmail
dmail
I would use the one VM, to be honest I don't understand why you would want a different lua state for each entity.
Silvo
Silvo
Thank you for that. To be honest I don't know why I thought that a separate VM for each entity would be good... I just did.
JoshG
JoshG
Heya Silvo,

I went through the same thing last year. My current method is for each entity, I hold a reference to a lua table. that table uses a metatable based upon the type of entity it is...ie..monster, upgrade etc. (The metatable is being assigned using luabind)

When I load a script for the entity, I change the lua environment to the entity's table, this way all the functions for the entity are loaded into it's own personal table. That way they don't interfer with global functions etc, and I can still access any global variables that I might need.

Hope this helps a little, It's a little confusing if you havn't used luabind before...

--Josh

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.