Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Delete an event ?  (Read 3437 times)

0 Members and 1 Guest are viewing this topic.

Kabelou

  • Newbie
  • *
  • Posts: 1
    • View Profile
Delete an event ?
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Delete an event ?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything