• 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.

[JASS] Looping over players

Status
Not open for further replies.

eejin

Tool Moderator
Level 12
Joined
Mar 6, 2017
Messages
234
Hi, i was wondering why the following snippet doesn't seem to work. I'd expect it to work for all players, but it doesn't seem to do anything.

Code:
function Trig_Add_Strength_Actions takes nothing returns nothing
    call DisplayTextToPlayer(Player(0),0,0,"You just pressed ESC")
endfunction

//===========================================================================
function InitTrig_Add_Strength takes nothing returns nothing
    local integer i = 0
    set gg_trg_Untitled_Trigger_001_Copy = CreateTrigger()
    loop
        exitwhen (i > 9)
        set i = i + 1
        call TriggerRegisterPlayerChatEvent( gg_trg_Untitled_Trigger_001_Copy, Player(i), "-str", false )
    endloop
    call TriggerAddAction( gg_trg_Untitled_Trigger_001_Copy, function Trig_Untitled_Trigger_001_Copy_Actions )
endfunction

Also I get this syntax error, but it works fine ingame:

0101yt8
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Also I get this syntax error, but it works fine ingame:
Any syntax error means it will not work fine in game as the map script failed to build properly or certain triggers have been forcefully disabled.

The syntax error points towards you having renamed some custom script GUI trigger elements without changing the standard function and variable names to match the new trigger. As such the map initialization function might be failing to call the trigger initialization function, the initialization functions might be defined twice which is not valid JASS, or a variable that does not exist is accessed.

The error you are showing does not translate to the trigger you posted above. It is showing a completely different trigger.
 

eejin

Tool Moderator
Level 12
Joined
Mar 6, 2017
Messages
234
The error you are showing does not translate to the trigger you posted above. It is showing a completely different trigger.

Yes the error is for the same function but then written without the loop. I was a unclear about that.


Code:
function Trig_Add_Strength_Actions takes nothing returns nothing
    call DisplayTextToPlayer(Player(0),0,0,SubString(GetEventPlayerChatString(), 5, StringLength(GetEventPlayerChatString())))
endfunction

//===========================================================================
function InitTrig_Add_Strength takes nothing returns nothing
    local integer i = 0
    set gg_trg_Add_Strength = CreateTrigger()
    loop
        exitwhen (i > 9)
        call TriggerRegisterPlayerChatEvent( gg_trg_Add_Strength, Player(i), "-str", false )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_Add_Strength, function Trig_Add_Strength_Actions )
endfunction

It works as that it displays anything behind the "-str", but it stil gives me:
02amqnp


Btw, is there a better way to do chat commands? It seems like there should be some built in functionailty for it, but I can't find it.
 
Status
Not open for further replies.
Top