function _init() chosen = 1 mode = "menu" level = 1 selx = 64 sely = 64 sinceshot = 0 shotx = 64 shoty = 64 cls() end function _update() cls() if mode=="menu" then if chosen==16 then print("no-scope mode?! 16 ⬆️/⬇️/🅾️", 1, 1, 11) print("(x, y) will be provided instead", 1, 10, 7) print("warning: extremely difficult!", 1, 19, 8) else if chosen>10 then print("novelty crosshair " .. tostr(chosen) .. " ⬆️/⬇️/🅾️", 1, 1, 10) else print("crosshair " .. tostr(chosen) .. " ⬆️/⬇️/🅾️", 1, 1, 6) end end spr((chosen - 1), 60, 60) if btnp(🅾️) then mode = "game" end if btnp(⬆️) then chosen += 1 end if btnp(⬇️) then chosen -= 1 end if chosen>16 then chosen = 16 end if chosen<1 then chosen = 1 end else if mode=="game" then rectfill(o, o, 128, 128, 12) spr(chosen-1, selx, sely) if sinceshot == 0 then spr(64, shotx, shoty, 2, 2) else if sinceshot == 1 then spr(66, shotx, shoty, 2, 2) else if sinceshot == 2 then spr(68, shotx, shoty, 2, 2) else if sinceshot == 3 then spr(70, shotx, shoty, 2, 2) else if sinceshot == 4 then spr(72, shotx, shoty, 2, 2) else if sinceshot == 5 then spr(74, shotx, shoty, 2, 2) end if btn(⬆️) then sely -= 1 end if btn(⬇️) then sely += 1 end if btn(➡️) then selx += 1 end if btn(⬅️) then selx -= 1 end if (btn(❎) and sinceshot>5) then sinceshot=0 shotx = selx shoty = sely else sinceshot += 1 end end end end |
Hi! When I try to run this code, I get errors saying I didn't close IF statements that I did close...
(namely line 41)
2
Lua's "else if" statement is one word, "elseif". I ran into the same issue several times :)
What @yaky said. In lua syntax, you can do either of these:
-- the lua elseif keyword way if blah then ... elseif foo then ... end -- same as what you had, but with a newline after else to clarify how it's parsed if blah then ... else if foo then ... end end |
There are times when the second version is useful because you want to do a little prep work before, or cleanup after, you do the secondary if block.
[Please log in to post a comment]