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

[Trigger] Problem with Variable Indexing! (Need help)

Status
Not open for further replies.
Level 4
Joined
Aug 22, 2010
Messages
54
So i've created my own quest system which works, however - i'm optimizing the system, and this
requires a better more effective index system than what i have now.

I define all the required quest variables at the start of the map with a standard array.

My issue is i'm using the array for QUEST INDEX, not for calling player number. I'm currently keeping track of the player kills and the state of the quests for each player, with variables for each player.
The quests are MUI - but it's extremely tedious, when coding in GUI.

Quest_Array
= Quest_Array + 1
Quest_Name(Quest_Array) = Maintaining Balance
Quest_Description(Quest_Array) = Slay 10 wolves.
Quest_UnitType(Quest_Array) = Wolf
Quest_AmountRequired(Quest_Array) = 10
Quest_Player1Kills(Quest_Array) = 0
Quest_Player2Kills(Quest_Array) = 0
Quest_Player3Kills(Quest_Array) = 0
Quest_Player4Kills(Quest_Array) = 0


I would like to store player kills like this instead for easier access of the variables when coding triggers:
Quest_PlayerKills(Quest_Array, Player_Number) or something like that. Instead of having 4 variables with the same array.

Quest_Array = Quest_Array + 1
Quest_Name(Quest_Array) = Maintaining Balance
Quest_Description(Quest_Array) = Slay 10 wolves.
Quest_UnitType(Quest_Array) = Wolf
Quest_AmountRequired(Quest_Array) = 10
Quest_PlayerKills(Quest_Array, Player_Number) = 0

This would make If/then/else statements way shorter in triggers.
I would like to avoid hashtables all together if possible.

Example: Current method

Event
A unit dies

For each Integer A from 1 to Quest_Array do
If TriggeringUnit = Quest_Unit(Integer_A) then
If Get:TriggeringPlayer(Get:OwnerOf(Killing Unit)) = 1 then
Quest_Player1Kills(Quest_Array) = Quest_Player1Kills(Quest_Array) + 1
else
If Get:TriggeringPlayer(Get:OwnerOf(Killing Unit)) = 2 then
Quest_Player2Kills(Quest_Array) = Quest_Player2Kills(Quest_Array) + 1
else
If Get:TriggeringPlayer(Get:OwnerOf(Killing Unit)) = 3 then
Quest_Player3Kills(Quest_Array) = Quest_Player3Kills(Quest_Array) + 1
else
If Get:TriggeringPlayer(Get:OwnerOf(Killing Unit))= 4 then
Quest_Player4Kills(Quest_Array) = Quest_Player4Kills(Quest_Array) + 1
else


Example: Goal

Event
A unit dies

For each Integer A from 1 to Quest_Array do
If TriggeringUnit = Quest_Unit(Integer_A) then
Quest_PlayerKills(Quest_Array, Get:TriggeringPlayer(Get:OwnerOf(Killing Unit)) = Quest_PlayerKills(Quest_Array, Get:TriggeringPlayer(Get:OwnerOf(Killing Unit)) + 1
else
 
Well, you can shorten the entire process if you use one player kill count array variable instead of 4.

Since you have four players, you can populate the variables as follows:

JASS:
Quest_PlayerKills[(Quest_Array - 1)*4 + GetPlayerIndex(player) + 1]

The important part here is the following: (Quest_Array - 1)*4 + GetPlayerIndex(player) + 1
This will simulate MUI behavior but will restrict you to 32768/4 or 8192 instances. This ensures that each new member has its' own unique sequence of arrays.

To be more concise: 1 Quest_Array member produces 4 Quest_PlayerKill members based on player count.
 
Status
Not open for further replies.
Top