PÄSSION: object-oriented LÖVE

Showcase your libraries, tools and other projects that help your fellow love users.
amshali
Prole
Posts: 3
Joined: Thu Dec 10, 2009 5:55 am

Re: PÄSSION: object-oriented LÖVE

Post by amshali »

Passion is not gonna work with love 0.5.0?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Hi amshali,

I'm afraid that only 0.6 is supported.

I suppose you could try "transforming" the current example into 0.5 by doing the following:
  • Changing love.load, love.draw and love.update to just draw, load and update
  • Changing "line" to love.draw_line
But I don't recommend doing this. Better try to update to 0.6... lot's of exciting features are there!

In any case, you can use MiddleClass if you are just looking for object-orientation.
When I write def I mean function.
User avatar
Pliskin09
Citizen
Posts: 89
Joined: Fri Jul 24, 2009 8:30 am

Re: PÄSSION: object-oriented LÖVE

Post by Pliskin09 »

is the first example on http://love2d.org/wiki/index.php?title=MiddleClass broken? and can i just do require('passion/init.lua') instead of using just middle class to run it? im just trying to find an example that works so i can fiddle with it/learn it better thats all. (the avalanche one is a little bit too much to grasp at the moment - the text example on the page i linked to above seems easy enough to grasp. but i get errors when running it. - attenpt to index global 'B' (a nil value))
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by Robin »

Help us help you: attach a .love.
User avatar
Pliskin09
Citizen
Posts: 89
Joined: Fri Jul 24, 2009 8:30 am

Re: PÄSSION: object-oriented LÖVE

Post by Pliskin09 »

still no good.there was another "B" left in there that i changed too, but it didn't help (i didn't change it on the wiki, as i didn't know if it was right or not). tried this in both 0.6.0 and 0.5.0

edit:

error is: attempt to index local 'self' (a nil value)
in function "speak"
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by Robin »

Pliskin09 wrote:still no good.there was another "B" left in there that i changed too,
Oops. :oops:
Pliskin09 wrote:error is: attempt to index local 'self' (a nil value)
in function "speak"
http://love2d.org/wiki/index.php?title= ... &oldid=942
Explanation: calling table1:func1() actually calls table1.func1(table1) (which was added to Lua specifically for OOP). That means, if you do p1.speak(), the argument self is nil, instead of p1.
Help us help you: attach a .love.
User avatar
Pliskin09
Citizen
Posts: 89
Joined: Fri Jul 24, 2009 8:30 am

Re: PÄSSION: object-oriented LÖVE

Post by Pliskin09 »

got it working. except that the "constructor" for each "class" needs to be called "initialize", not "init". i've amended the wiki too.

http://love2d.org/wiki/index.php?title= ... &oldid=943
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Hi, sorry for not replaying - I've been out and without internet access.

My shame is only surpassed by my gratefulness. Thanks Robin & Pliskin09 for fixing my sample code - you guys are great.
When I write def I mean function.
User avatar
Pliskin09
Citizen
Posts: 89
Joined: Fri Jul 24, 2009 8:30 am

Re: PÄSSION: object-oriented LÖVE

Post by Pliskin09 »

hey just another problem im having with the samples - see the mixins example? the hasWings module gives an error at '(' in function fly(). whats the correct way of doing this?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by Robin »

Pliskin09 wrote:hey just another problem im having with the samples - see the mixins example? the hasWings module gives an error at '(' in function fly(). whats the correct way of doing this?
This is the problem:

Code: Select all

HasWings = { -- HasWings is a module, not a class. It can be "included" into classes
  function fly()
    print('flap flap flap I am a ' .. self.class.name)
  end
}
You can't do that. You see, inside a table you can put expressions, but no statements. function fly() is a statement. To solve it, you can use either

Code: Select all

HasWings = { -- HasWings is a module, not a class. It can be "included" into classes
  fly = function ()
    print('flap flap flap I am a ' .. self.class.name)
  end
}
or

Code: Select all

HasWings = {} -- HasWings is a module, not a class. It can be "included" into classes
function HasWings.fly()
  print('flap flap flap I am a ' .. self.class.name)
end
.

I fixed it on the wiki as well.

EDIT: Word of advice: putting up examples on the wiki is good, but run them to check for mistakes first. An example that's wrong is worse than no example at all. ;)
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 63 guests