[solved] Animation - For Limit Must Be A Number

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Todespreis
Prole
Posts: 34
Joined: Sat Apr 01, 2023 9:30 pm

[solved] Animation - For Limit Must Be A Number

Post 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?
Last edited by Todespreis on Tue Nov 21, 2023 12:56 pm, edited 1 time in total.
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: Animation - For Limit Must Be A Number

Post by darkfrei »

What is imageHeight and imageWidth? Where it was defined?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Todespreis
Prole
Posts: 34
Joined: Sat Apr 01, 2023 9:30 pm

Re: Animation - For Limit Must Be A Number

Post 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!
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Animation - For Limit Must Be A Number

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Todespreis
Prole
Posts: 34
Joined: Sat Apr 01, 2023 9:30 pm

Re: Animation - For Limit Must Be A Number

Post 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?
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: Animation - For Limit Must Be A Number

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Animation - For Limit Must Be A Number

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Todespreis
Prole
Posts: 34
Joined: Sat Apr 01, 2023 9:30 pm

Re: Animation - For Limit Must Be A Number

Post 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!
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

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

Post 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. ;)
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Yolwoocle and 68 guests