• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Create a function in a converted GUI trigger

Status
Not open for further replies.

Ardenian

A

Ardenian

Two notes: I don't use JNGP and I am a bloody beginner to Jass.

I have a question concerning writing Jass in common GUI triggers ( converting the trigger and paste Jass code in it).

I have the following: I have a series of functions. Each function is called by the previous one and will call the next one in row. Each function shall have its own GUI trigger, as these functions are very complex.

My question now, how can I do this ? I learned in the past that, when not using JNGP, you have to paste all your Jass into your map header script.

However, I have the feeling this is not a 100% true. I recall it was said that if I call a function, the called function has to be above the function where the function call comes from.

What do I have to add to a converted trigger to make my Jass lines work ?

From converting I saw:
JASS:
function InitTrig_MyTrigger takes nothing returns nothing
    set gg_trg_MyTrigger = CreateTrigger(  )
    call TriggerAddAction( gg_trg_MyTrigger, function Trig_MyTrigger_Actions )
endfunction

Is this everything ? If I add this at the bottom of every converted GUI trigger, then I can use them as if they were all copied into the map header ?
A function called from under the function I call will be appropriate called ?

Copying a function into the map header means it can be called from everywhere, as if it was the first trigger in the trigger list ?

I ask, since it seems not to work and I would like to know whether the problem is this argumentation.
 
Level 7
Joined
Oct 19, 2015
Messages
286
The easiest solution is to use vJass libraries.

The second easiest solution is to put all common functions into the map header.

If neither of those is acceptable, then you can also do things your way. I just saw a thread about this very issue in the other forum so here's a link to the answer to your question, or at least a part of it.

As for the other part, if you want a trigger to compile and you don't have JNGP, then the trigger must contain a function named InitTrig_TRIGGER_NAME that takes nothing. The function can be empty, though.
 

Ardenian

A

Ardenian

Thank you for your answer!
Sadly none of the two solutions is acceptable for me.

So,
JASS:
function InitTrig_MyTrigger takes nothing returns nothing

endfunction

^This will properly work, when copied at the end of a converted GUI trigger with a Jass script ?
 
Level 7
Joined
Oct 19, 2015
Messages
286
That's right, you can also skip the empty line between function and endfunction. That's all a converted GUI trigger needs in order to not cause compile errors.
 

Ardenian

A

Ardenian

That's right, you can also skip the empty line between function and endfunction. That's all a converted GUI trigger needs in order to not cause compile errors.

Thank you, now it seems to work!
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
Each function is called by the previous one
If I add this at the bottom of every converted GUI trigger, then I can use them as if they were all copied into the map header ?
you can call functions by this
JASS:
 call functionname(parameters)
your functions do not have a parameter though so you just call them by their function name and empty brackets
JASS:
call MyTrigger()
the "InitTrig" will act as an initializer, but it is not necessary to call a function as long as it is public.
 
Status
Not open for further replies.
Top