Page 1 of 3

STI help

Posted: Sat Apr 19, 2014 1:01 pm
by superboySR
So I'm trying to load a map in STI. I created a map.lua file and at the top I wrote local sti = require "amin.sti" because my init.lua file is located in sti and sti is located in the folder amin. But it is still not working? Help :cry:

Re: STI help

Posted: Sat Apr 19, 2014 2:08 pm
by SneakySnake
You need to understand what gets executed and when.

main.lua is the only file that gets executed by LÖVE (besides conf.lua).
If you want map.lua to run, you must require() it (or execute it in some other way).

This brings us to the next point.
Let's say you now require "map" at the top of main.lua.
The love.load() defined in map.lua will not get executed.
Why?
In Lua, if you define a function with the same name as an existing function, the new definition will override the existing function.
In this case, love.load() defined in main.lua will override love.load() defined in map.lua.
So how would you define a setup function for the map module?
One solution would be to create a map.load() function that you would explicitly call when you want to initialize the map module.

Re: STI help

Posted: Sat Apr 19, 2014 9:46 pm
by superboySR
SneakySnake wrote:You need to understand what gets executed and when.

main.lua is the only file that gets executed by LÖVE (besides conf.lua).
If you want map.lua to run, you must require() it (or execute it in some other way).

This brings us to the next point.
Let's say you now require "map" at the top of main.lua.
The love.load() defined in map.lua will not get executed.
Why?
In Lua, if you define a function with the same name as an existing function, the new definition will override the existing function.
In this case, love.load() defined in main.lua will override love.load() defined in map.lua.
So how would you define a setup function for the map module?
One solution would be to create a map.load() function that you would explicitly call when you want to initialize the map module.
Thanks for that! But unfortunately I changed the map.lua love.load() into map.load() and I did require "map" in main.lua and it has the same problem :crazy:

Re: STI help

Posted: Sun Apr 20, 2014 3:04 pm
by Karai17
You need to call map.load() from inside love.load().

Code: Select all

local map = require "map"

function love.load()
    map.load()
end

Re: STI help

Posted: Sun Apr 20, 2014 9:44 pm
by superboySR
Karai17 wrote:You need to call map.load() from inside love.load().

Code: Select all

local map = require "map"

function love.load()
    map.load()
end
I did that but same error. ;( :cry:

Re: STI help

Posted: Mon Apr 21, 2014 5:03 pm
by superboySR
It seems my code still isn't working :cry: Can someone post an example? That would mean a lot :nyu:

Re: STI help

Posted: Mon Apr 21, 2014 9:08 pm
by Karai17
I moved your stuff out of map.lua because it served no purpose there. STI now loads, but you didn't include a map file with it so you will need to put that back in.

Re: STI help

Posted: Mon Apr 21, 2014 11:03 pm
by superboySR
Karai17 wrote:I moved your stuff out of map.lua because it served no purpose there. STI now loads, but you didn't include a map file with it so you will need to put that back in.
Thanks! :awesome: I will carefully look at how it loads :ultrahappy:

Re: STI help

Posted: Tue Apr 22, 2014 2:45 pm
by superboySR
Karai17 wrote:I moved your stuff out of map.lua because it served no purpose there. STI now loads, but you didn't include a map file with it so you will need to put that back in.
I'm not sure why it says file not found because it is located in amin/mapsa/map01 ? I think it has something to do with that it says this: file not found: amin/mapsa/map01.lua.

Re: STI help

Posted: Tue Apr 22, 2014 6:12 pm
by Karai17
Because that file doesn't exist.