Jump to content

Access Scripts properties


moechofe
 Share

Recommended Posts

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')

Link to comment
Share on other sites

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

  • Upvote 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...