[Solved] Help with Hashtable loading of AbilityNumber of player

Level 5
Joined
Jun 24, 2024
Messages
59
Hi again,

i am stuck on a problem for quite a while now and want to ask, where i am doing wrong / take a wrong turn.

Following trigger part creates an entry into a hashtable:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • temp_bol Equal to False
    • Then - Actions
      • Unit - Add temp_Abilities[(Integer B)] to (Hero manipulating item)
      • Hashtable - Save (Name of temp_Abilities[(Integer B)]) as (Integer B) of (Player number of (Owner of (Hero manipulating item))) in Hotkey_Htable.
      • Set VariableSet maxabilities_counter[(Player number of (Owner of (Hero manipulating item)))] = (maxabilities_counter[(Player number of (Owner of (Hero manipulating item)))] + 1)
      • Set VariableSet retraining_levelof_Ability[(Player number of (Owner of (Hero manipulating item)))] = 1
      • Set VariableSet retraining_Ability[(Player number of (Owner of (Hero manipulating item)))] = temp_Abilities[(Integer B)]
      • Set VariableSet retraining_item_type[(Player number of (Owner of (Triggering unit)))] = (Item-type of (Item being manipulated))
      • Hashtable - Save temp_integr[(Integer B)] as (Integer B) of (Player number of (Owner of (Hero manipulating item))) in maxabilities.
      • Custom script: call AddAbility(GetTriggerPlayer(), bj_forLoopBIndex+1, udg_temp_Abilities[bj_forLoopBIndex])
      • Skip remaining actions
    • Else - Actions
With this, maxabilities now knows the learned ability id setup in another trigger.

This is a working upgrade trigger, but it only works for Player 1

  • Upgrade Ability
    • Events
    • Conditions
    • Actions
      • -------- Create Button --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • reward_chosenbutton_num Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • maxabilities_counter[(Player number of Player 1 (Red))] Greater than 0
            • Then - Actions
              • Set VariableSet temp_num = 0
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)] for NICKHeroArray[1]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)] for NICKHeroArray[1]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Abilities_1[temp_num] = Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)]
                      • Set VariableSet temp_num = (temp_num + 1)
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • temp_num Greater than 0
                • Then - Actions
                  • Set VariableSet reward_list_randomnum[r_temp_num] = (Random integer number between 1 and 2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • reward_list_randomnum[r_temp_num] Equal to 1
                    • Then - Actions
                      • Set VariableSet chance = (Random integer number between 0 and (temp_num - 1))
                      • Set VariableSet reward_list_randomnum[r_temp_num] = chance
                      • Set VariableSet temp_Ability = temp_Abilities_1[chance]
                      • Dialog - Create a dialog button for reward_dialog labelled (|cffffff00Upgrade + (Substring((Name of temp_Ability), 1, ((Length of (Name of temp_Ability)) - 2))))
                      • Set VariableSet reward_dialog_button[r_temp_num] = (Last created dialog Button)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • reward_list_randomnum[r_temp_num] Equal to 2
                        • Then - Actions
                          • Dialog - Create a dialog button for reward_dialog labelled |cffffff00Upgrade A...
                          • Set VariableSet reward_dialog_button[r_temp_num] = (Last created dialog Button)
                        • Else - Actions
                • Else - Actions
                  • Set VariableSet r_temp_num = (r_temp_num - 1)
            • Else - Actions
              • Set VariableSet r_temp_num = (r_temp_num - 1)
        • Else - Actions
          • -------- Click Button --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnum[reward_chosenbutton_num] Equal to 1
            • Then - Actions
              • Set VariableSet temp_Ability = Hotkey_Abilities[(Load reward_list_randomnum[reward_chosenbutton_num] of (Player number of Player 1 (Red)) from maxabilities.)]
              • Unit - Increase level of temp_Ability for NICKHeroArray[(Player number of Player 1 (Red))]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnum[reward_chosenbutton_num] Equal to 2
            • Then - Actions
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)] for NICKHeroArray[1]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)] for NICKHeroArray[1]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Ability = Hotkey_Abilities[(Load (Integer A) of (Player number of Player 1 (Red)) from maxabilities.)]
                      • Unit - Increase level of temp_Ability for NICKHeroArray[(Player number of Player 1 (Red))]
                    • Else - Actions
            • Else - Actions
Trying to create a copy trigger for player 2, i have pretty much everything set up correctly like in other similar triggers.
I do not know how to set up the If condition for the ability count check to fit player 2, it always goes into the else and throws the error:

"""
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Greater than 0
    • Then - Actions
      • Set VariableSet temp_Abilities_2[r_temp_num_2] = Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)]
      • Set VariableSet temp_num_2 = (temp_num_2 + 1)
    • Else - Actions
      • Game - Display to (All players) the text: ERROR creating Butt...
"""
Am i mistaking the "(Integer A) of "2"" as a player number? What else could go wrong here?

Edit:

Here the full trigger of "Upgrade Ability player 2"
Yes, i make variables and triggers per player. I've tried countless times to unify it along with dialog boxes,
but those dialog boxes seem way to clunky for me to work with a unified/neutralized system.. Or i'm lacking exp.
Either way, maybe you find, what i missed to set up correctly here.

  • Upgrade Ability 2
    • Events
    • Conditions
    • Actions
      • -------- Create Button --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • reward_chosenbutton_num_2 Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • maxabilities_counter[(Player number of Player 2 (Blue))] Greater than 0
            • Then - Actions
              • Set VariableSet temp_num_2 = 0
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Abilities_2[r_temp_num_2] = Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)]
                      • Set VariableSet temp_num_2 = (temp_num_2 + 1)
                    • Else - Actions
                      • Game - Display to (All players) the text: ERROR creating Butt...
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • temp_num_2 Greater than 0
                • Then - Actions
                  • Set VariableSet reward_list_randomnum_2[r_temp_num_2] = (Random integer number between 1 and 2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • reward_list_randomnum_2[r_temp_num_2] Equal to 1
                    • Then - Actions
                      • Set VariableSet chance_2 = (Random integer number between 0 and (temp_num_2 - 1))
                      • Set VariableSet reward_list_randomnum_2[r_temp_num_2] = chance_2
                      • Set VariableSet temp_Ability_2 = temp_Abilities_2[chance_2]
                      • Dialog - Create a dialog button for reward_dialog_2 labelled (|cffffff00Upgrade + (Substring((Name of temp_Ability_2), 2, ((Length of (Name of temp_Ability_2)) - 2))))
                      • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • reward_list_randomnum_2[temp_int_2] Equal to 2
                        • Then - Actions
                          • Dialog - Create a dialog button for reward_dialog_2 labelled |cffffff00Upgrade A...
                          • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                        • Else - Actions
                          • Game - Display to (All players) the text: ERROR creating Butt...
                • Else - Actions
                  • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
            • Else - Actions
              • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
        • Else - Actions
          • -------- Click Button --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnum_2[reward_chosenbutton_num_2] Equal to 1
            • Then - Actions
              • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load reward_list_randomnum_2[reward_chosenbutton_num_2] of (Player number of Player 2 (Blue)) from maxabilities.)]
              • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
            • Else - Actions
              • Game - Display to (All players) the text: ERROR on Button Pre...
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnum_2[reward_chosenbutton_num_2] Equal to 2
            • Then - Actions
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)]
                      • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
                    • Else - Actions
                      • Game - Display to (All players) the text: ERROR on Button Pre...
            • Else - Actions
              • Game - Display to (All players) the text: ERROR in Button Pre...

Thanks in advance
SMOrc
 
Last edited:
Level 12
Joined
Nov 13, 2010
Messages
277
as i see it the problem for player 2 is that when loading you need to Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities
then you need to update this --> Load (Integer A) of 2 from maxabilities to --> Load 2 of (Integer A) from maxabilities or you can do --> Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities
and then we need to replace (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) with ths --> (Level of Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)] for NICKHeroArray[2])
 
Level 5
Joined
Jun 24, 2024
Messages
59
Well that wasn't quite it, tho some Loads have to happen with player number, some wont work with them but will with a "Load 1" or "Load 2".

Here is the updated trigger, it now almost works. It will show the correct ability as a button event to suggest a upgrade but it either does nothing or will upgrade all abilities that come before it, e.g. Abilities in the slots: QWERDFG - Pick Ability R to upgrade, upgrades QWE... Wierd behavior..

  • Upgrade Ability 2
    • Events
    • Conditions
    • Actions
      • -------- Create Button --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • reward_chosenbutton_num_2 Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • maxabilities_counter[(Player number of Player 2 (Blue))] Greater than 0
            • Then - Actions
              • Set VariableSet temp_num_2 = 0
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Abilities_2[r_temp_num_2] = Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)]
                      • Set VariableSet temp_num_2 = (temp_num_2 + 1)
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • temp_num_2 Greater than 0
                • Then - Actions
                  • Set VariableSet reward_list_randomnumP2_1[r_temp_num_2] = (Random integer number between 1 and 2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • reward_list_randomnumP2_1[r_temp_num_2] Equal to 1
                    • Then - Actions
                      • Set VariableSet chance_2 = (Random integer number between 0 and (temp_num_2 - 1))
                      • Set VariableSet reward_list_randomnumP2_1[r_temp_num_2] = chance_2
                      • Set VariableSet temp_Ability_2 = temp_Abilities_2[chance_2]
                      • Dialog - Create a dialog button for reward_dialog_2 labelled (|cffffff00Upgrade + (Substring((Name of temp_Ability_2), 1, ((Length of (Name of temp_Ability_2)) - 2))))
                      • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • reward_list_randomnumP2_1[temp_int_2] Equal to 2
                        • Then - Actions
                          • Dialog - Create a dialog button for reward_dialog_2 labelled |cffffff00Upgrade A...
                          • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                        • Else - Actions
                • Else - Actions
                  • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
            • Else - Actions
              • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
        • Else - Actions
          • -------- Click Button --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnumP2_1[reward_chosenbutton_num_2] Equal to 1
            • Then - Actions
              • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load reward_list_randomnumP2_1[reward_chosenbutton_num_2] of (Player number of Player 2 (Blue)) from maxabilities.)]
              • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnumP2_1[reward_chosenbutton_num_2] Equal to 2
            • Then - Actions
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)]
                      • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
                    • Else - Actions
            • Else - Actions
---
Edit:

It now with this exact trigger shows the button text as "upgrade "efault str"" as in Default string, so there is something amiss.
It upgrades every ability as well so it seems to go into the wrong if statement..

Edit 2:

In another test case i got a Upgrade window for Ability in slot G but it upgraded the ability in slot W..
 
Last edited:
Level 5
Joined
Jun 24, 2024
Messages
59
Hi Nichilus,

kind of, yes. Every player will own only one singular hero unit. This unit will learn abilities via Reward dialog prompts.
These learned abilities are not deletable or changeable.

The current trigger version:

  • Upgrade Ability 2
    • Events
    • Conditions
    • Actions
      • -------- Create Button --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • reward_chosenbutton_num_2 Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • maxabilities_counter[(Player number of Player 2 (Blue))] Greater than 0
            • Then - Actions
              • Set VariableSet temp_num_2 = 0
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Abilities_2[r_temp_num_2] = Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)]
                      • Set VariableSet temp_num_2 = (temp_num_2 + 1)
                    • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • temp_num_2 Greater than 0
                • Then - Actions
                  • Set VariableSet reward_list_randomnumP2_1[r_temp_num_2] = (Random integer number between 1 and 2)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • reward_list_randomnumP2_1[r_temp_num_2] Equal to 1
                    • Then - Actions
                      • Set VariableSet chance_2 = (Random integer number between 0 and (temp_num_2 - 1))
                      • Set VariableSet reward_list_randomnumP2_1[r_temp_num_2] = chance_2
                      • Set VariableSet temp_Ability_2 = temp_Abilities_2[chance_2]
                      • Dialog - Create a dialog button for reward_dialog_2 labelled (|cffffff00Upgrade + (Substring((Name of temp_Ability_2), 1, ((Length of (Name of temp_Ability_2)) - 2))))
                      • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • reward_list_randomnumP2_1[temp_int_2] Equal to 2
                        • Then - Actions
                          • Dialog - Create a dialog button for reward_dialog_2 labelled |cffffff00Upgrade A...
                          • Set VariableSet reward_dialog_button_2[r_temp_num_2] = (Last created dialog Button)
                        • Else - Actions
                • Else - Actions
                  • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
            • Else - Actions
              • Set VariableSet r_temp_num_2 = (r_temp_num_2 - 1)
        • Else - Actions
          • -------- Click Button --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnumP2_1[reward_chosenbutton_num_2] Equal to 1
            • Then - Actions
              • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load reward_list_randomnumP2_1[reward_chosenbutton_num_2] of (Player number of Player 2 (Blue)) from maxabilities.)]
              • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • reward_list_randomnumP2_1[reward_chosenbutton_num_2] Equal to 2
            • Then - Actions
              • For each (Integer A) from 0 to 6, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)] for NICKHeroArray[2]) Less than or equal to 9
                      • (Level of Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)] for NICKHeroArray[2]) Greater than 0
                    • Then - Actions
                      • Set VariableSet temp_Ability_2 = Hotkey_Abilities[(Load (Integer A) of (Player number of Player 2 (Blue)) from maxabilities.)]
                      • Unit - Increase level of temp_Ability_2 for NICKHeroArray[(Player number of Player 2 (Blue))]
                    • Else - Actions
            • Else - Actions
The map, not protected - you can check out the triggers way at the bottom in "Reward Options":


After more vigorous testing with a friend, the following happened:
In 70% of cases player two got an ability upgrade offer, the string was printed correctly and the ability upgraded on button press.
in 30% of cases player two got "upgrade "default stri"" and the button press event did nothing.
 
Last edited:
Level 29
Joined
Sep 26, 2009
Messages
2,594
I had to do a text comparison between Upgrade ability and Upgrade ability 2 triggers from your original post, I think similar mistakes are also in your latest version.

In "Upgrade ability" you do this:
  • Set VariableSet temp_num = 0
  • ...
  • Set VariableSet temp_Abilities_1[temp_num] = Hotkey_Abilities[(Load (Integer A) of 1 from maxabilities.)]
while in "Upgrade ability 2" you do this:
  • Set VariableSet temp_num_2 = 0
  • ...
  • Set VariableSet temp_Abilities_2[r_temp_num_2] = Hotkey_Abilities[(Load (Integer A) of 2 from maxabilities.)]
temp_abilities_2 is using r_temp_num_2

I have also noticed that player 1's version is doing this:
  • If - Conditions
    • reward_list_randomnum[r_temp_num] Equal to 2
while player 2's version is doing:
  • If - Conditions
    • reward_list_randomnum_2[temp_int_2] Equal to 2
So again, you are using different variable for index. My guess would be that it is supposed to be r_temp_num_2

I think you should start using variables in better ways :D All of these variables are called "temp", so assuming they are temporal variables, then the entire point of them is that they are "helper" variables used during trigger's execution to help you calculate some stuff. So it should be safe to reuse them in multiple triggers.
Creating a new version of them for player 2 and possibly new versions for other players kind of defeats the purpose.
 
Level 5
Joined
Jun 24, 2024
Messages
59
Thanks for the analysis, this helped a lot!
For the "Temp" variables i have the problem, that those get used in 19 reward triggers per player and the arrays receive infos.
The variables save information that might not instantly be obsolete again, because the player triggers with the button press of
the dialog button. Because it is not instant, i do not know if it would be a wise decision to let every trigger run over the same temp
variables. Tho i understand your point and in general applications it is redundant. Dialog triggers are a different breed tho.. I got headaches from 'em ^^
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
For the "Temp" variables i have the problem, that those get used in 19 reward triggers per player and the arrays receive infos.
The variables save information that might not instantly be obsolete again
But that's what I was pointing out in my previous post. The idea of temp variables is that they are helper variables that do not store data outside of trigger's execution. Since you need those variables to store information for some time, they logically cannot be considered temp variables :)

I took a look at your map, since just the Upgrade Ability trigger is part of a larger system.
From the looks of it, I think you are not really leveraging the potential of arrays nor of hashtables.

For example:
Your "Upgrade Ability" trigger uses "temp_Abilies_1" array, which it populates with up to 6 abilities belonging to hero of Player 1 red. You just use this array a few lines below when picking random ability from this array.
In your "Upgrade Ability 2" trigger you use "temp_Abilies_2", which you populate the same way but this time from hero of Player 2 blue.

Then, further down in the same trigger you set value to "reward_list_randomnumP1_1" array. Here you store the information about whether given reward upgrades a single ability or all abilities. In this case, the index to the array is the index number of the reward. Since you have 5 rewards, up to 5 values can populate the first 5 positions in the array (indices 1-5).
In player 2 Blue's version you have same code, but use "reward_list_randomnumP2_1" array.

Why do I say you are not leveraging array potential?
In the first example with "temp_Abilities_1": This array does not store data outside trigger's execution - meaning it is a temporal variable. You can safely reuse that variable in "Upgrade Ability 2". There will be no issues.

In case of "reward_list_randomnumP1_1" you cannot consider it temporal variable, because it stores data for some time. However you do not need to have one array variable for each player, you can achieve the same thing using a single array:
  • You know that each player takes up to 5 spaces in the array because there are 5 rewards. It may be less, but it never is more.
  • You know player's number
  • You can calculate offset using players number. offset = (player_number - 1) * 5
  • Using the offset and the reward's id (number 1-5), you can store each players' values in single array under unique index numbers.
  • Player 1 red's offset will be 0 (offset = (1 - 1) * 5 = 0)
  • Player 1 red's indices in the array will be 1-5 (index = offset + reward id = 0 + [1 up to 5] = [1 up to 5]
  • Player 2 blue's offset will be 5 (offset = (2 - 1) * 5 = 5)
  • Player 2 blue's indices in the array will be 6-10 (index = offset + reward id = 5 + [1 up to 5] = [6 up to 10]


I have attached an updated version of your map. I did not update your existing triggers, instead I have added a new folder in Trigger editor under path Rewards / Reward Options / Example.
This folder contains a few triggers that are copies of some (parts) of your existing triggers. And a bunch of variables.
I have prefixed those triggers and variables with lowercase "x", so it is easy to see in editor in case you want to remove it.

The main thing to see in those triggers:
  • Those triggers are MPI. They should safely work for each player, there is no need to create a copy of each trigger for each player.
  • You can see how the array index offset is calculated and used for dialog buttons ("reward round" and "reward chosen" triggers)
  • "Reward Round" trigger is now solely responsible for dialog handling. It manages dialog and creates dialog buttons.
  • "Reward Round" now also manages value of RewardIdx (which in your triggers is called "r_temp_num") - increment and decrementing it.
  • Reward triggers like "Upgrade Ability" no longer create dialog button, they also no longer modify value of "r_temp_num"/RewardIdx - they only reads it. What it does now is set boolean value to tell the calling trigger (Reward Round) that picking this option was successful and when it was successful it also set text of the dialog button into a string variable.
  • Hashtable is more utilized - it stores player hero's abilities and number of abilities. It is also used to store some other data (for example it replaces reward_list_randomnumP1_1 array)
  • There's a bunch of variables in the Example folder. You may notice that those that are all lowercase (like "xiterator") are only ever used as temp variables - they help calculate stuff during trigger's execution, but they are not passed to any other trigger, nor do they store data outside of trigger's execution. On the other hand there are those variables which start with capital letter after "x" (like "xPN") which are passed either as inputs or outputs for triggers, or they store data (for example between dialog button creation and player clicking that button).
 

Attachments

  • Test of Survival BETA v8.w3x
    15.8 MB · Views: 2
Level 5
Joined
Jun 24, 2024
Messages
59
Wow... you are a legend Dude! Thank you very much, this is awesome. I will have to take my time to understand so i can replicate it onto the other reward triggers. There is still more in the background which set specific variables like spell damage, lifesteal on damage events and so on. Maybe i need to rethink the whole structure ground up.
 
Top