SFML community forums

Bindings - other languages => DotNet => Topic started by: Kabelou on April 01, 2020, 02:15:25 pm

Title: Delete an event ?
Post by: Kabelou on April 01, 2020, 02:15:25 pm
Hi,


I am creating a game with several methods that use the same events but with different attributes:

app.JoystickMoved += (s, e) => JoyMoved3(e.Axis, e.Position, app, s1, s2, s3, s4, s5, s6, r1, r2, r3, r4, r5, r6);

app.JoystickMoved += (s, e) => JoyMoved(e.Axis, e.Position, map);

I add in the events "JoystickMoved" a new event "JoyMoved3". But if I call my function which adds a new event "JoyMoved3" x times, it executes x times but I would like it to execute 1 time even if I call it 15 times.

I thought about that: (with minus)

app.JoystickMoved -= (s, e) => JoyMoved3(e.Axis, e.Position, app, s1, s2, s3, s4, s5, s6, r1, r2, r3, r4, r5, r6);

But it does not work.

How can I delete this event please ?


Thanks for any help and sorry for my bad english.
Title: Re: Delete an event ?
Post by: eXpl0it3r on April 07, 2020, 10:17:57 am
I'm not sure if you can remove anonymous lambdas from an event handler like that. If it's named you can indeed us -= to remove it. Alternatively, you can also set it to null and reassign the other handlers.