improve C_Trigger usage example#155
improve C_Trigger usage example#155the-overdriven wants to merge 1 commit intoGothic-Modding-Community:mainfrom
Conversation
|
Thanks for the contribution. I recalled a similar comment on Discord here where Gratt mentioned the However, idk if |
|
|
||
| class C_Trigger | ||
| { | ||
| var int Delay; // defines the frequency (in miliseconds) at which the function will be called. |
There was a problem hiding this comment.
miliseconds -> milliseconds
| func void poison_me() { | ||
| var C_Trigger trigger; | ||
| trigger = AI_StartTriggerScriptEx("poison_me_loop", 1000, hero, null, null); | ||
| NadjaTrigger.Delay = 500; // repeat loop each call by 500ms |
|
|
||
| The trigger function | ||
| func void poison_me() { | ||
| var C_Trigger trigger; |
There was a problem hiding this comment.
Now this is in the function, local variable redefinition, same name as global.
It would work in Gothic as the local variable is merged with the function name, so it's poison_me.trigger.
part (1/2)
| // available iterations has reached 0. If it did | ||
| // we stop the trigger by returning the LOOP_END value. | ||
| if (SelfTrigger.AIVariables[0] <= 0) | ||
| if (trigger.AIVariables[0] <= 0) |
There was a problem hiding this comment.
part (2/2)
The previous example should've been incorrect, as there was no SelfTrigger to reference.
And now you're accessing the global trigger value, but it's the same name as in the previous function.
| trigger.AIVariables[0] = 15; // how many times the function should be called | ||
| trigger.AIVariables[1] = 5; // how much damage to deal each iteration |
There was a problem hiding this comment.
Given that AIVariables can store anything, and there is no standard, I think this could be improved by removing the magic number indexing and add a global const int like TRIGGER_AI_REPEATS = 0 to globally define that index 0 is the number of repeats.
The current example is incomplete and not working in game.
I've copy-pasted an extended working example from GMC discord by @auronen.
Added a few minor improvements:
triggeronly, nottriggerandSelfTrigger)delayacceleration (for the sake of basic example it was adding unnecessary complexity and can cause "Divide by Zero" error ifdelaydrops below 0)c_looptopoison_me_loop