1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Join the 6th Melee Mapping Contest for a chance to have your map featured in this year's Hive Cup!
    Dismiss Notice
  4. Shoot to thrill, play to kill. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  5. Do you hear boss music? It's the 17th Mini Mapping Contest!
    Dismiss Notice
  6. Let your favorite entries duke it out in the 15th Techtree Contest Poll.
    Dismiss Notice
  7. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Discussion in 'World Editor Help Zone' started by HerlySQR, Aug 2, 2020.

Tags:
  1. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    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
     
  2. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    1,853
    Resources:
    0
    Resources:
    0
    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:
    Code (vJASS):

    NewTrigger = CreateTrigger()
     
    Then you can reference NewTrigger.
     
    Last edited: Aug 2, 2020
  3. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    Can you show me how will look the entire script?
     
  4. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    1,853
    Resources:
    0
    Resources:
    0
    Just delete set gg_trg_Detonador_sin_nombre_002 = CreateTrigger( ) and you should be good to go.
     
  5. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    Ok I will see
     
  6. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,991
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    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:

    Code (vJASS):
    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.
     
  7. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    842
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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.
     
  8. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,991
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    Jasshelper does often throw errors on GUI initialized globals regardless.
    Hence why the TO should learn how to declare globals in Jass next.
     
  9. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    842
    Resources:
    2
    Spells:
    2
    Resources:
    2
    That's strange; I've never had any trouble with it.
    Well, one must know how to declare globals in JASS if they want to switch to it, anyway.
     
  10. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    Pls, Can you show me how must look the entire script?
     
  11. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    842
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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:
    Code (vJASS):
    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


    Code (vJASS):
    //===========================================================================
    // 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: Aug 2, 2020
  12. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    There is no longer Syntax error, but the map doesn't load.
     
    Last edited: Aug 2, 2020
  13. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    842
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Not sure what's going on with your editor. It works as intended for me, even with 1.27b JNGP (either Vexorian's JassHelper turned on or off)

    Untitled-2.png
     

    Attached Files:

  14. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    Ok, I don't get why, but it worked to me too.
     
  15. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    I even deleted this
    Code (vJASS):
    call TriggerRegisterTimerEvent(triggerVar, 1.00, false)

    And added this
    • Events
      • Player - Player 1 Red press left arrow
    • Conditions
    • Actions
      • Custom script: call HelloWorld()

    And it worked.
     
  16. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    I even added more functions and they work, seriously why?
     
  17. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,991
    Resources:
    12
    Models:
    5
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    12
    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.
     
  18. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    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?
     
  19. HerlySQR

    HerlySQR

    Joined:
    Jun 26, 2020
    Messages:
    208
    Resources:
    0
    Resources:
    0
    Ok I finally got it, thanks for your help.