pushing events

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
omarshariff
Prole
Posts: 3
Joined: Mon Aug 30, 2010 11:14 pm

pushing events

Post by omarshariff »

Anyone have any ideas why the following simple code doesn't work? Is there something I'm missing regarding pushing events and the love.handlers table?

Code: Select all

function love.load()
	love.handlers["walk"] = function(d) print("awesome " .. d) end
end

function love.update(dt)
	if love.keyboard.isDown('a') then
		love.event.push("walk", 'left')
	elseif love.keyboard.isDown('d') then
		love.event.push("walk", 'right')
	end
end
Cheers!
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: pushing events

Post by Tesselode »

So you made a function? I don't think you need to use event.push. Just say love.handlers["walk"]("left").
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: pushing events

Post by bartbes »

Because the event can't be mapped to an inbuilt type and hence is discarded, love.graphics.push should be returning false.
But why this rape of the even system, I ask?
omarshariff
Prole
Posts: 3
Joined: Mon Aug 30, 2010 11:14 pm

Re: pushing events

Post by omarshariff »

"But why this rape of the even system, I ask?"

I didn't realize that the event system was restricted to love only, the wiki doesn't make this distinction. In fact, the wiki appears to suggest that the love.event objects and functions are available to regular developers for use. Could you please expand on why you think this is an abuse of the event system? I thought that my approach was quite clean and elegant, unless I have misunderstood the purpose of the event system. Could you explain?

And to answer Tesselodes question, I was hoping to take advantage of the event system so that I could ensure a seperation of concerns. You see, in my program I am attempting to seperate the input controllers (joysticks) and AI controllers (AI inputs) so that my characters can be controled by either. I've done this by reducing the various outputs from each to simple instructions (MOVELEFT, FIRERIGHT, etc). I was hoping that I would be able to simplify things and ensure this speration by having the various characters/sprites listen for events. That way, I should be able to swap an AI controller character with a joystick controlled character at runtime.

This is mere exploratory work at the moment, hence my first initial investigations into the love.event system. Looking at the contents of the default love.run function, the event loop there seemed to duplicate what I wanted, which led me to the love.event wiki entry.

Again, if anyone has more information on the love.event system, especially as to why I should not use it for such things, I would appreaciate it (or even better, update the wiki with these reasons!)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: pushing events

Post by Robin »

omarshariff wrote:I didn't realize that the event system was restricted to love only, the wiki doesn't make this distinction. In fact, the wiki appears to suggest that the love.event objects and functions are available to regular developers for use. Could you please expand on why you think this is an abuse of the event system? I thought that my approach was quite clean and elegant, unless I have misunderstood the purpose of the event system. Could you explain?
love.event is for passing events such as key down, a mouse click or quitting the game from the lower depths to their handler (love.keypressed, love.mousepressed, etc.)

The only thing you'll usually push is 'q', to quit the game.

What you're trying to do is normally done by functions.

Code: Select all

function walk(direction)
 -- do something
end
omarshariff wrote:And to answer Tesselodes question, I was hoping to take advantage of the event system so that I could ensure a seperation of concerns. You see, in my program I am attempting to seperate the input controllers (joysticks) and AI controllers (AI inputs) so that my characters can be controled by either. I've done this by reducing the various outputs from each to simple instructions (MOVELEFT, FIRERIGHT, etc). I was hoping that I would be able to simplify things and ensure this speration by having the various characters/sprites listen for events. That way, I should be able to swap an AI controller character with a joystick controlled character at runtime.
Still, plain old functions do this excellently.

Otherwise, I think there are libraries that implement something like you want. (kikito, one of yours maybe?)

I don't think we ever had anyone else misunderstand the purpose of love.event, but perhaps it would be good to explain on the wiki that it mostly takes a passive role, rather than an active one, and only in relation to system events, as opposed to game events.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: pushing events

Post by bartbes »

omarshariff wrote:Could you please expand on why you think this is an abuse of the event system?
Well, Robin had a nice explanation:
Robin wrote:only in relation to system events, as opposed to game events.
There we go.
omarshariff
Prole
Posts: 3
Joined: Mon Aug 30, 2010 11:14 pm

Re: pushing events

Post by omarshariff »

I don't think we ever had anyone else misunderstand the purpose of love.event
raises hand weakly... :)

Cheers for the info guys. I'll look into those suggestions tonight. Thanks!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests