Fix functions not working with multiple scenes or with external events.

For the first issue, functions do not expose anymore a global variable.
For the second issue, functions are mangled with scene name and the search
for a function is now following links.