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