Function references
-
I'm having a lot of fun playing around with F4NS so far! Here is a little feature suggestion:
It would be useful to be able to store references to functions in variables/arrays/structs or pass them as arguments to other functions.
Imagine being able to do something like this:array entity[100] = [ .position = { 0, 0 }, .behavior = noBehavior ] // Assign functions to .behavior on entities entity[0].behavior = playerBehavior entity[1].behavior = enemyBehavior entity[2].behavior = enemyBehavior entity[3].behavior = enemyBehavior loop updateEntities() update() repeat function updateEntities() for i = 0 to 100 loop entity[i].behavior(i) // Call the function assigned to .behavior repeat return void function noBehavior(i) // Do nothing return void function playerBehavior(i) // Do player stuff for entity[i] return void function enemyBehavior(i) // Do enemy stuff for entity[i] return void
-
I believe they are in the process of being able to call functions in this manner.
-
@Discostew can you let me know where you heard this please so I can lookup the info. Thanks.
-
This should do the trick, however there are some limitations:
The timer is set to 0 delay and unlimited repeats, so the timers must be stopped inside their function.
The function will be called once because the interval is set to 0 seconds, so keep that in mind when implementing.
Let me know if you have any more questions :) -
@Jaywalker That's pretty clever! Still would be nice to have proper function references though :)