Page 1 of 1

I've been trying to code in my.main game scene and it just gives me an error when I press my start button

Posted: Sat Apr 23, 2022 9:02 pm
by Jolt
here's the error
Error

main.lua:20: attempt to index global 'Scene' (a nil value)


Traceback

main.lua:20: in function <main.lua:18>
[C]: in function 'xpcall'

My code is:

Code: Select all

function love.load()
playstarter = love.graphics.newImage("TitleAssets/startplay.png")
time = 0
end

function love.draw()
love.graphics.setColor(0, 1, 0.3)
love.graphics.circle("fill", 416, 300, 80+math.sin(time)*10)
love.graphics.setColor(1, 1, 1)
love.graphics.scale(0.55, 0.55)
love.graphics.draw(playstarter, 560, 315+math.sin(time)*8)
end

function love.update(dt)
time = time + dt
end

function love.touchpressed(id, x, y)
Scene1 = ("Scenes/Scene1") <-- error here
if Scene.load then Scene:touchpressed(id,x, y) end
end
Can somebody please explain to me what is going on and give me some better code or help to fix the code right there

Re: I've been trying to code in my.main game scene and it just gives me an error when I press my start button

Posted: Sun Apr 24, 2022 12:00 am
by BrotSagtMist
What is that even supposed to do? Explain to US what is going on.
Whenever the touchscreen is used Scene1 becomes a string? Why?
Then if "Scene" has an entry 'load' do something.
There is no 'Scene' so that if case raises the error.

Re: I've been trying to code in my.main game scene and it just gives me an error when I press my start button

Posted: Sun Apr 24, 2022 1:39 am
by Jolt
I was trying to do scenes but i went nvm I'm getting and figuring out a library for scenes

Re: I've been trying to code in my.main game scene and it just gives me an error when I press my start button

Posted: Tue Apr 26, 2022 11:46 pm
by Gunroar:Cannon()
Jolt wrote: Sat Apr 23, 2022 9:02 pm function love.touchpressed(id, x, y)
Scene1 = ("Scenes/Scene1") <-- error here
if Scene.load then Scene:touchpressed(id,x, y) end
end[/code]

Can somebody please explain to me what is going on and give me some better code or help to fix the code right there
Maybe you meant

Code: Select all

Scene1 = require("Scenes/Scene1") --you also named it Scene instead of Scene1
But that's only if you have a lua file called Scene1 in a folder called Scenes.