• 🏆 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!

[Solved] Simple Message Function from JASS tutorial

Status
Not open for further replies.
Level 2
Joined
Dec 28, 2017
Messages
19
I can't even get this simple function to work. I've taken it from a Intro to JASS. I just want the the message to appear.

JASS:
function Trig_Melee_Initialization_Actions takes nothing returns nothing
    call MeleeStartingVisibility(  )
    call MeleeStartingHeroLimit(  )
    call MeleeGrantHeroItems(  )
    call MeleeStartingResources(  )
    call MeleeClearExcessUnits(  )
    call MeleeStartingUnits(  )
    call MeleeStartingAI(  )
    call MeleeInitVictoryDefeat(  )
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction
function HelloWorld takes nothing returns nothing
    call BJDebugMsg("Hi, my name is Bob.")
    call BJDebugMsg("I am 2 years old!")
    //And so on, by the way you can add comments to your code like this
    //Basically if you have '//' somewhere on a line, the rest of the line (after the '//') counts as a comment
endfunction

Nothing happens when I run the test on the map. Is there a certain way you have to put it in, do I erase something. How does the message appear?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
you have to call the function.
At the beginning of the map the trigger "Melee Initialization" is created. This is what the function InitTrig_Melee_Initialization does. It is automatically called by the game.
You probably have "run on map initialization" enabled, so the trigger will then be executed and run its actions.
The action here is the function "Trig_Melee_Initialization_Actions".

However the function HelloWorld is never used. You can just call it in the actions function:
JASS:
function Trig_Melee_Initialization_Actions takes nothing returns nothing
    call MeleeStartingVisibility(  )
    call MeleeStartingHeroLimit(  )
    call MeleeGrantHeroItems(  )
    call MeleeStartingResources(  )
    call MeleeClearExcessUnits(  )
    call MeleeStartingUnits(  )
    call MeleeStartingAI(  )
    call MeleeInitVictoryDefeat(  )
    call HelloWorld()
endfunction

However in Jass when you call a function, the called function must be declared above. In the end you should have:
JASS:
function HelloWorld takes nothing returns nothing
    call BJDebugMsg("Hi, my name is Bob.")
    call BJDebugMsg("I am 2 years old!")
    //And so on, by the way you can add comments to your code like this
    //Basically if you have '//' somewhere on a line, the rest of the line (after the '//') counts as a comment
endfunction

function Trig_Melee_Initialization_Actions takes nothing returns nothing
    call MeleeStartingVisibility(  )
    call MeleeStartingHeroLimit(  )
    call MeleeGrantHeroItems(  )
    call MeleeStartingResources(  )
    call MeleeClearExcessUnits(  )
    call MeleeStartingUnits(  )
    call MeleeStartingAI(  )
    call MeleeInitVictoryDefeat(  )
    call HelloWorld()
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction
 
Level 2
Joined
Dec 28, 2017
Messages
19
A-HA. Now I get it. I just forgot to add that *call HelloWorld() line into the script. I guess the way the tutorial worded it confused me. I kept reading it over and over but for some reason it did not click. Thanks!! I'm a visual person so when you actually gave me a visual of the script, made perfect sense. Now if I had a custom map that did not have the trigger for typical melee ai, how different would that look?

Beginning JASS Tutorial Series <-tutorial if you cared
 
Level 2
Joined
Dec 28, 2017
Messages
19
Sounds good to me, I've been just using GUI and converting into custom text and learning it on JASSCRAFT. It's okay but still confusing. Been working on this for awhile now!
 
Level 2
Joined
Dec 28, 2017
Messages
19
Do you use just regular old Jasscraft? I've seen it is outdated and there are better modding tools. I downloaded Sharpcraft but it does not work for me.
 
Status
Not open for further replies.
Top