Trying to animate some sprites and I have this:
Code: Select all
function animateSprites(sprite,x,y,frameSpeed) --Starting on a random frame won't work
dt = lt.getDelta()
currentFrame = currentFrame+ frameSpeed*dt
if currentFrame > #sprite then
currentFrame = 1
end
lg.draw(spriteSheet,sprite[math.floor(currentFrame)],x,y,0,zoom)
end
The problem there is I don't know how. I've done it in the past using copied code, but there are two things:
1: I want to LEARN how to do it
2: I want the code to be in the main file NOT a resource script or library
Now to the error:
From what I can find people state declare a variable table and write some code:
Code: Select all
t = {}
function t:func(x, y)
self.x = x
self.y = y
end
t:func(1, 1)
print(t.x) -- 1
Which I guess would work or some variation of it would work, but when I use these examples I always get the error:
attempt to index global "tablename" (a nil value)
Well, yes... the table is NIL, but it's declared and this happens even if I don't call the function. Just goes off.
I know the post is rambley and I've not really asked a specific question, but please try to post constructive and helpful feedback? I'm kinda stuck and don't want to copy-pasta.
EDIT: Turns out using OOP in my project was counter to how I had my project layed out in the first place. Although I did figure out my crashing issue there is no way OOP in this manner is going to work for my current build. Leaving here for posterity(?) but marking as solved as I no longer need help with it.