Decorators vs the eventscripts way ..
Posted: Sat Jul 07, 2012 1:19 pm
So I thought that in addons it might be better to use decorators instead of making some functions automatically work as it gives a bit more freedom. I also don't really like how es tries to register every functon as event (unless it starts with _)
Some ideas:
Thoughts`?
Some ideas:
Syntax: Select all
@load
def myloadfunction():
print ("This will be loaded upon script load")
@load
def anotherloadfunction():
print("Hey, this will be loaded, too, but after the first function since it was declared later on :P")
@event
def player_hurt(ev):
# this registers this function as event listener; since no event specified, the function name (func.__name__) will be assumed to be the event
pass
@event("player_hurt")
def give_health_on_hurt(ev):
# This registers this function as event listener for player hurt
pass
Thoughts`?