From 0e550e52c6fff5f7816eb86e335f177cb9f6e07f Mon Sep 17 00:00:00 2001 From: Steffen Date: Sun, 15 Feb 2015 16:11:31 +0100 Subject: [PATCH] Got scripts to work as intended, had to use an ugly hack for it. --- data/levels/Level1.xml | 15 +++++++++++++++ data/levels/scripts/Template.lua | 11 +++++++---- data/levels/scripts/global.lua | 3 +++ data/levels/scripts/openFirstDoor.lua | 13 ++++++++----- data/levels/scripts/openFirstDoorUndo.lua | 13 ++++++++----- 5 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 data/levels/scripts/global.lua diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index 3b2854f..d66ef6e 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -1337,6 +1337,21 @@ 133 0 + + openFirstDoorUndo + 159.5 + 22 + 17.5 + - + - + 0.2 + false + 0 + openFirstDoorUndo + 1 + 133 + 0 + diff --git a/data/levels/scripts/Template.lua b/data/levels/scripts/Template.lua index ef29605..df848f8 100644 --- a/data/levels/scripts/Template.lua +++ b/data/levels/scripts/Template.lua @@ -1,8 +1,11 @@ -if(triggeredSCRIPTNAME == nil) then - triggeredSCRIPTNAME = false +--I have no idea why this hack from the internet works, but it does... +package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path +local global = require( "global" ) +if(global.triggeredSCRIPTNAME == nil) then + global.triggeredSCRIPTNAME = false end function trigger(objectToChange) - if(triggeredSCRIPTNAME == false) then + if(global.triggeredSCRIPTNAME == false) then if(not level) then print("No level found in Lua!") return @@ -10,7 +13,7 @@ function trigger(objectToChange) --enter the scripts code here and replace all occurences of SCRIPTNAME with the name of the script. - triggeredSCRIPTNAME = true + global.triggeredSCRIPTNAME = true print("SCRIPTNAME") end end diff --git a/data/levels/scripts/global.lua b/data/levels/scripts/global.lua new file mode 100644 index 0000000..c68517d --- /dev/null +++ b/data/levels/scripts/global.lua @@ -0,0 +1,3 @@ +--global variable space +local M = {} +return M diff --git a/data/levels/scripts/openFirstDoor.lua b/data/levels/scripts/openFirstDoor.lua index eb762f2..b36148e 100644 --- a/data/levels/scripts/openFirstDoor.lua +++ b/data/levels/scripts/openFirstDoor.lua @@ -1,8 +1,11 @@ -if(triggereOpenFirstDoor == nil) then - triggereOpenFirstDoor = false +--I have no idea why this hack from the internet works, but it does... +package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path +local global = require( "global" ) +if(global.triggeredOpenFirstDoor == nil) then + global.triggeredOpenFirstDoor = false end function trigger(objectToChange) - if(triggereOpenFirstDoor == false) then + if(global.triggeredOpenFirstDoor == false) then if(not level) then print("No level found in Lua!") return @@ -14,9 +17,9 @@ function trigger(objectToChange) local zPos = 17.5 level:moveObject(objectToChange, strength, xPos, yPos, zPos) - triggeredOpenFirstDoorUndo = false + global.triggeredOpenFirstDoorUndo = false - triggereOpenFirstDoor = true + global.triggeredOpenFirstDoor = true print("openFirstDoor") end end diff --git a/data/levels/scripts/openFirstDoorUndo.lua b/data/levels/scripts/openFirstDoorUndo.lua index 2beed71..6fd9de2 100644 --- a/data/levels/scripts/openFirstDoorUndo.lua +++ b/data/levels/scripts/openFirstDoorUndo.lua @@ -1,8 +1,11 @@ -if(triggereOpenFirstDoorUndo == nil) then - triggereOpenFirstDoorUndo = false +--I have no idea why this hack from the internet works, but it does... +package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path +local global = require( "global" ) +if(global.triggeredOpenFirstDoorUndo == nil) then + global.triggeredOpenFirstDoorUndo = true end function trigger(objectToChange) - if(triggereOpenFirstDoorUndo == false) then + if(global.triggeredOpenFirstDoorUndo == false) then if(not level) then print("No level found in Lua!") return @@ -14,9 +17,9 @@ function trigger(objectToChange) local zPos = 17.5 level:moveObject(objectToChange, strength, xPos, yPos, zPos) - triggeredOpenFirstDoor = false + global.triggeredOpenFirstDoor = false - triggereOpenFirstDoorUndo = true + global.triggeredOpenFirstDoorUndo = true print("openFirstDoorUndo") end end