• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] I'm begining using JASS but...

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,928
I tried this thing of creating a functions, but always I get Syntax errors, and the tutorials of this forum don't say why?

What am I doing bad?

(Pls don't ask me why am I using the old Jass New Gen)

upload_2020-8-1_22-4-47.png

upload_2020-8-1_22-5-38.png
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
gg_trg_Detonador_sin_nombre_002 is already a trigger. You don't need to create it again.

You can use a Variable in that situation like:
vJASS:
NewTrigger = CreateTrigger()
Then you can reference NewTrigger.
 
Last edited:
Mixing GUI globals with Jass is not recommended as the initialization of GUI globals is very weird.

Unless you still want to use GUI triggers here and there, I recommend using vJass globals:

Just put a block like this on the top of your script to initialize a Jass global variable:

JASS:
globals
    trigger MyTrig = CreateTrigger()
endglobals
Then use MyTrig instead of the GUI global there.


However, in your case, you can also use a local variable right in your init function:
local trigger MyTrig = CreateTrigger()

You only need global variables of you want to use them outside of your function.
 
Level 13
Joined
May 10, 2009
Messages
868
I just wanna explain that the error related to "gg_trg_Detonador_sin_nomber_002" being undeclared probably happened because you used the "Syntax Check" button instead of saving the map. That button doesn't check the entire map script, but only the scope being visible at run time. Since that variable isn't being declared there, it threw such error. I recommend that you save your map if you want to check for any real errors.
 
I just wanna explain that the error related to "gg_trg_Detonador_sin_nomber_002" being undeclared probably happened because you used the "Syntax Check" button instead of saving the map. That button doesn't check the entire map script, but only the scope being visible at run time. Since that variable isn't being declared there, it threw such error. I recommend that you save your map if you want to check for any real errors.
Jasshelper does often throw errors on GUI initialized globals regardless.
Hence why the TO should learn how to declare globals in Jass next.
 
Level 13
Joined
May 10, 2009
Messages
868
Let's take another approach. Despite the error being shown, your piece of code primarily won't run because there's no event associated with the trigger, and the trigger itself doesn't reference your "HelloWorld" function even if it had a proper event.

Change your script to this:
JASS:
function HelloWorld takes nothing returns nothing
    call BJDebugMsg("Hello World!")
endfunction

//===========================================================================
function InitTrig_Detonador_sin_nombre_002 takes nothing returns nothing
    local trigger triggerVar = CreateTrigger()
    call TriggerAddAction(triggerVar, function HelloWorld)
    call TriggerRegisterTimerEvent(triggerVar, 1.00, false)
endfunction

JASS:
//===========================================================================
// The function name below is generated by the editor when converting from GUI to JASS. It should respect the "trigger name".
// This function is called by another "hidden" function (Main -> InitCustomTriggers)
function InitTrig_Detonador_sin_nombre_002 takes nothing returns nothing
    local trigger triggerVar = CreateTrigger() // Local variable, type: Trigger, Name: triggerVar = Initializes a new trigger object.
    call TriggerAddAction(triggerVar, function HelloWorld) // TriggerAddAction appends a function ("HelloWorld" in this case) to a trigger, and such function is fired when using events or running this trigger.
    call TriggerRegisterTimerEvent(triggerVar, 1.00, false) // This registers a timer event which expires in 1 second and doesn't repeat (Just like "Time Elapsed" GUI event)
endfunction

Here's how the trigger works so far:
1 - Map loads, and InitTrig_Detonador_sin_nombre_002 function is called by the game automatically.
2 - A new trigger object is created and assigned to a local variable
3 - Adds an action and event to the trigger object, referencing the local variable.
4 - After timer event expires, the "action" (function) added to the trigger is called. (Calls HelloWorld function)
5 - Prints "Hello World" to all possible clients.
 
Last edited:
Level 24
Joined
Jun 26, 2020
Messages
1,928
Let's take another approach. Despite the error being shown, your piece of code primarily won't run because there's no event associated with the trigger, and the trigger itself doesn't reference your "HelloWorld" function even if it had a proper event.

Change your script to this:
JASS:
function HelloWorld takes nothing returns nothing
    call BJDebugMsg("Hello World!")
endfunction

//===========================================================================
function InitTrig_Detonador_sin_nombre_002 takes nothing returns nothing
    local trigger triggerVar = CreateTrigger()
    call TriggerAddAction(triggerVar, function HelloWorld)
    call TriggerRegisterTimerEvent(triggerVar, 1.00, false)
endfunction

JASS:
//===========================================================================
// The function name below is generated by the editor when converting from GUI to JASS. It should respect the "trigger name".
// This function is called by another "hidden" function (Main -> InitCustomTriggers)
function InitTrig_Detonador_sin_nombre_002 takes nothing returns nothing
    local trigger triggerVar = CreateTrigger() // Local variable, type: Trigger, Name: triggerVar = Initializes a new trigger object.
    call TriggerAddAction(triggerVar, function HelloWorld) // TriggerAddAction appends a function ("HelloWorld" in this case) to a trigger, and such function is fired when using events or running this trigger.
    call TriggerRegisterTimerEvent(triggerVar, 1.00, false) // This registers a timer event which expires in 1 second and doesn't repeat (Just like "Time Elapsed" GUI event)
endfunction

Here's how the trigger works so far:
1 - Map loads, and InitTrig_Detonador_sin_nombre_002 function is called by the game automatically.
2 - A new trigger object is created and assigned to a local variable
3 - Adds an action and event to the trigger object, referencing the local variable.
4 - After timer event expires, the "action" (function) added to the trigger is called. (Calls HelloWorld function)
5 - Prints "Hello World" to all possible clients.
There is no longer Syntax error, but the map doesn't load.
 
Last edited:
Because you simply call your hello world function.

The InitTrig stuff is only there to attach an event and establish your trigger. If you directly call your function from another trigger, you don't need it at all.

You need the InitTrig if you want to build event triggers in JASS. But calling Jass functions from GUI also works. Its just a matter of how much you want to commit coding in Jass versus applying a hybrid of GUI and Jass.
 
Level 24
Joined
Jun 26, 2020
Messages
1,928
Because you simply call your hello world function.

The InitTrig stuff is only there to attach an event and establish your trigger. If you directly call your function from another trigger, you don't need it at all.

You need the InitTrig if you want to build event triggers in JASS. But calling Jass functions from GUI also works. Its just a matter of how much you want to commit coding in Jass versus applying a hybrid of GUI and Jass.
I mean, why it work now when I downloaded his test map and not when I did it myself if I did the same thing?
 
Status
Not open for further replies.
Top