Rick Posted December 1, 2009 Share Posted December 1, 2009 Here is something that might be of interest and should allow for some more dynamic behavior controlled from the editor. You can call functions by just knowing the string name of it. function HelloWorld(name) print("Hello "..name) end _G["HelloWorld"]("Rick") With this you can have a model class that has 2 properties. One for a lua file and one for a function name. In the Spawn() you can run a dofile() on the lua file to load it, and inside the update you can read the function name and call it from the string name. This would allow 1 model class to have different behaviors based on what you setup via the editor. So let's say I'm making an rpg game. I have a rat model that I really like and would like to use a few times. Let's say I want a "Small Rat" that has basic attacks. Then later in my game I want to use the same rat model but want it to have more functionality and call it "Big Rat". With this I can have 2 separate lua files that control the behavior of the rat and in the editor assign what lua file gets played with each instance. Very cool. This will also be useful for volume triggers because you can use the same trigger model but have it run different things, because the trigger model is generic and what happens in each trigger would be unique. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 You can even write a little script in the property editor and make the model execute that code. There's an option in the text property to open a multiline text editor in a separate window. I didn't use this feature, but it is an example of just how flexible Lua is. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Author Share Posted December 1, 2009 Would that execute it right in the editor? Is that a value we can get from a property so it can be executed at a specific time? Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 Maybe enter this text in the property editor: function CustomBehavior(entity) Notify("Hello!") end Then in SetKey add this: function SetKey(key,value) if key=="customscript" then dostring(value) end end So now at this point the new code has been evaluated and the function is usable in Lua. Now add this to the message receive function: function ReceiveMessage(message,extra) if message=="custombehavior" then CustomBehavior(entity) end end I don't know if this is a great idea, because it is confusing, and the state is shared across all instances of the model, but it's interesting that it works. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Author Share Posted December 1, 2009 Cool, that works. For things that I want ran every Update() call or on Collisions() for volume triggers I'll probably just do the separate filename/function thing for clarity. Quote Link to comment Share on other sites More sharing options...
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.