SpiderPig Posted June 7, 2013 Posted June 7, 2013 What's the correct way to handle GetKeyValue() & SetKeyValue() in Lua now, so I can make custom keys? Quote
Josh Posted June 7, 2013 Posted June 7, 2013 Do you mean in the editor? Quote My job is to make tools you love, with the features you want, and performance you can't live without.
SpiderPig Posted June 7, 2013 Author Posted June 7, 2013 I mean in a script attached to the entity, so when I call SetKeyValue() from C++ I can perform Lua code on that entity. Quote
Rick Posted June 7, 2013 Posted June 7, 2013 local value = entity:GetKeyValue("key") entity:SetKeyValue("key", "value") Is that all you mean? Quote
SpiderPig Posted June 7, 2013 Author Posted June 7, 2013 I want to handle the event like in LE2; function object:SetKey(key,value) if key=="key1" then self.key1=tonumber(value) else return self.super:SetKey(key,value) end return 1 end ...or does LE3 handle it in a different way? Quote
Rick Posted June 7, 2013 Posted June 7, 2013 Yeah, it's different. There is no function that gets called when you set values from the editor. Check out http://www.leadwerks.com/werkspace/page/documentation/_/user-guide/object-scripts-r631 Quote
SpiderPig Posted June 7, 2013 Author Posted June 7, 2013 Thanks for that. So SetKeyValue() can only set keys that have been predefined then, like an entity's name or something... Quote
Rick Posted June 7, 2013 Posted June 7, 2013 No, you can set anything you want (has to be text I think though). entity:SetKeyValue("age", "10") entity:SetKeyValue("eye.color", "blue") etc Quote
Josh Posted June 7, 2013 Posted June 7, 2013 Probably best to use Entity::SetString and GetString(). This will attach values to the Lua script object, if a script is present. They GetKey/SetKey functionality was just left in for backwards compatibility. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
SpiderPig Posted June 8, 2013 Author Posted June 8, 2013 Can SetString() be handled in the script so when a value changes I can execute some code? ...rather than checking for the changed value in UpdateWorld() - like LE2 handled SetKey()... Quote
Josh Posted June 8, 2013 Posted June 8, 2013 No, but you could just call Entity::CallFunction(functionname) Quote My job is to make tools you love, with the features you want, and performance you can't live without.
SpiderPig Posted June 8, 2013 Author Posted June 8, 2013 That'd be the shot, thanks. Is there any documentation for CallFunction, SetString & GetString? I looked under "Entity" but found only SetString with not much info... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.