Lua script works now, worked around the bug by saving the name as a std::string.
This commit is contained in:
parent
fe58023458
commit
d936d1f269
@ -1,9 +1,8 @@
|
|||||||
function trigger(objectToChange)
|
function trigger(objectToChange)
|
||||||
print("Hello from Lua!")
|
if(not this_level) then
|
||||||
--if(not this_level) then
|
|
||||||
print("No level found!")
|
print("No level found!")
|
||||||
return
|
return
|
||||||
--end
|
end
|
||||||
a = this_level:getObjectCount()
|
a = this_level:getObjectCount()
|
||||||
rand = math.random(0, a - 1)
|
rand = math.random(0, a - 1)
|
||||||
this_level:deleteObject(rand)
|
this_level:deleteObject(rand)
|
||||||
|
3
level.cc
3
level.cc
@ -376,7 +376,7 @@ void Level::load() {
|
|||||||
}
|
}
|
||||||
if (object != 0) {
|
if (object != 0) {
|
||||||
if (objectToChange != 0) {
|
if (objectToChange != 0) {
|
||||||
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange, this);
|
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange);
|
||||||
triggers.push_back(trigger);
|
triggers.push_back(trigger);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -484,7 +484,6 @@ std::vector<Object*>* Level::getObjects() {
|
|||||||
|
|
||||||
void Level::deleteObject(int objectIndex){
|
void Level::deleteObject(int objectIndex){
|
||||||
objects.erase(objects.begin() + objectIndex);
|
objects.erase(objects.begin() + objectIndex);
|
||||||
printf("Deleting an object.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Level::getObjectCount(){
|
int Level::getObjectCount(){
|
||||||
|
45
trigger.cc
45
trigger.cc
@ -1,17 +1,11 @@
|
|||||||
#include "trigger.hh"
|
#include "trigger.hh"
|
||||||
#include "level.hh"
|
|
||||||
|
|
||||||
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, Level* level) {
|
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange) {
|
||||||
this->position=position;
|
this->position=position;
|
||||||
this->distance=distance;
|
this->distance=distance;
|
||||||
this->isBigger=isBigger;
|
this->isBigger=isBigger;
|
||||||
this->object=object;
|
this->object=object;
|
||||||
this->triggerLuaScript=("../Levels/scripts/" + luaScript + ".lua").c_str();
|
this->luaScript="../Levels/scripts/" + luaScript + ".lua";
|
||||||
printf("Hallo\n");
|
|
||||||
printf(this->triggerLuaScript);
|
|
||||||
printf("Hallo\n");
|
|
||||||
printf("\n");
|
|
||||||
this->level = level;
|
|
||||||
this->L = L;
|
this->L = L;
|
||||||
if(L == nullptr){
|
if(L == nullptr){
|
||||||
printf("L is NULL in trigger!\n");
|
printf("L is NULL in trigger!\n");
|
||||||
@ -29,41 +23,14 @@ Trigger::~Trigger(){
|
|||||||
void Trigger::triggerUpdate(){
|
void Trigger::triggerUpdate(){
|
||||||
if (!triggered){
|
if (!triggered){
|
||||||
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
||||||
printf(triggerLuaScript);
|
luaL_dofile(L, luaScript.c_str());
|
||||||
printf("\n");
|
luabridge::getGlobal(L, "trigger")(objectToChange);
|
||||||
printf(triggerLuaScript);
|
|
||||||
printf("\nTriggering\n");
|
|
||||||
//luaL_dofile(L, luaScript);
|
|
||||||
//luabridge::getGlobal(L, "trigger")(objectToChange);
|
|
||||||
triggered = true;
|
triggered = true;
|
||||||
}
|
}
|
||||||
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
||||||
printf(triggerLuaScript);
|
luaL_dofile(L, luaScript.c_str());
|
||||||
printf("\n");
|
luabridge::getGlobal(L, "trigger")(objectToChange);
|
||||||
printf(triggerLuaScript);
|
|
||||||
printf("\nTriggering\n");
|
|
||||||
//luaL_dofile(L, luaScript);
|
|
||||||
//luabridge::getGlobal(L, "trigger")(objectToChange);
|
|
||||||
triggered = true;
|
triggered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trigger::trigger_function_0(Level* level) {
|
|
||||||
if (!triggered) {
|
|
||||||
int rand = std::rand() % level->getObjects()->size();
|
|
||||||
level->getObjects()->erase(level->getObjects()->begin() + rand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trigger::trigger_function_1(Level* level) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trigger::trigger_function_2(Level* level) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trigger::trigger_function_3(Level* level) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Trigger::trigger_function_4(Level* level) {
|
|
||||||
}
|
|
||||||
|
10
trigger.hh
10
trigger.hh
@ -14,7 +14,7 @@ class Level;
|
|||||||
|
|
||||||
class Trigger {
|
class Trigger {
|
||||||
public:
|
public:
|
||||||
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, Level* level);
|
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange);
|
||||||
Trigger();
|
Trigger();
|
||||||
~Trigger();
|
~Trigger();
|
||||||
void triggerUpdate();
|
void triggerUpdate();
|
||||||
@ -23,16 +23,10 @@ class Trigger {
|
|||||||
float distance;
|
float distance;
|
||||||
bool isBigger;
|
bool isBigger;
|
||||||
Object* object;
|
Object* object;
|
||||||
const char* triggerLuaScript;
|
std::string luaScript;
|
||||||
Level* level;
|
|
||||||
bool triggered;
|
bool triggered;
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
int objectToChange;
|
int objectToChange;
|
||||||
void trigger_function_0(Level* level);
|
|
||||||
void trigger_function_1(Level* level);
|
|
||||||
void trigger_function_2(Level* level);
|
|
||||||
void trigger_function_3(Level* level);
|
|
||||||
void trigger_function_4(Level* level);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user