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 .
Navi
Prole
Posts: 1 Joined: Wed May 01, 2024 12:06 am
Post
by Navi » Wed May 01, 2024 12:11 am
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!
BrotSagtMist
Party member
Posts: 659 Joined: Fri Aug 06, 2021 10:30 pm
Post
by BrotSagtMist » Wed May 01, 2024 1:26 am
" 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
Post
by TyperWithS » Wed May 01, 2024 8:17 pm
You want to rewrite: "squarex = squarex + square * dt"
To: "squarex = squarex + square.squarespeed * dt"
Azzla
Prole
Posts: 43 Joined: Sun Mar 29, 2020 2:23 am
Post
by Azzla » Wed May 01, 2024 8:24 pm
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.
Users browsing this forum: Bing [Bot] and 5 guests