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

A problem with loops and dialogs (triggering)

Status
Not open for further replies.
Level 1
Joined
Feb 26, 2006
Messages
2
Hi, my name is 2evil, and if any of you have used the blizzard forum recently, you probably recognize me from all the questions that I have been posting :D

anyways, i have a part in my map that when a hero dies, the dead hero gets stored in a varible array (size:110) Thus, slots 1-10 are for player 1 and so on. All players can have up to 10 heros at once in the 'cache'.

I recently changed the way that the computer makes the dialog boxes to make it easier on myself when triggering (from 100 different triggers to 1 trigger with multiple parts) In this new problem I use lots of looping, which simplifies it greatly.

However, only the last killed hero now shows up (theres only one button) but once that one hero is res'd, the next killed one will pop up. It is supposed to show all killed heros, up to the max 10, if it needs to.

Here is the trigger and the task - I have looked thgis through many times and cannot find whats wrong with it...

thanks in advance for your help
2evil

Events
Unit - A unit enters ResB <gen>
Unit - A unit enters ResT <gen>

Conditions

Actions
Dialog - Clear Res_hero_diag
Dialog - Change the title of Res_hero_diag to ((|c + (Player_Colors[(Player number of (Triggering player))] + Your|r)) + dead Heroes)
For each (Integer B) from 1 to 10, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Integer B) Equal to 1
Then - Actions
For each (Integer A) from (Player_res_addons_array[(Integer B)] + 1) to (Player_res_addons_array[(Integer B)] + 10), do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 1
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 1)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[1] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 2
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 2)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[2] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 3
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 3)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[3] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 4
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 4)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[4] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 5
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 5)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[5] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 6
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 6)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[6] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 7
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 7)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[7] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 8
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 8)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[8] = (Last created dialog Button)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 9
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 9)
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r + (Name of Slain_Heros[(Integer A)])))))
Set Res_hero_diag_button[9] = (Last created dialog Button)
Else - Actions
Do nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Slain_Hero_Total[(Integer B)] Equal to 0
Slain_Hero_Total[(Integer B)] Equal to 1
Then - Actions
Dialog - Create a dialog button for Res_hero_diag labelled Nevermind
Set Res_hero_diag_button[0] = (Last created dialog Button)
Else - Actions
Do nothing
Else - Actions
Do nothing
Dialog - Show Res_hero_diag for (Owner of (Triggering unit))



Thanks again now that you made thru it :)
 
Level 7
Joined
Jul 30, 2004
Messages
451
i'm just gonna pre-format it for you, because reading non-indented material is hard on the eyes

and then i'll read it now

2evil said:
Code:
Events
    Unit - A unit enters ResB <gen>
    Unit - A unit enters ResT <gen>

Conditions

Actions
    Dialog - Clear Res_hero_diag
    Dialog - Change the title of Res_hero_diag to ((|c + (Player_Colors[(Player number of (Triggering player))] + Your|r)) +  dead Heroes)
    For each (Integer B) from 1 to 10, do (Actions)
        Loop - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Integer B) Equal to 1
                Then - Actions
                    For each (Integer A) from (Player_res_addons_array[(Integer B)] + 1) to (Player_res_addons_array[(Integer B)] + 10), do (Actions)
                        Loop - Actions
                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                If - Conditions
                                    Slain_Hero_Total[(Integer B)] Equal to 1
                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 1)
                                Then - Actions
                                    Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                    Set Res_hero_diag_button[1] = (Last created dialog Button)
                                Else - Actions
                                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        If - Conditions
                                            Slain_Hero_Total[(Integer B)] Equal to 2
                                            (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 2)
                                        Then - Actions
                                            Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                            Set Res_hero_diag_button[2] = (Last created dialog Button)
                                        Else - Actions
                                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                If - Conditions
                                                    Slain_Hero_Total[(Integer B)] Equal to 3
                                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 3)
                                                Then - Actions
                                                    Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                    Set Res_hero_diag_button[3] = (Last created dialog Button)
                                                Else - Actions
                                                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                        If - Conditions
                                                            Slain_Hero_Total[(Integer B)] Equal to 4
                                                            (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 4)
                                                        Then - Actions
                                                            Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                            Set Res_hero_diag_button[4] = (Last created dialog Button)
                                                        Else - Actions
                                                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                If - Conditions
                                                                    Slain_Hero_Total[(Integer B)] Equal to 5
                                                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 5)
                                                                Then - Actions
                                                                    Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                                    Set Res_hero_diag_button[5] = (Last created dialog Button)
                                                                Else - Actions
                                                                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                        If - Conditions
                                                                            Slain_Hero_Total[(Integer B)] Equal to 6
                                                                            (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 6)
                                                                        Then - Actions
                                                                            Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                                            Set Res_hero_diag_button[6] = (Last created dialog Button)
                                                                        Else - Actions
                                                                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                                If - Conditions
                                                                                    Slain_Hero_Total[(Integer B)] Equal to 7
                                                                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 7)
                                                                                Then - Actions
                                                                                    Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                                                    Set Res_hero_diag_button[7] = (Last created dialog Button)
                                                                                Else - Actions
                                                                                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                                        If - Conditions
                                                                                            Slain_Hero_Total[(Integer B)] Equal to 8
                                                                                            (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 8)
                                                                                        Then - Actions
                                                                                            Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                                                            Set Res_hero_diag_button[8] = (Last created dialog Button)
                                                                                        Else - Actions
                                                                                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                                                                If - Conditions
                                                                                                    Slain_Hero_Total[(Integer B)] Equal to 9
                                                                                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 9)
                                                                                                Then - Actions
                                                                                                    Dialog - Create a dialog button for Res_hero_diag labelled (((|c + Player_Colors[(Integer B)]) + (Proper name of Slain_Heros[(Integer A)])) + (|r - Level |c00FFD700 + ((String((Hero level of Slain_Heros[(Integer A)]))) + (|r  + (Name of Slain_Heros[(Integer A)])))))
                                                                                                    Set Res_hero_diag_button[9] = (Last created dialog Button)
                                                                                                Else - Actions
                                                                                                    Do nothing
                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                If - Conditions
                                    Slain_Hero_Total[(Integer B)] Equal to 0
                                    Slain_Hero_Total[(Integer B)] Equal to 1
                                Then - Actions
                                    Dialog - Create a dialog button for Res_hero_diag labelled Nevermind
                                    Set Res_hero_diag_button[0] = (Last created dialog Button)
                                Else - Actions
                                    Do nothing
                Else - Actions
                    Do nothing
    Dialog - Show Res_hero_diag for (Owner of (Triggering unit))



Thanks again now that you made thru it  :)
 
Level 7
Joined
Jul 30, 2004
Messages
451
uhm, ok your loops are really weird and don't make a lot of sense how they're setup, but i'm assuming

Slain_Hero_Total[(Integer B)]

doesn't change throughout the entire loop process, so as Integer A counts through (Player_res_addons_array[(Integer B)] + 1) to (Player_res_addons_array[(Integer B)] + 10), it will only satisfy a single of the if-block conditions

if you want an example, suppose Slain_Hero_Total[1] = 2

then it'll get to IntA loop and go to the first if:

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions) 
                                If - Conditions 
                                    Slain_Hero_Total[(Integer B)] Equal to 1 
                                    (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 1)

slain_hero_total doesn't = 1, so it continues to the else,

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions) 
                                        If - Conditions 
                                            Slain_Hero_Total[(Integer B)] Equal to 2 
                                            (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 2)

slain_hero_total = 2 HOWEVER
(Integer A) does not equal (Player_res_addons_array[(Integer B)] + 2)
-- -- (it equals Player_res_addons_array[(Integer B)] + 1)

so it skips over this if and continues, the rest are arbitrary conditions, since slain_hero_total is clearly less than all the checks

now, the loop will increment IntA to "(Player_res_addons_array[(Integer B)] + 2)"

again, the first if will fail since slain_hero_total is 2, and when we get to the second if,

slain_hero_total = 2 AND
(Integer A) = (Player_res_addons_array[(Integer B)] + 2)

so it will add one button

the rest again are arbitrary conditions,

now intA will become (Player_res_addons_array[(Integer B)] + 3)

now clearly the only if that will run is when slain_hero_total = 2, but from now on intA will never be (Player_res_addons_array[(Integer B)] + 2) so no if blocks will run after that


IF you count up everytime a button was made you'll see it equates to 1
now, if you try this thought experiment again with any other value of slain_heros_total you will find a total of ONE button will ever be made

QED
 
Level 1
Joined
Feb 26, 2006
Messages
2
loop concept

Perhaps my concept of what a loop is wrong then. Does it not(loop A 1-10) run the function 10 times, with the (loop a) variable changing each time?

Let me explain the variables associated with the trigger and my reason behind each trigger.

Slain_Hero_Total - This is a 10 size array that stores how many heros each player currently has dead. Slain_Hero_Total[1]=red, Slain_Hero_Total[2]=blue, and so forth
Slain_Heros - This is a 110 size unit array that stores the slain heros. 1-10 is reserved for red, 11-20 for blue, and so forth.

Player_res_addons_array - Another size 10 array that stores the number 0 for red (slot 1), 10 for blue, 20 for player 3... I have this to that when I write a long trigger like this, it can be universal so that all I have to do is write this
Code:
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 2) 
or
(Integer A) Equal to (Player_res_addons_array[(Integer B)] + 3)
to adjust to the fact that player 2 has slots 11-20, while player 5 has 41-50. Without this, I waould have to manually edit each trigger multiple times, when now I just have to change this:
If - Conditions
(Integer B) Equal to 1

Its just cause I'm lazy :D

My Loops
Loop A = Looping 110 hero array. Only certain portions are looped at once (hence the For each (Integer A) from (Player_res_addons_array[(Integer B)] + 1) to (Player_res_addons_array[(Integer B)] + 10), do (Actions)
Loop B = Looping 10 Player Array. Wherever (loop a) shows up, it means player a. the a is defined farther up in the trigger


My ultimate goal for this trigger was to make one that when duplicated, only one value had to change. This was suggested to me because I did not want to make 100 triggers.

I hope that cleared some stuff up and thanks!
2evil
 
Level 7
Joined
Jul 30, 2004
Messages
451
ok, let me try explaining this again

on only one passby of the loop for a given player, (Integer A) Equal to (Player_res_addons_array[(Integer B)] + X) will be true for each X

on only one passby of the loop for a given player, Slain_Hero_Total[(Integer B)] Equal to X will be true for a single X value (ie, 1, 2, 3, ...)

suppose i use the same example, slain_total_hero[1] = 2

suppose loop B starts at B=1

<<i'm gonna iterate what the computer is saying as it goes through the trigger>>

then loop A starts at A=0 (for the sake of argument, i'm using A as 0 to 10)

now we enter the first if statement @ A=0 B=1

check: slain_hero_total[B=1] = 1 <-- NOT TRUE
::discontinue if-check
goto else

second if statement @ A=0 B=1
check: slain_hero_total[B=1] = 2 <-- TRUE
check: A=0 is equal to 1 <-- NOT TRUE

<<note, the 1 comes from (Integer A) Equal to (Player_res_addons_array[(Integer B)] + 2), since i used the assumption that we start at 0 with (Player_res_addons_array[(Integer B)] + 1) = 0>>

goto else

third if statement @ A=0 B=1
check: slain_hero_total[B=1] = 3 <-- NOT TRUE
::discontinue if-check

<<note, from this point on, slain_hero_total[B=1] will be LESS THAN whatever it is checking against, so there is no point in showing the rest of the if blocks, they will all follow the formula of the previous i just wrote>>

thus we get to the end and do nothing

so loop A itterates to A=1

now we enter the first if statement @ A=1 B=1

check: slain_hero_total[B=1] = 1 <-- NOT TRUE
::discontinue if-check
goto else

second if statement @ A=1 B=1
check: slain_hero_total[B=1] = 2 <-- TRUE
check: A=1 is equal to 1 <-- TRUE

create dialog button for 1 hero at this point

thus we are done with this since no elses are ran

so loop A itterates to A=2

now we enter the first if statement @ A=2 B=1

check: slain_hero_total[B=1] = 1 <-- NOT TRUE
::discontinue if-check
goto else

second if statement @ A=2 B=1
check: slain_hero_total[B=1] = 2 <-- TRUE
check: A=2 is equal to 1 <-- NOT TRUE
goto else

third if statement @ A=2 B=1
check: slain_hero_total[B=1] = 3 <-- NOT TRUE
::discontinue if-check

<<note, from this point on again, slain_hero_total[B=1] will be LESS THAN whatever it is checking against, so there is no point in showing the rest of the if blocks--this too will end in do nothing>>

so loop A itterates to A=3

now we enter the first if statement @ A=3 B=1

check: slain_hero_total[B=1] = 1 <-- NOT TRUE
::discontinue if-check
goto else

second if statement @ A=3 B=1
check: slain_hero_total[B=1] = 2 <-- TRUE
check: A=3 is equal to 1 <-- NOT TRUE
goto else

third if statement @ A=3 B=1
check: slain_hero_total[B=1] = 3 <-- NOT TRUE
::discontinue if-check

<<note, i hope you can see at this point we will never create another dialog button for this player>>


now what is the end result? well i have bolded the total dialog buttons created, but suppose you have 5 slain heroes, then it will create a button for Slain_hero_total[Player] = 5, and ONLY for hero 5, so there will be 1 button for the latest hero that died

i'm certain when you res him you reduce slain heroes by 1, so slain_hero_total[player] = 4 and when the dialog is shown again there will be a button for ONLY hero 4

etc...

and also

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions) 
                                If - Conditions 
                                    Slain_Hero_Total[(Integer B)] Equal to 0 
                                    Slain_Hero_Total[(Integer B)] Equal to 1 
                                Then - Actions 
                                    Dialog - Create a dialog button for Res_hero_diag labelled Nevermind 
                                    Set Res_hero_diag_button[0] = (Last created dialog Button) 
                                Else - Actions 
                                    Do nothing

will never occur, think about it, how is slain_hero_total ever going to be 0 and 1 at the same time?
 
Status
Not open for further replies.
Top