• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[AI] [JASS] How does this function work?

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
I'm reviewing AI scripts to try and understand how they work.

I see this function in the script and it "takes integer order" but I don't see "order" set anywhere else in the script. Where does this integer get set? Does my question make sense? Can anyone explain this?

JASS:
function SetHero takes integer order, integer heroid returns nothing
    if (order == 1) then
        set hero_id = heroid
        if (heroid == 'H01L') then
            set skills1[ 1] = ...
            set skills1[ 2] = ...
            set skills1[ 3] = ...
            ...

Thank you for any ideas.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,592
The function's (parameters) take an order in integer form and a hero id in integer form.

So the user must provide this information when calling the function:
vJASS:
call SetHero(order, heroid)
OR
  • Custom script: call SetHero(order, heroid)
These (parameters) act like local variables which can be referenced throughout the function, which you can see here:
vJASS:
if (order == 1) then
vJASS:
if (heroid == 'H01L') then
But maybe I'm misunderstanding.
 
Level 18
Joined
Mar 16, 2008
Messages
721
thank you for explaining that. the hero ID condition makes sense but there's no such piece of code anywhere in this script nor can i find anything referencing "function SetHero" in the API manual

there is no such code in this script:
JASS:
call SetHero(order, heroid)

just thinking out loud, don't feel obliged the read through all of this.

on this topic could I use a global variable as a condition?

i.e.
JASS:
if (heroid == globalvar) then

Anyway back to the main point of this thread: in the GUI AI editor, there are 3 different "orders" it will teach heroes abilities. I don't care to have variation of ability learn order in this script and it adds a lot of length to the script. I guess it's not that big of a deal though and maybe I could just conform to this format and make some variation.

JASS:
//===========================================================================
// Stores hero ID and skills
//===========================================================================
function SetHero takes integer order, integer heroid returns nothing
    if (order == 1) then
        set hero_id = heroid
        if (heroid == 'H01L') then
            set skills1[ 1] = KING_AURA         /// 1
            set skills1[ 2] = THUNDER_CLAP      /// 1
            set skills1[ 3] = KING_COURT        /// 1
            set skills1[ 4] = ROYAL_BANISH      /// 1
            set skills1[ 5] = KING_AURA         /// 2
            set skills1[ 6] = THUNDER_CLAP      /// 2
            set skills1[ 7] = KING_COURT        /// 2
            set skills1[ 8] = ROYAL_BANISH      /// 2
            set skills1[ 9] = KING_AURA         /// 3
            set skills1[10] = THUNDER_CLAP      /// 3
            set skills1[11] = KING_COURT        /// 3
            set skills1[12] = KING_AURA         /// 4
            set skills1[13] = KING_COURT        /// 4
            set skills1[14] = ROYAL_BANISH      /// 3   
        elseif (heroid == 'HC18') then
            ...
        elseif (heroid == 'H03I') then
            ...
        elseif (heroid == 'H01G') then
            ...
        elseif (heroid == 'Hpal') then
            ...
        elseif (heroid == 'H03J') then
            ...                                              
        endif
    elseif (order == 2) then
        set hero_id2 = heroid
        if (heroid == 'H01L') then
            set skills2[ 1] = ...
        elseif (heroid == 'HC18') then
            ...
        elseif (heroid == 'H03I') then
            ...
        elseif (heroid == 'H01G') then
            ...
        elseif (heroid == 'Hpal') then
            ...
        elseif (heroid == 'H03J') then
            ...
        endif
    elseif (order == 3) then
        set hero_id3 = heroid
        if (heroid == 'H01L') then
            set skills3[ 1] = ...
        elseif (heroid == 'HC18') then
            ...
        elseif (heroid == 'H03I') then
            ...
        elseif (heroid == 'H01G') then
            ...
        elseif (heroid == 'Hpal') then
            ...
        elseif (heroid == 'H03J') then
            ...
        endif
    endif
endfunction

//===========================================================================
// Returns the hero skill for the given hero and level
//===========================================================================
function ChooseHeroSkill takes nothing returns integer
    local integer curHero = GetHeroId()
    local integer level = GetHeroLevelAI()

    if (level > max_hero_level) then
        set max_hero_level = level
    endif

    if (curHero == hero_id) then
        return skills1[level]
    elseif (curHero == hero_id2) then
        return skills2[level]
    elseif (curHero == hero_id3) then
        return skills3[level]
    endif
    return 0
endfunction

Maybe I could just set the hero_id, hero_id2 variables in this section below???
JASS:
//===========================================================================
// Selects hero IDs for two possible heroes, nine king/prince combinations
//===========================================================================
function SelectHeroes takes nothing returns nothing
    local integer roll = GetRandomInt(1,9)
    if (roll == 1) then
        call SetHero( 1, 'H01G' )
        call SetHero( 2, 'H01L' )
    elseif (roll == 2) then
        call SetHero( 1, 'Hpal' )
        call SetHero( 2, 'H01L' )
    elseif (roll == 3) then
        call SetHero( 1, 'H03J' )
        call SetHero( 2, 'H01L' )
    elseif (roll == 4) then
        call SetHero( 1, 'H01G' )
        call SetHero( 2, 'HC18' )
    elseif (roll == 5) then
        call SetHero( 1, 'Hpal' )
        call SetHero( 2, 'HC18' )
    elseif (roll == 6) then
        call SetHero( 1, 'H03J' )
        call SetHero( 2, 'HC18' )
    elseif (roll == 7) then
        call SetHero( 1, 'H01G' )
        call SetHero( 2, 'H03I' )
    elseif (roll == 8) then
        call SetHero( 1, 'Hpal' )
        call SetHero( 2, 'H03I' )
    elseif (roll == 9) then
        call SetHero( 1, 'H03J' )
        call SetHero( 2, 'H03I' )
    endif
endfunction
 
Status
Not open for further replies.
Top