• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Multiple variable or one array varaible?

Status
Not open for further replies.
Level 9
Joined
Sep 20, 2015
Messages
385
Hello. In my map there is an item that you can't buy 2 times. So i created a boolean variable that turns true when the item is bought for the first time. It works fine, but i have 10 players in the map so here is my question:

Witch option is better between create one variable for each player and create one array variable with n = number of players ?

To be more clear:

option 1
create 1 variable for each player in the game
P1itemb, P2itemb, P3itemb and so on

OR

option 2
create one array variable that contains all players
ItemB[player number]
so will be ItemB[0] = P1, ItemB[1] = P2 and so on

For better i mean, witch option dont make the game freeze for a shot time?



Thank you
 
Level 9
Joined
Sep 20, 2015
Messages
385
Create one array variable with n number of players. It's easier, and more simple. Keep in mind that in GUI, the player number starts at 1 (Player 1 Red = 1), while JASS starts at 0 (Player 1 Red = 0).

Neither will make the game freeze. The array option is definitely and obviously better (Because of the possibility of using an array linked to player id : ItemB[GetPlayerId()])

All right array variable it is

Thank you both
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Array variable is the best as it reduces procedural coupling allow potential modifications to the code to be made more easily. You want to avoid repeating the same block of code multiple times, instead preferring to call functions (run triggers in GUI case) or use loops to achieve the same behaviour instead.
 
Status
Not open for further replies.
Top