Page 1 of 1

Running another main.lua from inside a game

Posted: Tue Mar 19, 2013 9:25 am
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

Re: Running another main.lua from inside a game

Posted: Tue Mar 19, 2013 10:24 am
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.

Re: Running another main.lua from inside a game

Posted: Tue Mar 19, 2013 10:28 am
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!