Discord
Login
Community
DARK THEME

Multiple Files

How do i use multiple files? Like the main file and a file called cutscene and run a fuction from cutscene from main? i tried and it didn't work

Scene = class
  constructor = function( parent )
    this.parent = parent
    this.text = ""
    this.return = 0
  end
  
  draw = function()
    screen.clear()
    screen.drawText( " Press SPACE ", 0, 40, 40, "orange")
    screen.drawText( this.text, 0, 0, 30, "red")
  end
  
  update = function()
    if keyboard.press.SPACE then 
      this.parent.setCurrent( this.return )
    end
  end
  
end

Game = class
  constructor = function()
    current = 0
  end

  draw = function()
    if current then current.draw() end
  end  
  
  update = function()
    if current then current.update() end
  end
  
  setCurrent = function( scene )
    this.current = scene
  end
end

init = function()
  game = new Game()
  scene1 = new Scene( game )
  scene2 = new Scene( game )
  game.setCurrent( scene1 )
  scene1.text = " Scene 1"
  scene2.text = " Cut scene "
  scene1.return = scene2
  scene2.return = scene1
end

update = function()
  game.update()
end

draw = function()
  game.draw()
end

Huh?

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community