Page 1 of 1
pushing events
Posted: Mon Aug 30, 2010 11:17 pm
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!
Re: pushing events
Posted: Tue Aug 31, 2010 3:18 am
by Tesselode
So you made a function? I don't think you need to use event.push. Just say love.handlers["walk"]("left").
Re: pushing events
Posted: Tue Aug 31, 2010 5:42 am
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?
Re: pushing events
Posted: Tue Aug 31, 2010 9:31 am
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!)
Re: pushing events
Posted: Tue Aug 31, 2010 2:00 pm
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.
Re: pushing events
Posted: Tue Aug 31, 2010 2:30 pm
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.
Re: pushing events
Posted: Tue Aug 31, 2010 4:17 pm
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!