diff --git a/Levels/ObjectSetups/Level1.xml b/Levels/ObjectSetups/Level1.xml
index 3a9b57f..5626fcc 100644
--- a/Levels/ObjectSetups/Level1.xml
+++ b/Levels/ObjectSetups/Level1.xml
@@ -20,7 +20,10 @@
3.0
false
0
- 0
+ deleteRandomObject
+ 1
+ 5
+ 0
deleteRandomObjectAtTorch
@@ -32,7 +35,10 @@
2.0
false
0
- 0
+ deleteRandomObject
+ 1
+ 5
+ 0
@@ -58,7 +64,10 @@
1.0
false
0
- -
+ -
+ -
+ -
+ -
@@ -84,7 +93,10 @@
1.0
false
0
- -
+ -
+ -
+ -
+ -
@@ -110,7 +122,10 @@
1.0
false
0
- -
+ -
+ -
+ -
+ -
@@ -136,7 +151,10 @@
1.0
false
0
- -
+ -
+ -
+ -
+ -
diff --git a/Levels/scripts/Level1/deleteRandomObject.lua b/Levels/scripts/Level1/deleteRandomObject.lua
deleted file mode 100644
index b24c44d..0000000
--- a/Levels/scripts/Level1/deleteRandomObject.lua
+++ /dev/null
@@ -1,10 +0,0 @@
-function trigger()
- print("Hello from Lua!")
- if(not Level) then
- print("No Level found!")
- return
- end
- --a = table.getn(Level.getObjects())
- --rand = math.random(0, table.getn(Level->getObjects()) - 1)
- --Level->getObjects()->erase(level->getObjects()->begin() + rand)
-end
diff --git a/Levels/scripts/deleteRandomObject.lua b/Levels/scripts/deleteRandomObject.lua
new file mode 100644
index 0000000..628eff0
--- /dev/null
+++ b/Levels/scripts/deleteRandomObject.lua
@@ -0,0 +1,11 @@
+function trigger(objectToChange)
+ print("Hello from Lua!")
+ --if(not this_level) then
+ print("No level found!")
+ return
+ --end
+ a = this_level:getObjectCount()
+ rand = math.random(0, a - 1)
+ this_level:deleteObject(rand)
+ print("Triggered from Lua!")
+end
diff --git a/converter/converter.cc b/converter/converter.cc
index 034d367..b296fcd 100644
--- a/converter/converter.cc
+++ b/converter/converter.cc
@@ -179,7 +179,10 @@ std::vector Converter::newComposition(int type, float posX, float posZ){
XMLElement* distance = doc->NewElement("distance");
XMLElement* isBiggerThan = doc->NewElement("isBiggerThan");
XMLElement* objectNum = doc->NewElement("objectNum");
- XMLElement* functionPointer = doc->NewElement("functionPointer");
+ XMLElement* luaScript = doc->NewElement("luaScript");
+ XMLElement* toChangeIdGreen = doc->NewElement("toChangeIdGreen");
+ XMLElement* toChangeIdBlue = doc->NewElement("toChangeIdBlue");
+ XMLElement* toChangeObjNum = doc->NewElement("toChangeObjNum");
name->SetText("-");
xPosition->SetText("0");
@@ -190,7 +193,10 @@ std::vector Converter::newComposition(int type, float posX, float posZ){
distance->SetText("1.0");
isBiggerThan->SetText("false");
objectNum->SetText("0");
- functionPointer->SetText("-");
+ luaScript->SetText("-");
+ toChangeIdGreen->SetText("-");
+ toChangeIdBlue->SetText("-");
+ toChangeObjNum->SetText("-");
trigger->InsertEndChild(name);
trigger->InsertEndChild(xPosition);
@@ -201,7 +207,10 @@ std::vector Converter::newComposition(int type, float posX, float posZ){
trigger->InsertEndChild(distance);
trigger->InsertEndChild(isBiggerThan);
trigger->InsertEndChild(objectNum);
- trigger->InsertEndChild(functionPointer);
+ trigger->InsertEndChild(luaScript);
+ trigger->InsertEndChild(toChangeIdGreen);
+ trigger->InsertEndChild(toChangeIdBlue);
+ trigger->InsertEndChild(toChangeObjNum);
std::vector ret = nextID;
nextID[1] += 1;
diff --git a/level.cc b/level.cc
index 1354d9e..115aa58 100644
--- a/level.cc
+++ b/level.cc
@@ -60,11 +60,12 @@ void Level::load() {
//Expose the class Level and its functions
luabridge::getGlobalNamespace(L)
.beginClass("Level")
- .addFunction("getObjects", &Level::getObjects)
+ .addFunction("deleteObject", &Level::deleteObject)
+ .addFunction("getObjectCount", &Level::getObjectCount)
.endClass();
//Push the level as a global variable
luabridge::push(L, this);
- lua_setglobal(L, "Level");
+ lua_setglobal(L, "this_level");
this->physics = Physics();
@@ -316,7 +317,7 @@ void Level::load() {
if (name.compare("-") != 0){
float xPos, yPos, zPos, distance;
bool isBigger;
- int idGreen, idBlue, objectNum, functionPointer_int;
+ int idGreen, idBlue, objectNum;
errorCheck(xmlTrigger->FirstChildElement("xPosition")->QueryFloatText(&xPos));
errorCheck(xmlTrigger->FirstChildElement("yPosition")->QueryFloatText(&yPos));
@@ -358,13 +359,32 @@ void Level::load() {
object = objects[objectIdentifiers[i][0]];
}
}
- errorCheck(xmlTrigger->FirstChildElement("functionPointer")->QueryIntText(&functionPointer_int));
+ const char* charLuaScript = xmlTrigger->FirstChildElement("luaScript")->GetText();
+ if(charLuaScript == NULL){
+ printf("XMLError: No Lua script found for a trigger.\n");
+ }
+ std::string luaScript = charLuaScript;
+
+ int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=0;
+ errorCheck(xmlTrigger->FirstChildElement("toChangeIdGreen")->QueryIntText(&toChangeIdGreen));
+ errorCheck(xmlTrigger->FirstChildElement("toChangeIdBlue")->QueryIntText(&toChangeIdBlue));
+ errorCheck(xmlTrigger->FirstChildElement("toChangeObjNum")->QueryIntText(&toChangeObjNum));
+ for (unsigned int i = 0; i* Level::getObjects() {
return &objects;
}
+
+void Level::deleteObject(int objectIndex){
+ objects.erase(objects.begin() + objectIndex);
+ printf("Deleting an object.\n");
+}
+
+int Level::getObjectCount(){
+ return objects.size();
+}
+
+
+
+
+
+
+
diff --git a/level.hh b/level.hh
index 00c0cca..ea48d0e 100644
--- a/level.hh
+++ b/level.hh
@@ -30,6 +30,8 @@ class Level {
glm::vec4 getFogColour();
void setSkydomeSize(float size);
std::vector