Page 5 of 15

Re: HUMP - yet another set of helpers

Posted: Sat Jan 15, 2011 8:56 pm
by Robin
TechnoCat wrote:And shouldn't these be

Code: Select all

function Gamestate.update(self, dt)
instead of

Code: Select all

function Gamestate.update(dt)
What about

Code: Select all

function Gamestate:update(dt)
?

Re: HUMP - yet another set of helpers

Posted: Sat Jan 15, 2011 9:01 pm
by TechnoCat
Robin wrote:What about

Code: Select all

function Gamestate:update(dt)
?
Yes, that is much better. What was I thinking?

I was doing this dumb syntax

Code: Select all

learnGamestate.update = function(self,dt)
end
instead of this better one

Code: Select all

function learnGamestate:update(dt)
end
:death:

REMINDER: http://love2d.org/forums/viewtopic.php? ... =30#p25382 is still unanswered.

Re: HUMP - yet another set of helpers

Posted: Sun Jan 16, 2011 3:03 pm
by vrld
TechnoCat wrote:I'm trying to use the Interpolater, but it keeps returning a boolean instead of a number.
Like Lua's coroutine.resume(), the interpolator function will not just return the function value(s), but a status and the function values:
If the interpolation is still going on, it will return true, function_values. If the interpolation is finished, it will return nil, function_values. So in your example, you need to do this:

Code: Select all

table.insert(squares,1,newSquare(function(self,dt)
    local valid,alpha = fader(dt)
    if valid then self.alpha = alpha end
end))
changed recently
TechnoCat wrote:And shouldn't these be

Code: Select all

function Gamestate.update(self, dt)
instead of

Code: Select all

function Gamestate.update(dt)
Yeah, the documentation is ambigious. Gamestate.update(dt) actually calls the update function on the active gamestate. This is for if you don't want to use Gamestate.registerEvents.
The update/draw/... functions of the gamestate itself have to be defined like you mentioned:

Code: Select all

state = Gamestate.new()
function state:update(dt)
    do_stuff()
end
I'll try to make both things clearer in the documentation.

Re: HUMP - yet another set of helpers

Posted: Sun Jan 16, 2011 6:19 pm
by TechnoCat
You have made epilepsy mode possible!

Re: HUMP - yet another set of helpers

Posted: Thu Jan 20, 2011 8:36 pm
by vrld
Big changes, including some API breakage:

hump modules are now proper Lua modules.
You can require them to variables, like this:

Code: Select all

local GS = require 'hump.gamestate'
menu = GS.new()
This also means the global namespace will no longer be polluted. For example

Code: Select all

require 'hump.timer'
would previously define three global variables: Timer, Interpolator and Oscillator. Now the only global you will have is hump.timer. You can still use Timer.add() and such by loading the module to a table called Timer:

Code: Select all

Timer = require 'hump.timer'
This style (proably with local) is generally how you should use hump now.

Timer.Interpolator() behaves differently
Instead of returning <status>, <function values> it now returns the function values if the interpolation is still going on or nil, if the interpolation has finished. This may result in the interpolation function never receiving the value 1 as fraction argument (so you better don't rely on that to happen).

Removal of sequence.lua
Since it felt like a misfit and probably nobody used it anyway.

And finally:
New, better documentation
I updated/rewrote the whole documentation. It's much cleaner now and each function has an example attached to it.

Re: HUMP - yet another set of helpers

Posted: Thu Jan 20, 2011 8:45 pm
by nevon
Awesome! I really appreciate that you are taking the time to make HUMP. It's a huge help for me, and your class implementation is the least horrible one (personal taste) I've found for Lua so far.

Also, here's a patch to add love.quit and love.focus to gamestate.lua.

Re: HUMP - yet another set of helpers

Posted: Thu Jan 20, 2011 10:40 pm
by TechnoCat
vrld wrote:hump modules are now proper Lua modules.
You can require them to variables, like this:
This is a very welcome change. Thanks vrld!

Re: HUMP - yet another set of helpers

Posted: Sun Jan 23, 2011 10:51 pm
by vrld
Thanks for the kind words.
nevon wrote:Also, here's a patch to add love.quit and love.focus to gamestate.lua.
Now part of hump. ^^

Re: HUMP - yet another set of helpers

Posted: Wed Apr 13, 2011 11:26 am
by vrld
I totally forgot to write about some updates:
  • Gamestates can now have an init() callback that will be executed (exactly once) before you first enter the state. Useful for one time loading of resources and stuff:

    Code: Select all

    state = Gamestate.new()
    function state:init()
        self.fonts[30] = love.graphics.newFont(30)
        self.background = love.graphics.newImage('img/background.jpg')
        self.animation = ...
    end
  • You can inherit from other classes directly at defining the class - no more akward class:inherit(others) (though that's still possible):

    Code: Select all

    A = class{}
    B = class{inherits = A}
    C = class{}
    D = class{inherits = {B,C}}
  • Automatic name inference for (global) classes - the name parameter is not neccessary anymore:

    Code: Select all

    A = class{} -- same as A = class{name = "A"}
    print(A) --> 'A'
    a = A()
    print(a) --> '<instance of A>'
    You still can supply a name parameter if you want (or have to in case of global or module classes).
The documentation has more details on that:
hump.gamestate and hump.class.

Re: HUMP - yet another set of helpers

Posted: Sun Apr 24, 2011 5:11 am
by Queops
This is great! Keep up the good work mate! I really hump this.