diff --git a/Levels/scripts/deleteObject.lua b/Levels/scripts/deleteObject.lua index a49b066..6117ead 100644 --- a/Levels/scripts/deleteObject.lua +++ b/Levels/scripts/deleteObject.lua @@ -1,11 +1,18 @@ -function trigger(objectToChange) - if(not level) then - print("No level found in Lua!") - return - end - if(not physics) then - print("No physics found in Lua!") - return - end - level:deleteObject(objectToChange) +if(triggeredDeleteObject == nil) then + triggeredDeleteObject = false +end +function trigger(objectToChange) + if(triggeredDeleteObject == false) then + if(not level) then + print("No level found in Lua!") + return + end + if(not physics) then + print("No physics found in Lua!") + return + end + level:deleteObject(objectToChange) + triggeredDeleteObject = true + print("deleteObject") + end end diff --git a/Levels/scripts/deleteRandomObject.lua b/Levels/scripts/deleteRandomObject.lua index 25fbbc1..2f7db64 100644 --- a/Levels/scripts/deleteRandomObject.lua +++ b/Levels/scripts/deleteRandomObject.lua @@ -1,14 +1,20 @@ -function trigger(objectToChange) - if(not level) then - print("No level found in Lua!") - return - end - if(not physics) then - print("No physics found in Lua!") - return - end - a = level:getObjectCount() - rand = math.random(0, a - 1) - level:deleteObject(rand) - print("Triggered from Lua!") +if(triggeredDeleteRandomObject == nil) then + triggeredDeleteRandomObject = false +end +function trigger(objectToChange) + if(triggeredDeleteRandomObject == false) then + if(not level) then + print("No level found in Lua!") + return + end + if(not physics) then + print("No physics found in Lua!") + return + end + a = level:getObjectCount() + rand = math.random(0, a - 1) + level:deleteObject(rand) + triggeredDeleteRandomObject = true + print("deleteRandomObject") + end end diff --git a/trigger.cc b/trigger.cc index 4a701b5..cd3cfb8 100644 --- a/trigger.cc +++ b/trigger.cc @@ -11,7 +11,6 @@ Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* obje printf("L is NULL in trigger!\n"); } this->objectToChange = objectToChange; - triggered = false; } Trigger::Trigger(){ @@ -21,18 +20,14 @@ Trigger::~Trigger(){ } void Trigger::triggerUpdate(){ - if (!triggered){ if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { luaL_dofile(L, luaScript.c_str()); luabridge::getGlobal(L, "trigger")(objectToChange); - triggered = true; } else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { luaL_dofile(L, luaScript.c_str()); luabridge::getGlobal(L, "trigger")(objectToChange); - triggered = true; } - } } bool Trigger::deleteNotification(int deletedObjectIndex){ diff --git a/trigger.hh b/trigger.hh index 45d8804..669c2c8 100644 --- a/trigger.hh +++ b/trigger.hh @@ -25,7 +25,6 @@ class Trigger { bool isBigger; Object* object; std::string luaScript; - bool triggered; lua_State* L; int objectToChange; };