Page 1 of 1

'=' expected near 'if' problem

Posted: Wed Sep 28, 2016 11:34 am
by PlumberGraduate
So, I tried to make a switch palace, and found this script from the official PGE wiki, so it probably should work, but it doesn't. I'm just getting this error: '=' expected near 'if'. Is it a bug? I can't find any errors. :x

The script

Code: Select all

local myGlobalData = Data(Data.DATA_WORLD, "switchPalace")
 
if myGlobalData == nil then
    myGlobalData:set("exampleGlobalSwitch", tostring(1))
	myGlobalData:save()
end
 
function onEvent(eventname)
    if eventname == "globalBarrierKill" then
        myGlobalData:set("exampleGlobalSwitch", tostring(0))
        myGlobalData:save()
    end
end
 
local ranInitialCheck = false;
local barrierData = myGlobalData:get("exampleGlobalSwitch");
 
function onLoop()
    if ranInitialCheck == false then
        if barrierData = tostring(0) then
            triggerEvent("globalBarrierKill")
        end
    ranInitialCheck = true;
    end
end

Re: '=' expected near 'if' problem

Posted: Wed Sep 28, 2016 11:59 am
by Waddle
The error message should specify in what line the error occurs, which might help you find the error.

EDIT: nvm, got it. In the last few lines of the code you're saying "if barrierData = tostring(0) then" whereas it should be "if barrierData == tostring(0) then". That might solve the problem. Also function onLoop() is effectively a worse function onTick() so I recommend you switch those too.

Re: '=' expected near 'if' problem

Posted: Wed Sep 28, 2016 12:38 pm
by PlumberGraduate
The error still occurs even though I fixed those two errors. And sorry for not specifying on what line the error happens. It happens in the third line. Also, the LunaWorld.lua also contains "smb3card = loadAPI("smb3goalcard");", but I don't think it matters.