| 12-07-2002, 09:14 PM | #1 |
If I have two triggers in custom text, each with an identical function with the same name, my map won't compile: Trigger1: function is_prime takes integer i returns boolean [code] end function function trigger1 takes nothing returns nothing [code] end function trigger2: function is_prime takes integer i returns boolean [same code as in is_prime function above] end function function trigger2 takes nothing returns nothing [code] end function WE doesn't like this, and won't compile the map until I rename one instance of the is_prime function (to is_prime2, for example). Does this imply that a function can be invoked in *any* trigger, or does it simply mean that every instance of the same function has to have a different name? For instance, can function3 have this line: return is_prime (64) even if is_prime is in function1 or do I have to redefine the same function with a different name in this trigger as well? |
| 12-07-2002, 11:37 PM | #2 |
Guest | For some reason, the world editor is very testy about functions in seperate triggers. Basically its a trigger editor problem. The trigger editor will let you define the same function in different triggers, but the world editor will realize there's a problem when you try to save the map. In similar fashion, the trigger editor wont let you call functions from another trigger, even though the code will eventually be saved in a single file. If you want several triggers to use the same function, you can always copy all the triggers into one "trigger" (by this i mean in the trigger editor interface). That way the trigger editor will see the code the way the world editor does. |
| 12-08-2002, 09:30 AM | #3 |
There's a way you can use functions from other triggers: Write the function in trigger 1. Write a function with the same name in trigger 2 that does nothing. Now you can use the function in trigger 2. Before saving your map you must comment out your function in trigger 2. If your trigger 2 gets deactivated (by script errors for example) you must remove the comment slashes from your function to reenable the trigger. NOTICE: When you use a function that should return something (like string or integer) you MUST return a value!!! Don't just do 'endfunction'. And the best of the best: If you just write endfunction, WE will crash. w00t! So your small copy of the original function should consist of a return statement. |
