Running another main.lua from inside a game

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
User avatar
Outlaw11A
Prole
Posts: 4
Joined: Tue Mar 19, 2013 9:18 am

Running another main.lua from inside a game

Post by Outlaw11A »

Hi all!

I have been creating a game, and have run into a problem.

I have created separate scenes, that are separate from each other. I want it so that, when something is clicked in one scene, it loads another scene.

The folder structure is as so:

menu -

/textures/
/sounds/
/main.lua

intro-1 -

/textures/
/main.lua

I want it so that when a button is clicked in the menu program, it runs the intro-1 program, but can't seem to get it to run another file from the program.

Any suggestions? I need help!

If you need clarification on anything, I can provide it.

Thanks

Outlaw11A
LEGENDCRAFT MINECRAFT SERVER: play.legendcraft.beastnode.net
http://legendcraft.beastnode.net/
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Running another main.lua from inside a game

Post by micha »

What you are looking for, is called game state. Have a variable "state" of type string where you save, which scene you are in. In love.update and love.draw you first check which state you are in and run the corresponding function
Example:

Code: Select all

function love.load()
  state = 'intro'
end

Code: Select all

function love.update(dt)
  if state = 'intro' then
    intro.update(dt)
  elseif state = 'firstScene' then
    scene1.update(dt)
  elseif state = 'gameover' then
    gameoverscreen.update(dt)
  end
end
And the same in love.draw.
User avatar
Outlaw11A
Prole
Posts: 4
Joined: Tue Mar 19, 2013 9:18 am

Re: Running another main.lua from inside a game

Post by Outlaw11A »

micha wrote:What you are looking for, is called game state. Have a variable "state" of type string where you save, which scene you are in. In love.update and love.draw you first check which state you are in and run the corresponding function
Example:

Code: Select all

function love.load()
  state = 'intro'
end

Code: Select all

function love.update(dt)
  if state = 'intro' then
    intro.update(dt)
  elseif state = 'firstScene' then
    scene1.update(dt)
  elseif state = 'gameover' then
    gameoverscreen.update(dt)
  end
end
And the same in love.draw.

Thats sounds like exactly what I am looking for. Will give this a go!
LEGENDCRAFT MINECRAFT SERVER: play.legendcraft.beastnode.net
http://legendcraft.beastnode.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests