Charrua Posted August 8, 2014 Share Posted August 8, 2014 i have many objects with scripts attached if i get one of them via collision or ray pick, can i call a function declared inside the entity's script? something like pickinfo.entity.script.Hit(), if Hit is defined inside the script thank's in advance Juan Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 8, 2014 Share Posted August 8, 2014 Try this: http://www.leadwerks.com/werkspace/topic/9838-has-script-attached/ Quote Link to comment Share on other sites More sharing options...
Rick Posted August 8, 2014 Share Posted August 8, 2014 Unless Josh made this easier in Leadwerks, you probably can but it might be ugly. I know Josh has some Lua wrappers exposed. Below is a starting point to see how a "normal" lua function is called. Look at the Lua function here and you should see some similar ones in Leadwerks that Josh wrapped up and you might be able to work it out. If you do, make a nice easy function for the rest of us Since script functions are table functions the call will be different. You probably have to push the table onto the stack or something like that before making the call. http://www.lua.org/pil/25.2.html It would be really nice if Josh made this really easy though. Something like: pickinfo.entity->script->CallFunction("Hit"); Quote Link to comment Share on other sites More sharing options...
Charrua Posted August 8, 2014 Author Share Posted August 8, 2014 thank's i have to seriously start studying c++ and lua by the moment i have to evade call a script function from c++, till i get older! thank's again Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
beo6 Posted August 12, 2014 Share Posted August 12, 2014 tried: entity->CallFunction("Hit"); ? Quote Link to comment Share on other sites More sharing options...
Rick Posted August 12, 2014 Share Posted August 12, 2014 That does work. I wonder how one could pass parameters though. There is also a CallOutputs() which is nice. Quote Link to comment Share on other sites More sharing options...
beo6 Posted August 12, 2014 Share Posted August 12, 2014 Not sure. I am on the go, but you could try if entity->SetString("yourVar", "yourvalue"); Exists in the API and set it before calling the function Then read that value in the script. Quote Link to comment Share on other sites More sharing options...
Rick Posted August 12, 2014 Share Posted August 12, 2014 Yeah, that's what I was thinking, but limited to string/number that way vs tables/objects, but would probably work for a good number of situations although a little hacky. Quote Link to comment Share on other sites More sharing options...
beo6 Posted August 12, 2014 Share Posted August 12, 2014 There is also entity->SetObject(); Quote Link to comment Share on other sites More sharing options...
Rick Posted August 12, 2014 Share Posted August 12, 2014 I wonder if we can combine CallFunction() with pushing things on the stack in Lua if that would pass the data to the function like normal parameters. Will have to test when I have time. 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.