Skip to content

Comments

improve C_Trigger usage example#155

Open
the-overdriven wants to merge 1 commit intoGothic-Modding-Community:mainfrom
the-overdriven:patch-2
Open

improve C_Trigger usage example#155
the-overdriven wants to merge 1 commit intoGothic-Modding-Community:mainfrom
the-overdriven:patch-2

Conversation

@the-overdriven
Copy link
Contributor

@the-overdriven the-overdriven commented Aug 6, 2025

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:

  • fixed trigger variable names (use trigger only, not trigger and SelfTrigger)
  • removed delay acceleration (for the sake of basic example it was adding unnecessary complexity and can cause "Divide by Zero" error if delay drops below 0)
  • renamed ambiguous c_loop to poison_me_loop

@kamilkrzyskow
Copy link
Collaborator

Thanks for the contribution.
hmm, you're defining the class yourself in Daedalus.

I recalled a similar comment on Discord here where Gratt mentioned the After option:

META {
  After = zUnionTrigger.d; // include triggers api
  Using = zParserExtender; // using std namespace
};

However, idk if zUnionTrigger.d is part of Union or not maybe it needs to be defined by the user with the snippet above 🤔
Was this case also considered? I saw Gratt commenting in "more recent" threads, but it was never mentioned again, so it could be patched out 🤔


class C_Trigger
{
var int Delay; // defines the frequency (in miliseconds) at which the function will be called.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NadjaTrigger?


The trigger function
func void poison_me() {
var C_Trigger trigger;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +82 to +83
trigger.AIVariables[0] = 15; // how many times the function should be called
trigger.AIVariables[1] = 5; // how much damage to deal each iteration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants