sepperating projects
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: sepperating projects
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.
Help us help you: attach a .love.
Re: sepperating projects
still don't get it to run, please provide me with some running code...
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: sepperating projects
What if you try:Sparx wrote:still don't get it to run, please provide me with some running code...
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
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.
Help us help you: attach a .love.
Re: sepperating projects
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.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.
Haha sure XD, usually my untested code has a crapload of syntax errors...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
Edit
The attachment is a complete example, with two rooms and fully working hooks. I changed the name from 'states' to 'rooms'.
- Attachments
-
- rooms.love
- Simple room table handeling example.
- (1.73 KiB) Downloaded 113 times
Re: sepperating projects
i try using this code as-well with no success
Re: sepperating projects
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
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
Look at the post above you , read the whole thread before posting my bro.ub3rl1t wrote:i try using this code as-well with no success
Who is online
Users browsing this forum: Google [Bot] and 14 guests