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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Jolt
Prole
Posts: 2
Joined: Sat Apr 23, 2022 8:52 pm

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

Post 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
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

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

Post 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.
obey
Jolt
Prole
Posts: 2
Joined: Sat Apr 23, 2022 8:52 pm

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

Post by Jolt »

I was trying to do scenes but i went nvm I'm getting and figuring out a library for scenes
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

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

Post 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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: lysandre and 4 guests