sepperating projects

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: sepperating projects

Post 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.
Help us help you: attach a .love.
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: sepperating projects

Post by Sparx »

still don't get it to run, please provide me with some running code...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: sepperating projects

Post 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.
Help us help you: attach a .love.
User avatar
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Re: sepperating projects

Post 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'.
Attachments
rooms.love
Simple room table handeling example.
(1.73 KiB) Downloaded 103 times
ub3rl1t
Prole
Posts: 15
Joined: Sun Jul 12, 2009 10:43 pm

Re: sepperating projects

Post by ub3rl1t »

i try using this code as-well with no success
User avatar
Sparx
Party member
Posts: 125
Joined: Thu Apr 02, 2009 9:54 am
Location: Aachen, Germany

Re: sepperating projects

Post 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
User avatar
Zorbatron
Citizen
Posts: 78
Joined: Wed May 27, 2009 6:58 pm

Re: sepperating projects

Post by Zorbatron »

ub3rl1t wrote:i try using this code as-well with no success
Look at the post above you :P, read the whole thread before posting my bro.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 223 guests