RetroBASIC
Retrogamecoding(.org) => EGSL => Topic started by: Osgeld on August 24, 2013, 08:10:43 PM
-
for example, this
player =
{
walkL = loadimage("walk.png"),
kickL = loadimage("kick.png"),
punchL = loadimage("punch.png"),
walkR = fliphorizontal(player.walkL),
kickR = fliphorizontal(player.kickL),
punchR = fliphorizontal(player.punchL),
}
fails with
game.lua:16: attempt to index global 'player' (a nil value)
but this
player ={}
player.walkL = loadimage("walk.png")
player.kickL = loadimage("kick.png")
player.punchL = loadimage("punch.png")
player.walkR = fliphorizontal(player.walkL)
player.kickR = fliphorizontal(player.kickL)
player.punchR = fliphorizontal(player.punchL)
works fine
weird
-
In the first example you're trying to access a value of a player table before the table is created. It looks like player.walkL is not ready when you're trying to call it to set player.walkR, probably because they are part of a single statement. In the second example each line is a separate statement, so player.walkL is ready to use when you're trying to set player.walkR.
-
yep your probably right
tables can be a double sided sword, one hand they help organize, on the other hand you get stuff like this floating around your code
baddies[drawOrder[d][2]][1]