## HUMP - yet another set of helpers

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

### Re: HUMP - yet another set of helpers

TechnoCat wrote:And shouldn't these be

Code: Select all

function Gamestate.update(self, dt)

Code: Select all

function Gamestate.update(dt)

Code: Select all

function Gamestate:update(dt)
?

TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

### Re: HUMP - yet another set of helpers

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

Code: Select all

function learnGamestate:update(dt)
end

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

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

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)
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)

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.
Last edited by vrld on Sat Jan 22, 2011 10:50 am, edited 1 time in total.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

### Re: HUMP - yet another set of helpers

You have made epilepsy mode possible!
Attachments
learnHUMP.love

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

### Re: HUMP - yet another set of helpers

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.

TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

### Re: HUMP - yet another set of helpers

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!

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: HUMP - yet another set of helpers

• 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Queops
Prole
Posts: 2
Joined: Sat Apr 23, 2011 11:47 pm

### Re: HUMP - yet another set of helpers

This is great! Keep up the good work mate! I really hump this.

### Who is online

Users browsing this forum: No registered users and 14 guests