REQUESTING HELP
Posted: Thu Sep 14, 2023 2:39 pm
Hi! I'm kinda new and I really need help to find out what's wrong with my coded, can someone help me please?
function love.load()
totalStars = 1000
stars = {}
for i = 0, totalStars, 1 do
stars [1] = {
r = love.math.random(0,255) / 255,
g = love.math.random(0,255) / 255,
b = love.math.random(0,255) / 255,
a = love.math.random(0,255) / 255,
x = love.math.random(0, love.graphics.getWidth()),
y = love.math.random(0, love.graphics.getHeight()),
radio = love.math.random(1,5)
}
end
end
function love.draw()
for i = 0, totalStars, 1 do
love.graphics.setColor(
stars.r,
stars.g,
stars.b,
stars.a
)
love.graphics.circle(
"fill",
stars.x,
stars.y,
stars.radio)
end
end
function love.update(dt)
stars[100].x = stars[100].x + 1
stars[100].y = stars[100].y + 1
if stars[101].x > love.graphics.getWidth() then
stars[101].x = 0
end
if stars[101].y > love.graphics.getHeight() then
stars[101].y = 0
end
end
And this is what appears to me when I run it:
Error
main.lua:39: attempt to index a nil value
Traceback
[love "callbacks.lua"]:228: in function 'handler'
main.lua:39: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
function love.load()
totalStars = 1000
stars = {}
for i = 0, totalStars, 1 do
stars [1] = {
r = love.math.random(0,255) / 255,
g = love.math.random(0,255) / 255,
b = love.math.random(0,255) / 255,
a = love.math.random(0,255) / 255,
x = love.math.random(0, love.graphics.getWidth()),
y = love.math.random(0, love.graphics.getHeight()),
radio = love.math.random(1,5)
}
end
end
function love.draw()
for i = 0, totalStars, 1 do
love.graphics.setColor(
stars.r,
stars.g,
stars.b,
stars.a
)
love.graphics.circle(
"fill",
stars.x,
stars.y,
stars.radio)
end
end
function love.update(dt)
stars[100].x = stars[100].x + 1
stars[100].y = stars[100].y + 1
if stars[101].x > love.graphics.getWidth() then
stars[101].x = 0
end
if stars[101].y > love.graphics.getHeight() then
stars[101].y = 0
end
end
And this is what appears to me when I run it:
Error
main.lua:39: attempt to index a nil value
Traceback
[love "callbacks.lua"]:228: in function 'handler'
main.lua:39: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'