Page 1 of 2

[solved] Animation - For Limit Must Be A Number

Posted: Fri Nov 10, 2023 7:17 pm
by Todespreis
Hey there! I'm trying to animate my sprites without image:getHeight or Width. So here is my code for it:

Code: Select all

function newAnimation(image, width, height, duration)
    local animation = {
        spriteSheet = image,
        quads = {}
    }

    for y = 0, imageHeight, height do
        for x = 0, imageWidth, width do
            table.insert(animation.quads, love.graphics.newQuad(0, 0, 8, 16, 512, 512))
        end
    end

    animation.duration = duration or 1
    animation.currentTime = 0

    return animation
end
The Error is the one of the Topic's name. Any ideas how to solve that?

Re: Animation - For Limit Must Be A Number

Posted: Fri Nov 10, 2023 8:06 pm
by darkfrei
What is imageHeight and imageWidth? Where it was defined?

Re: Animation - For Limit Must Be A Number

Posted: Sun Nov 12, 2023 8:43 pm
by Todespreis
Hey darkfrei! Thank you very much for the fast reply. That's a good question, i did'nt define it anywhere. :ultraglee: I got the code from chat gpt and asked it to remove the image:getHeight function, because the code got pretty slow suddenly.
I saw, that you animate your games with separated sprites. So i stole your code for it, sliced my spritesheet and will try that out the days.
Thank you again and have a nice week!

Re: Animation - For Limit Must Be A Number

Posted: Sun Nov 12, 2023 10:57 pm
by zorg
Todespreis wrote: Sun Nov 12, 2023 8:43 pm Hey darkfrei! Thank you very much for the fast reply. That's a good question, i did'nt define it anywhere. :ultraglee: I got the code from chat gpt and asked it to remove the image:getHeight function, because the code got pretty slow suddenly.
I saw, that you animate your games with separated sprites. So i stole your code for it, sliced my spritesheet and will try that out the days.
Thank you again and have a nice week!
Consider learning how to code and not rely on an unreliable machine learning tool, at the very least, without sufficient prior knowledge.

Re: Animation - For Limit Must Be A Number

Posted: Sun Nov 19, 2023 11:25 am
by Todespreis
@zorg Why are you that grumpy? I'm still learning and due to not having anyone, who is familiar with Lua coding, besides of this forum, i only can ask an AI for help. So i think, it's a valid way to learn stuff.

@darkfrei Hey there again! Your code worked, thank you again for it! Now i only have to figure out, how to put everything into different loops for walking, running, jumping, attacking... And I'm almost done! :ultrahappy: Just joking! :cry: Can you explain, how it works? I see, that it is working, but i don't understand how and why

Code: Select all

love.update=function (dt)

    FrameTimer = FrameTimer + dt
    if FrameTimer >= FrameDuration then
        FrameTimer = 0
        FrameIndex = FrameIndex + 1
        if FrameIndex > #Frames then
            FrameIndex = 1
        end
        FrameEnabled = Frames[FrameIndex]
    end
So the timer is counting, i do understand that. It's just a variable, that is counting. But how does the FrameDuration work? It's not a function, it is a variable, too. So how does the interpreter know, what that means? Okay, the FrameTimer gets set to zero, when the FrameDuration is over, i understand that, too. And i think, i understand, how the FrameIndex works. So the FrameDuration is just a numerical value? What does the "#Frames" mean? Does the "#" mean "ignore the first character"? So the value of the frame?

Re: Animation - For Limit Must Be A Number

Posted: Sun Nov 19, 2023 2:17 pm
by MrFariator
In lua, # is the length operator. It returns the length of a string or table. I recommend looking up what the reserved keywords and operators are. PIL (the manual I linked) is a good resource to read through if you want to learn lua.

Re: Animation - For Limit Must Be A Number

Posted: Sun Nov 19, 2023 4:19 pm
by zorg
Todespreis wrote: Sun Nov 19, 2023 11:25 am @zorg Why are you that grumpy? I'm still learning and due to not having anyone, who is familiar with Lua coding, besides of this forum, i only can ask an AI for help. So i think, it's a valid way to learn stuff.
I'm not grumpy, i told you a statement i believed to be actually good for you.

That said, you're the n+1th person doing this, thinking you're learning something with trusting a chatbot when you don't have the ability to discern whether it gives you actual workable code or not; that would come with experience, and at that point, you'd not use it at all anyway, considering you'd know how to code by then.

Also, you'll have way more stuff to un-learn like this, whenever the chatbot says something stupid and you believe it.

Also, consider learning by yourself, there's tons of materials that actually are decent:
https://sheepolution.com/learn
https://www.lua.org/pil/contents.html (you'll need to figure out what changed between 5.0 and 5.1 though)
And/or by just reading the wiki.

Finally, i didnt have anyone either when i learned lua by myself, although the Discord server that does exist can be helpful if you want to ask questions while trying to code.

Re: Animation - For Limit Must Be A Number

Posted: Tue Nov 21, 2023 12:55 pm
by Todespreis
@MrFariator oh, thank you for the link! The reference manual is written by Roberto Jerusalimschy - the creator of Lua. I have a book written by him - Programming in Lua. But it is somehow harder to understand, than C programming.

@ i see, where you are coming from, but considering a learning resource as bad, just because it was not available at the time, you have learned it, is wrong in my opinion. Ofcourse you are right. As long as i don't understand, what is wrong and what not, i have to believe everything. But i think, it's a good starting point to get any idea about the language and the possible solutions. Oh and scheepolution - that's a good starting point for a beginner. Thank you for that!

Re: [solved] Animation - For Limit Must Be A Number

Posted: Fri Nov 24, 2023 7:29 am
by zorg
I don't consider ChatGPT bad because it's "newfangled", as you might want to imply; i consider it bad because it's not reliable.
I would consider a badly written manuscript full of errors documenting lua just as bad.

That said, i do hope you'll find at least the sheepo tutorials helpful.

Re: [solved] Animation - For Limit Must Be A Number

Posted: Tue Nov 28, 2023 6:23 pm
by milon
zorg wrote: Fri Nov 24, 2023 7:29 am I don't consider ChatGPT bad because it's "newfangled", as you might want to imply; i consider it bad because it's not reliable.
I would consider a badly written manuscript full of errors documenting lua just as bad.
Right. The thing people seem to forget about ChatGPT et al is that it's not actually AI. Calling it AI was merely a (brilliant) marketing move. These algorithms are just really really good at predicting "what comes next" for a given (large!) set of inputs that they've been explicitly trained on. This training typically takes the form of text & code grabbed from the web - usually without the author's permission or knowledge. There is absolutely no guarantee that they're accurate. And they break down in epic fashion when confronted with unknown situations. It's risky to use them as interactive tutorials, but I guess they can be used it to get started. Just don't assume they'll teach best practices or anything. ;)