SOCIAL
GAMES
ART
BLOG
Event Lambdas
09.26.2025
Rowan Byington
Issues
   My problem this month was primarily with reworking the combat system. In the combat system I was working on, I abstracted the attacks. To do so, I stored an array of attacks with an index representing which attack to trigger. The issue with this was that I now had to find a way to trigger the attack function (which now takes an integer parameter) with a button event. Standard events for buttons take in a parameterless function. I had two paths: one, I could make a new function every time I wanted to add a new attack button to the ui, or two, I could make a lambda that just calls the attack function with the proper index. Making separate functions for each index was out of the question since that would defeat the entire purpose of the abstraction. Although, as I'm sure you are now aware, Dynamic events and button events both dont take lambda expressions.

Solutions
  My solution to this problem is a little sloppy, and if I had more time, I would fix it. I added a new event to the ButtonWithText that supports lambdas. With this new event, I was able to bind a lambda. In the future, I would prefer if these bindings were procedural instead of hard-coded, but for now, since the buttons on the UI are not procedural, this will be fine. With this new system in place, I can add any number of new attacks without adding any functions. This keeps my code clean and interchangeable.