Page 2 of 2
Re: sepperating projects
Posted: Tue Jul 07, 2009 9:24 am
by Robin
For my latest project (it's called "Planets!"), I have done a similar thing. Although I used two load functions: :init() and :load(). The first is more like the regular load(), while :load() is called every time the state becomes active. It's much better than using if statements inside update() and draw(), as I did with Jump Game.
Re: sepperating projects
Posted: Tue Jul 07, 2009 11:39 am
by Sparx
still don't get it to run, please provide me with some running code...
Re: sepperating projects
Posted: Tue Jul 07, 2009 12:16 pm
by Robin
Sparx wrote:still don't get it to run, please provide me with some running code...
What if you try:
main.lua:
Code: Select all
states = {}
for k, v in ipairs(love.filesystem.enumerate("states/")) do --loop through all files in your ./states folder
local STATE = {}
local pos = v:find("%.lua$"))
if (pos) then --if the file ends in .lua
love.filesystem.include("states/"..v) --load it
state[v:sub(1,pos-1)] = STATE --store state in state table using filename minus .lua
end
end
currentstate = states.menu
function switchstate(target)
currentstate = states[target]
end
function load()
currentstate:load()
end
states/menu.lua:
Code: Select all
function STATE:load()
--do stuff
end
?
If that doesn't work: I can upload what I have for Planets!, it doesn't do much yet, but at least it works.
Re: sepperating projects
Posted: Tue Jul 07, 2009 2:50 pm
by Zorbatron
bartbes wrote:Few things, it's good that you just load the entire states folder, but I really can't agree with your choice for ., using I don't like the ENTRY. stuff, I always prefer self.. (for stuff that needs to be saved in the state, and has no business in the wide world of the global table)
EDIT: Oh and have to add, I just spotted that you DO have a : in the second snippet.
Well, its a design decision really, if you really have troubles with namespaces then you could just `:' instead, I thought'd it be easier for him. I'll rewrite that second one.
Sparx wrote:Zorbatron wrote:A more complete example.....
Thanks that looks quite good (as i thougth t should be)besides the fact that i can't get it to work. I am not very used to using methods. Could you provide the same thing you wrote me without syntax errors and working...?
Thanks in advance Sparx
Haha sure XD, usually my untested code has a crapload of syntax errors...
Edit
The attachment is a complete example, with two rooms and fully working hooks. I changed the name from 'states' to 'rooms'.
Re: sepperating projects
Posted: Mon Jul 13, 2009 7:07 pm
by ub3rl1t
i try using this code as-well with no success
Re: sepperating projects
Posted: Mon Jul 13, 2009 7:28 pm
by Sparx
it works for me, did you download rooms.love
that's acomplete example...
If ou don't know how to edit such files: try opening it with a programm beeing able to unzip.. else rename it to .zip and do the same again.. have fun
Re: sepperating projects
Posted: Mon Jul 13, 2009 11:52 pm
by Zorbatron
ub3rl1t wrote:i try using this code as-well with no success
Look at the post above you
, read the whole thread before posting my bro.