• 🏆 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] Checking AI Difficulity problem (+rep to be given)

Status
Not open for further replies.
Level 9
Joined
Jul 24, 2007
Messages
308
hello. i have this trigger, when i run the map it shows NOTHING.

JASS:
function PutToArrays takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>11
               if (GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER ) then
        if GetAIDifficulty(Player(i))==AI_DIFFICULTY_NEWBIE then
            set udg_PlayerIsEasy[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Easy!" ) )
        elseif GetAIDifficulty(Player(i))==AI_DIFFICULTY_NORMAL then
            set udg_PlayerIsNormal[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Normal!" ) )
        elseif GetAIDifficulty(Player(i))==AI_DIFFICULTY_INSANE then
            set udg_PlayerIsInsane[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Insane!" ) )
        endif
        endif
        set i=i+1
    endloop
endfunction


//===========================================================================
function InitTrig_TEMP takes nothing returns nothing
    set gg_trg_TEMP = CreateTrigger(  )
    call TriggerAddAction( gg_trg_TEMP, function PutToArrays )
    call TriggerRegisterTimerEventSingle( gg_trg_TEMP, 2.01 )
endfunction
 
Mmm, First, try correction you identation, it is hard to understand your code.
Second, if nothing happens then it is because you skipped all ifs ... Your conditions are surely wrong... I don't remind seeing computer level "newbie"...
Anyway, try also using BJDebugMsg("text). It will display a text and is actually good for debugging, which is your trouble.
 
Level 9
Joined
Jul 24, 2007
Messages
308
allright
What i want is to check each AI player (computer player) difficulity (or level), and set them in a global variable.
i tried many ways and it didnt work

for this trigger, nothing displays, when i removed the first condition "if (GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER ) then" it displayed all users are Normal AI Players (even unused slots).

thats enough explaining?
 
JASS:
function PutToArrays takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>11
            if (GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER ) then
                call BJDebugMsg("I am computer" + I2S(i))
            endif
        set i=i+1
    endloop
endfunction

Your report seems quite strange. Try running this small test to see if all slots are visited correctly.
If not, then we know where our problem really is.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I have the suspicion that MAP_CONTROL_USER is not what you think it is :D
I will just check this.
My bad - it is.
I wounder are your "computer" players defined as computer players in the Player settings?
 
Level 11
Joined
Feb 18, 2004
Messages
394
hello. i have this trigger, when i run the map it shows NOTHING.

JASS:
function PutToArrays takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>11
               if (GetPlayerController(Player(i))==MAP_CONTROL_COMPUTER ) then
        if GetAIDifficulty(Player(i))==AI_DIFFICULTY_NEWBIE then
            set udg_PlayerIsEasy[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Easy!" ) )
        elseif GetAIDifficulty(Player(i))==AI_DIFFICULTY_NORMAL then
            set udg_PlayerIsNormal[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Normal!" ) )
        elseif GetAIDifficulty(Player(i))==AI_DIFFICULTY_INSANE then
            set udg_PlayerIsInsane[i] = true
            call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(Player(i)) + " Insane!" ) )
        endif
        endif
        set i=i+1
    endloop
endfunction


//===========================================================================
function InitTrig_TEMP takes nothing returns nothing
    set gg_trg_TEMP = CreateTrigger(  )
    call TriggerAddAction( gg_trg_TEMP, function PutToArrays )
    call TriggerRegisterTimerEventSingle( gg_trg_TEMP, 2.01 )
endfunction

Cleaned up your code:
JASS:
function PutToArrays takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i > 11
        if GetPlayerController(Player(i)) == MAP_CONTROL_COMPUTER then
            if GetAIDifficulty(Player(i)) == AI_DIFFICULTY_NEWBIE then
                set udg_PlayerIsEasy[i] = true
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(i)) + " Easy!")
            elseif GetAIDifficulty(Player(i)) == AI_DIFFICULTY_NORMAL then
                set udg_PlayerIsNormal[i] = true
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(i)) + " Normal!")
            elseif GetAIDifficulty(Player(i)) == AI_DIFFICULTY_INSANE then
                set udg_PlayerIsInsane[i] = true
                call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(i)) + " Insane!")
            endif
        endif
        set i = i + 1
    endloop
endfunction

function InitTrig_TEMP takes nothing returns nothing
    set gg_trg_TEMP = CreateTrigger()
    call TriggerAddAction(gg_trg_TEMP, function PutToArrays)
    call TriggerRegisterTimerEvent(gg_trg_TEMP, 2.01, false)
endfunction
Works fine as far as I can see... displays the proper AI difficulties for all computer-controlled slots.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Hm that is I said if it is no problem.
Map is at begging - no problem.
Map has stuff in it - problem
To prevent abuse a Personal message to someone trusted is recommended.
 
Are you sure everything is Ok ?
Because when i ran the map in WE nothing happened :S

Found 3 problems when debugging:
1 - The name of your trigger doesn't match the call function. Your trigger is called TEMP copy 2, but the function is calling TEMP - an error should occur here

2 - You have something in the map's header that is conflicting with the trigger, thus making it not be fired: Since map's header is the only trigger working, deleting it will make the TEMP copy 2 trigger be fired.

3 - Finally, your conditions seem to be all wrong, because although the loop is started, it skips all If's. Why ? dunno...

Also you should work on your identation ... it is horrible to understand code like that...
 
Status
Not open for further replies.
Top