STI help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
STI help
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
- Attachments
-
- love2dgame.love
- (22.49 KiB) Downloaded 138 times
"It's all about the game." - VGHS
- SneakySnake
- Citizen
- Posts: 94
- Joined: Fri May 31, 2013 2:01 pm
- Contact:
Re: STI help
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.
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.
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
Re: STI help
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 problemSneakySnake 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.
"It's all about the game." - VGHS
Re: STI help
You need to call map.load() from inside love.load().
Code: Select all
local map = require "map"
function love.load()
map.load()
end
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
Re: STI help
I did that but same error. ;(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
"It's all about the game." - VGHS
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
Re: STI help
It seems my code still isn't working Can someone post an example? That would mean a lot
"It's all about the game." - VGHS
Re: STI help
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.
- Attachments
-
- love2dgame.love
- (22.72 KiB) Downloaded 131 times
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
Re: STI help
Thanks! I will carefully look at how it loadsKarai17 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.
"It's all about the game." - VGHS
- superboySR
- Prole
- Posts: 24
- Joined: Mon Feb 24, 2014 8:54 pm
- Contact:
Re: STI help
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.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.
"It's all about the game." - VGHS
Re: STI help
Because that file doesn't exist.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
LÖVE3D - A 3D library for LÖVE 0.10+
Dev Blog | GitHub | excessive ❤ moé
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests