i'm quite frustrated about this, it would be so much better if we could set 'self' as well for the called function in addEventListener. i'm struggling a lot how to pass self and one other parameter to the called function, somehow there is always some error. and this is not the first time this happens.
Comments
Fragmenter - animated loop machine and IKONOMIKON - the memory game
- what you are trying to achieve
- a code sample of what you currently do
- and ideally what would the code look like to you, if it was available in Gideros
I think that would help understand your point better. Isn't it achievable with the third parameter?Case 1
Case 2
Didn't test the case 2 but you get the idea
i think case2 is what i needed, so it is indeed achievable relatively nicely, just one dummy function is needed which can be defined right there as in case2. thanks for the help.
yet i can try to explain myself better, as my proposition still makes some sense.
my proposed feature would be to able to add:
instead of :
stage:addEventListener(Event.TOUCHES_BEGIN,
function() enemy:onTouchesBegin(param1)
end)
have:
i)stage:addEventListener(Event.TOUCHES_BEGIN, enemy:onTouchesBegin, param1)
or
ii)stage:addEventListener(Event.TOUCHES_BEGIN, enemy.onTouchesBegin, param1)
or worst case (with 4 parameters, that was my initial proposition, but it seems redundant and less intuitive):
iii)stage:addEventListener(Event.TOUCHES_BEGIN, enemy.onTouchesBegin, param1, enemy)
iiib)stage:addEventListener(Event.TOUCHES_BEGIN, Enemy.onTouchesBegin, param1, enemy)
(for me i) seems to be the most intuitive)
of course it solves the problem only in case of one parameter but anyway the current setup also allows to add one parameter nicely and additionals only with a dummy function as in case2 you say. so the change would be that one parameter+self would be possible to add nicely and additional parameters would need to be done as in case2.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
at least propositions cannot do much harm.
thanks again
Fragmenter - animated loop machine and IKONOMIKON - the memory game
so how would one modify case2 to receive the 'event' object dispatched by the dispatcher (for a custom event) like this:
local event=Event.new("changed")
event.color=100
self:dispatchEvent(event)
so how to do if i want that the function receives this event, the proper 'self' and also custom parameters.
thanks
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
i think that ar2rsawseen's
stage:addEventListener(Event.TOUCHES_BEGIN,
function(e) enemy:onTouchesBegin(e, param1, param2, param3)
end)
is closest in look, length and function to what i wanted to do. together with the other suggestions probably i can get all the details of how all this event stuff works.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: vitalitymobile
on the other hand a line like
local data2 = data[3] (2=3, hmm)
illustrates well why perhaps passing self separately as a third parameter (second in addeventlistener, as 'event' is passed automatically then) would be more logical/intuitive.
in any case i'm happy with the above list of solutions.
Fragmenter - animated loop machine and IKONOMIKON - the memory game