moechofe Posted January 7, 2015 Share Posted January 7, 2015 Hi, I would like to access a property of a script (the one that appear in the Script panel of the leadwerks editor) inside an other lua script or with c++. How to do that? Something like: entity.script.myProperty or entity::GetScript<Entity>('myProperty') Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2015 Share Posted January 7, 2015 You first need to get access to that entity somehow. Normally you'd make a script property that is of type entity like: Script.Target = nil ---entity And then drag the other entity into this position in the script tab. Now inside your script self.Target refers to that other entity and since that other entity has a script attach (assuming it does) you access that script and all of it's functions and variables via self.Target.script.VariableName or self.Target.script:Function(). The key is to get access to an entity first. You can also check if an entity even has a script attached by seeing if the .script variable is nil or not. if entity.script ~= nil then entity.script.variable = 5 end 1 Quote Link to comment Share on other sites More sharing options...
moechofe Posted January 9, 2015 Author Share Posted January 9, 2015 Thank you for the answer. So if a user do not set the right lua script in the second entity, the first script should be ****ed up. This should not be very serious for the abstraction level covered by the lua scripting. But what about c++ side? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 9, 2015 Share Posted January 9, 2015 I don't think this works the same in C++. I've never used the script field in C++ so can't tell you how working with that is. In Lua you'd check if functions or variables (basically the same thing anyway) exist before trying to use them and if they don't you can print a warning to tell the person they messed up. Quote Link to comment Share on other sites More sharing options...
moechofe Posted January 26, 2015 Author Share Posted January 26, 2015 Just an update to explain that it works. My goal was to chain pivot entities to create a path system. My Camera has a script with a first entity value that point to Pivot 2. The Pivot 2 has a script with a target entity value that point to Pivot 4. ... In the Camera script : if self.first then self.from = self.first:GetPosition(true) if self.first.script and self.first.script.target then self.dest = self.first.script.target:GetPosition(true) end end 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.