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

Basics - Variable Arrays

Status
Not open for further replies.
Level 2
Joined
Jul 12, 2018
Messages
17

Task

Code



Create a (JASS) trigger that runs when a player presses the 'Esc' button (Skip Cinematic).
The trigger's goal is to count how often a player has hit the 'Esc' button, and to print the correct value on screen.
The trigger must be MPI (tip: always search for things you don't know Elemental Coder Guide).



If you don't already have done so, do now the "Part 2" without using any "if statement".
Tip: Each player has a unique player number.



JASS:
scope Part1n2 initializer init
    globals
        integer array Counter 
    endglobals
   
    private function main takes nothing returns nothing
        local integer id = GetPlayerId(GetTriggerPlayer())
       
        set Counter[id] = Counter[id] + 1
       
        call ClearTextMessages()
        call BJDebugMsg("You've hit esc " + I2S(Counter[id]) + " time(s)")
    endfunction
   
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
       
        loop
            exitwhen i >= bj_MAX_PLAYERS
            call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_END_CINEMATIC)
            set  i = i + 1
        endloop
       
        call TriggerAddAction(t, function main)
    endfunction
endscope

 

Attachments

  • [Crash Course] Basics - Variable Array.w3m
    23.5 KB · Views: 65
Status
Not open for further replies.
Top