Game state management with hierarchy, looking for comments

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Game state management with hierarchy, looking for comments

Post by Robin »

Depending on how much you want to shield from those files, you could use setfenv:

Code: Select all

do
    local g = {} --put stuff in it
    local f = loadstring(--[[stuff]])
    setfenv(f, g)
    f()
end
Help us help you: attach a .love.
giniu
Party member
Posts: 221
Joined: Mon Nov 30, 2009 4:44 pm

Re: Game state management with hierarchy, looking for comments

Post by giniu »

Hi, thanks for all the hints, I think I choose one based on this hint:
bartbes wrote:

Code: Select all

local localvar = {}
loadstring("return somefun")(localvar)
print(localvar.status)
just I would use

Code: Select all

assert(loadstring("return somefun"))()(localvar)
it works great, didn't thought that returning function would be enough here :) Anyway I've updated the file, later on I will document it a bit more and think if I want to move it to classes. Thanks again for help! :)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Game state management with hierarchy, looking for comments

Post by bartbes »

Why doesn't _G work, it seems waaaay more appropriate (and it's probably a whole lot faster too)
giniu
Party member
Posts: 221
Joined: Mon Nov 30, 2009 4:44 pm

Re: Game state management with hierarchy, looking for comments

Post by giniu »

bartbes wrote:Why doesn't _G work, it seems waaaay more appropriate (and it's probably a whole lot faster too)
Didn't knew it works faster and you said about second method, that it "seems to make more sense", but now I get that it was in answer to kalle2990s way. Indeed, the _G looks cleaner, just it was first time I ever saw that, so maybe that's why I didn't picked it at first...
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Game state management with hierarchy, looking for comments

Post by kikito »

Hi there!

I know it is a bit late, but I want to tell you that I've created a wiki page for MindState now. It is still missing some advanced examples, but there's one about creating a "Game manager" object, in case you are interested.

Regards!
When I write def I mean function.
giniu
Party member
Posts: 221
Joined: Mon Nov 30, 2009 4:44 pm

Re: Game state management with hierarchy, looking for comments

Post by giniu »

Hi, I feel I wouldn't use MindState directly, I'm actually quite used to hierarchy in game states - but maybe I would use MiddleClass thought to get previous behaviour from attached file, will see :)
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

Re: Game state management with hierarchy, looking for comments

Post by pygy »

I hadn't seen either this post or Mindsatate before starting Pölygamy. Both projects look very interesting.

Pölygamy will provide some middle ground between both approaches, actually. New version this evening, with "scene" management (menu, in game, pause screen, etc...) at the update/draw level. Stay posted.
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 68 guests