vblack 2 Posted June 5, 2017 Share Posted June 5, 2017 'm using the C++ SDK and lua for small objects code. I need to create the entities from C++ and later use the bool Entity::CallFunction(const std::string& functionName, Object* extra) How to 'bind' on script lua to an entity ? it looks that Interpreter is using tolua++, but I can't figure how to load the .lua properly to the object // Create 100 special entity std::vector<Entity*> list; for (int i = 0; i < 100; i ++) { Entity* entity = new MyEntity(); entity->AddToWorldTable(true ); list.push_back(entity); } // Load special script (But not working, object not callable). Interpreter::NewTable(); Interpreter::SetGlobal("Script"); // Must Script. Don't change that, because the script are prefixed with Script:myFunction if (Interpreter::ExecuteFile("MyEntity.lua")) { System::Print("Error: Failed to execute script \"" + it + "\"."); } for (auto&it : list) it->CallFunction("OnSpecialFunction") Script Lua function Script:OnSpecialFunction() print self end Quote Link to post Share on other sites
vblack 2 Posted June 5, 2017 Author Share Posted June 5, 2017 Yes I've read that, but the class doesn't do the loading of LUA file and instancing of for object I'm using Interpreter::Push (which is tolua_pushusertype(L, o, o->GetClassNameStr().c_str()) But my class is for example Class A : public Entity, but my script using Script:<NameSpace> (same format as Leadwerks). I need a function from an allocated Entity 1) Load 1 Lua file (Interpreter::ExecuteFile) (Which is using Script::<NameSpace> function). 2) 'Connect' for each entity to the loaded lua (I don't want to load 1000 times the same lua code). 3) Ability that each entity have its own variable. Quote Link to post Share on other sites
Optimus Josh 9,733 Posted June 6, 2017 Share Posted June 6, 2017 Entity::SetScript? Quote Link to post Share on other sites
Crazycarpet 85 Posted June 6, 2017 Share Posted June 6, 2017 Doesn't this just give "Error failed to..." every time? you're printing the error when the Interpreter::ExecuteFile method returns true.. But yeah Josh is right, Entity::SetScript(const std::string& path); is what you're looking for. Quote Link to post Share on other sites
vblack 2 Posted June 7, 2017 Author Share Posted June 7, 2017 Ah ok, so SetScript is not just setting the file name, it loads and attach it, correct ? Quote Link to post Share on other sites
Optimus Josh 9,733 Posted June 7, 2017 Share Posted June 7, 2017 Yep. There is no script loading function, because there is no script object. Quote Link to post Share on other sites
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.