• 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] Overcomplicated trigger

Status
Not open for further replies.
Level 7
Joined
May 3, 2007
Messages
210
JASS:
 method SetPriorities takes nothing returns nothing
            local integer p = GetPlayerId(Player(0))
            if ArrowLeft and not ArrowRight and not ArrowDown and not ArrowUp then
                set PriorityLeft = 4
                if ArrowRight and not ArrowDown and not ArrowUp then
                    set PriorityRight = 3
                        if ArrowDown and not ArrowUp then
                            set PriorityDown = 2
                            set PriorityUp = 1
                        else
                            set PriorityDown = 1
                            set PriorityUp = 2
                        endif
                elseif ArrowDown and not ArrowRight and not ArrowUp then
                    set PriorityDown = 3
                        if ArrowRight and not ArrowUp then
                            set PriorityRight = 2
                            set PriorityUp = 1
                        else
                            set PriorityRight = 1
                            set PriorityUp = 2
                        endif
                elseif ArrowUp and not ArrowRight and not ArrowDown then
                    set PriorityUp = 3
                        if ArrowDown and not ArrowRight then
                            set PriorityDown = 2
                            set PriorityRight = 1
                        else
                            set PriorityDown = 1
                            set PriorityRight = 2
                        endif
                endif
            elseif ArrowRight and not ArrowLeft and not ArrowDown and not ArrowUp then
                set PriorityRight = 4
                if ArrowLeft and not ArrowDown and not ArrowUp then
                    set PriorityLeft = 3
                        if ArrowDown and not ArrowUp then
                            set PriorityDown = 2
                            set PriorityUp = 1
                        else
                            set PriorityDown = 1
                            set PriorityUp = 2
                        endif
                elseif ArrowDown and not ArrowLeft and not ArrowUp then
                    set PriorityDown = 3
                        if ArrowLeft and not ArrowUp then
                            set PriorityLeft = 2
                            set PriorityUp = 1
                        else
                            set PriorityLeft = 1
                            set PriorityUp = 2
                        endif
                elseif ArrowUp and not ArrowLeft and not ArrowDown then
                    set PriorityUp = 3
                        if ArrowDown and not ArrowLeft then
                            set PriorityDown = 2
                            set PriorityLeft = 1
                        else
                            set PriorityDown = 1
                            set PriorityLeft = 2
                        endif
                endif
            elseif ArrowDown and not ArrowLeft and not ArrowRight and not ArrowUp then
                set PriorityDown = 4
                if ArrowRight and not ArrowLeft and not ArrowUp then
                    set PriorityRight = 3
                        if ArrowLeft and not ArrowUp then
                            set PriorityLeft = 2
                            set PriorityUp = 1
                        else
                            set PriorityLeft = 1
                            set PriorityUp = 2
                        endif
                elseif ArrowLeft and not ArrowRight and not ArrowUp then
                    set PriorityLeft = 3
                        if ArrowUp and not ArrowRight then
                            set PriorityUp = 2
                            set PriorityRight = 1
                        else
                            set PriorityUp = 1
                            set PriorityRight = 2
                        endif
                elseif ArrowUp and not ArrowRight and not ArrowLeft then
                    set PriorityUp = 3
                        if ArrowLeft and not ArrowRight then
                            set PriorityLeft = 2
                            set PriorityRight = 1
                        else
                            set PriorityLeft = 1
                            set PriorityRight = 2
                        endif
                endif
            elseif ArrowUp and not ArrowLeft and not ArrowRight and not ArrowDown then
                set PriorityUp = 4
                if ArrowRight and not ArrowDown and not ArrowLeft then
                    set PriorityRight = 3
                        if ArrowLeft and not ArrowDown then
                            set PriorityLeft = 2
                            set PriorityDown = 1
                        else
                            set PriorityLeft = 1
                            set PriorityDown = 2
                        endif
                elseif ArrowDown and not ArrowRight and not ArrowLeft then
                    set PriorityDown = 3
                        if ArrowLeft and not ArrowRight then
                            set PriorityLeft = 2
                            set PriorityRight = 1
                        else
                            set PriorityLeft = 1
                            set PriorityRight = 2
                        endif
                elseif ArrowLeft and not ArrowRight and not ArrowDown then
                    set PriorityLeft = 3
                        if ArrowDown and not ArrowRight then
                            set PriorityDown = 2
                            set PriorityRight = 1
                        else
                            set PriorityDown = 1
                            set PriorityRight = 2
                        endif
                endif
            endif
        endmethod

Assume there are 8 global array variables (4 of which boolean, the other 4 integers) (which there are in the grander scheme of the code). However, the problem is not that, but rather the horrendous approach I took in checking for every possible scenario.

This is what the code is designed to do (or at least what I tried to design it to do):

When called it will check whether or not an ArrowKey is down or not, True means the arrow key is down, false means it is up. If the arrow key is down, and it is the only one down, it gets the highest priority and keeps that priority until released. If another key is pressed while that key is being held, it gets a priority one below, and so on.

The point is to check every scenario of possible key combinations without extravagent and overused selection (as I have done).
 
Status
Not open for further replies.
Top