Page 2 of 2

Re: Game state management with hierarchy, looking for comments

Posted: Thu Jan 07, 2010 3:37 pm
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

Re: Game state management with hierarchy, looking for comments

Posted: Thu Jan 07, 2010 7:25 pm
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! :)

Re: Game state management with hierarchy, looking for comments

Posted: Thu Jan 07, 2010 7:28 pm
by bartbes
Why doesn't _G work, it seems waaaay more appropriate (and it's probably a whole lot faster too)

Re: Game state management with hierarchy, looking for comments

Posted: Thu Jan 07, 2010 7:36 pm
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...

Re: Game state management with hierarchy, looking for comments

Posted: Tue Feb 09, 2010 12:37 am
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!

Re: Game state management with hierarchy, looking for comments

Posted: Tue Feb 09, 2010 11:36 am
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 :)

Re: Game state management with hierarchy, looking for comments

Posted: Thu Feb 11, 2010 2:08 pm
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.