I always get this error code

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.
Post Reply
Navi
Prole
Posts: 1
Joined: Wed May 01, 2024 12:06 am

I always get this error code

Post by Navi »

So, when i try to do some movment i always get the error saying that squarex,squarey or squarespeed is equivalent to nil.

here my code:

Code: Select all

local square = {
    squarex = 0,
    squarey = 0 ,
    squarespeed = 100
}
function love.draw()
    love.graphics.setColor(0,0,1)
    love.graphics.rectangle('fill',square.squarex,square.squarey,50,60)
end
function love.update(dt)
    if love.keyboard.isDown('right') then
    squarex = squarex + square * dt
    end
end
If someone can help me out thanks! :D
User avatar
BrotSagtMist
Party member
Posts: 627
Joined: Fri Aug 06, 2021 10:30 pm

Re: I always get this error code

Post by BrotSagtMist »

" squarex = squarex + square * dt"
This line makes no sense whatsoever. Yure multiplying by a table.
obey
TyperWithS
Prole
Posts: 1
Joined: Wed May 01, 2024 8:15 pm

Re: I always get this error code

Post by TyperWithS »

You want to rewrite: "squarex = squarex + square * dt"
To: "squarex = squarex + square.squarespeed * dt"
User avatar
Azzla
Prole
Posts: 39
Joined: Sun Mar 29, 2020 2:23 am

Re: I always get this error code

Post by Azzla »

Change your update function to this:

Code: Select all

function love.update(dt)
    if love.keyboard.isDown('right') then
    	square.squarex = square.squarex + square.squarespeed * dt
    end
end
You need to access the properties of the table like you are in the draw function. Also consider the following:

Code: Select all

local square = {
    x = 0,
    y = 0,
    speed = 100
}
So that your code is easier to read and you don't have to redundantly type 'square' all the time.
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests