• 🏆 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!

[General] Am I using arrays/player groups/unit groups correctly? (Example shown)

Status
Not open for further replies.
Level 3
Joined
Feb 25, 2019
Messages
35
Hello, I'm new to the map making scene. I've read many tutorials and think I understand the use of variables, arrays, etc. fairly well. I am getting pretty far into developing my first map and I've run into a few issues along the way that have led me to point towards one common factor - I may not understand how arrays interact as much as I'd hoped. I was hoping someone could look at what I am doing briefly and tell me why/why not it works/doesn't work, etc.

TLDR: I am concerned about my ignorance regarding a specific unit array, a player group, and a unit group & how to use them.

1) Hero Selection: The biggest red flag for me all points back to how the game starts. 1-5 players can play, there are currently 5 heroes (eventually more) available for selection. Upon selection, a hero is set as the value for "PlayerUnit[PlayerNumber(of the person selecting)]." That "PlayerUnit" array is 1 of the 3 parts of my design that I am concerned may be causing issues. The other 2:​

2) At map initialization, I create a player group called, "IsPlaying," of the players that match both "User" and slot status of "is playing." I use this so the game doesn't generate rewards for players that are computer based or not filled for that game. I am worried that my total lack of understanding on player groups may be leading to some unexpected conflicts later on (examples will come). Oh, I should also mention I use the absolute hell out of this player group, especially in the for all integers A function by setting the range of values as, "1 to (Number of players in group, IsPlaying)."​

3) Along with assigning a selected hero to "PlayerUnit[Number]," I also then add them to a unit group, "AllPlayerHeroes." This one is also incredibly useful if it is working the way I am hoping, because it allows for things like global rewards for quests where I don't have to condition which heroes are nearby, involved, etc. In situations where I want all heroes to get a reward, but still need to isolate it to only the ones that have been chosen and are being actively played, I use this unit group to distribute rewards like exp & items.​

Some examples of these uses:

ApprenticeCounter[A].PNG


In this example, a quest has been going on for a long chain of events, all given by a single unit that 'sells' an item that allows for events to progress. Basically, you select the item he sells and the trigger checks the current stage of the quest (Quest2 = ?) and returns the correct response. However, after the chain of quests is over, I want this unit to act as a returning character, but ONLY for players who have chosen the "apprentice path." I decided, for now, to add these feature in as just another part of the chain, where a new counter "ApprenticeCounter[PlayerNumber]" is used to determine if that player has started the first part of the apprentice path quests.

TLDR: A different trigger based on a different unit sets ApprenticeCounter[number] = 1, if it is 1 when interacting with this unit, I want him to set it to 2, but ONLY for the player interacting with him.

I've set a "for each (integer A)" for the range of players from 1 to 'IsPlaying' to check the possible player numbers it could be, and then my hope is that the condition, "if Hero Manipulating Item = PlayerUnit[A]," will work by detecting if the player interacting with this unit is also the PlayerUnit[A] that it is currently checking for, then only increasing the value for that player's ApprenticeCounter[Number] to 2.

Does this sort of system work? Have I just gotten lucky with it in the past? Is there anything I should be concerned about?

Next example:
AllPlayerHeroes.PNG


Here, I again have an array for an integer that is used to detect if a player has already received a very specific reward. This quest can be done multiple times, but I only one each player to be able to get the item one single time at an ideally 70% chance (but I've set it to 80 to help in debugging a little).

My hope is that it will pick each unit in in "AllPlayerHeroes" and give each one the 3k exp, but then require both the 80% dice roll AND that the player's "RewardCounter[PlayerNumber]" for that specific player be 0 and not 1 in order to give the item. If the player does get the item, I their "RewardCounter[PlayerNumber]" to change to 1, and theirs only. Does this work?

Thank you taking the time to read any of what you've chosen to. I don't expect anyone to examine all of it but any feedback I can get it valuable to me.

As a quick clarification, I am aware that many of my uses would be ruined if, for example, 2 players were playing and one changed colors to be teal instead of blue, resulting in the "# of players in IsPlaying" to = 2, but the PlayerNumber needed actually being 3. I am completely okay with this. Thank you again!
 
Level 4
Joined
Jan 18, 2019
Messages
71
I think that you are using the correct system to:

a) keep track and distribute rewards to all players

However,

I think you will run into problems the deeper and more extsensive the path goes. You need to set individual arrays for each path. For instance, quest 1 is completed by player 2.

Set variable “Quest2Complete(player2)” = 1

Then, when the player 2 wants to start an alternative path that is an exstention of quest 1, the trigger needs only to check the condition:

If “Quest2Complete(player2)” = 1 then do actions:

For every path complete, define a new variable array for all players. Then check each quest array variable. It will mean you will have many arrays, but you can have nearly infinite of them.

So if your quest is 10 stages long or steps, whatever, then check each new quest array:

Quest Part 1:

If “Quest1Complete(player1)” equal to 1, then do actions and set “Quest2Complete(player1)” equal to 2. Repeat this until they have reached the last part and it should be checking for:

If “Quest1Complete(player1)” equal to 10, then do actions:

Set “Quest2Avaliable(Player1)” = 1

Give <xp, gold,etc...>

Then when the player interacts with quest unit, if the variable “Quest2Avaliable(player1)”=1 the. Set “Quest2Complete(player1)” =1.
 
Last edited:
Level 3
Joined
Feb 25, 2019
Messages
35
I think that you are using the correct system to:

a) keep track and distribute rewards to all players

However,

I think you will run into problems the deeper and more extsensive the path goes. You need to set individual arrays for each path. For instance, quest 1 is completed by player 2.

Set variable “Quest2Complete(player2)” = 1

Then, when the player 2 wants to start an alternative path that is an exstention of quest 1, the trigger needs only to check the condition:

If “Quest2Complete(player2)” = 1 then do actions:

For every path complete, define a new variable array for all players. Then check each quest array variable. It will mean you will have many arrays, but you can have nearly infinite of them.

So if your quest is 10 stages long or steps, whatever, then check each new quest array:

Quest Part 1:

If “Quest1Complete(player1)” equal to 1, then do actions and set “Quest2Complete(player1)” equal to 2. Repeat this until they have reached the last part and it should be checking for:

If “Quest1Complete(player1)” equal to 10, then do actions:

Set “Quest2Avaliable(Player1)” = 1

Give <xp, gold,etc...>

Then when the player interacts with quest unit, if the variable “Quest2Avaliable(player1)”=1 the. Set “Quest2Complete(player1)” =1.
This is an amazing response and I appreciate it a lot, unfortunately, it is my fault for not providing quite enough context. The variable like "Quest2" is not an array itself because it is actually intended to be a universal progression as it will open up areas, unlock dungeons, progress the storyline, etc. All players are intended to have that quest progression shared (same for Q1). The very last line there, with "Quest2 = 12," is the last time the Quest2 variable would mentioned for the future "else" functions in that trigger. It serve the purpose (there, very specifically) of making sure none of the other previous dialog/actions are called for when starting the individual path/quests that are primarily based around "ApprenticeCounter[PlayerNumber]." Also, I switched the method for checking & changing this to "If ApprenticeCounter[PlayerNumber(OwnerOfUnit(HeroManipulatingItem))] = (Number)" & then having it alter it in a similar format. Thank you for the amazing advice, though. I'm just now starting work on individualized paths so I'll hopefully get some experience with making those ^^
 
Level 9
Joined
Jul 30, 2018
Messages
445
I would like to help, but I have a hard time figuring out what exactly is your problem... :p Is something not working? Or if you are having more problems, could you give a bit more specific examples?


Also, a couple of side notes:
- You don't need the "Do nothing" action. If you leave it empty, it will just do nothing as well.
- You can post triggers directly to this website. First right-click the paper icon next to the trigger name inside World Editor's Trigger Editor and then select "Copy as text" and paste it inside [ trigger]....[/trigger ] tags (without the spaces) here.
- I suggest to check out this thread regarding the leaks. I think it's better to learn to remove the leaks right from the start, so they become a habit as fast as possible.
 
Level 3
Joined
Feb 25, 2019
Messages
35
I would like to help, but I have a hard time figuring out what exactly is your problem... :p Is something not working? Or if you are having more problems, could you give a bit more specific examples?


Also, a couple of side notes:
- You don't need the "Do nothing" action. If you leave it empty, it will just do nothing as well.
- You can post triggers directly to this website. First right-click the paper icon next to the trigger name inside World Editor's Trigger Editor and then select "Copy as text" and paste it inside [ trigger]....[/trigger ] tags (without the spaces) here.
- I suggest to check out this thread regarding the leaks. I think it's better to learn to remove the leaks right from the start, so they become a habit as fast as possible.
  • Yeah, I read about the "Do Nothing" action about 3-4 days ago and have stopped using it, but I need to go back and remove it from all previous code.
  • THANK YOU... I've been trying to figure that out. I read that on the rules but I swear I don't know what you're talking about when you say [ trigger ]...[/trigger] tags.. I don't know what a tag is : (
  • Are you saying this because you see a lot of leaks that I don't understand?
To clarify my 'problem,' there are a lot of things I simply don't understand, and am concerned about the potential interaction with them:

  1. Is there any issue with setting the same value to multiple variables? (PlayerUnit[1] = Footman, BossTarget[3] = Same Footman)
  2. If I set floating text or a special effect to be attached to a unit, does that count as a location that should've been removed to prevent a leak? (I usually try to just do the point but it'd still be nice to know).
  3. Is there anything wrong with treating an array as multiple unique variables? (So can I treat.. "Location[1], Location[2], Location[3], Location[4]" the same as "TempPoint1, TempPoint2, TempPoint3, TempPoint4?") To give more elaboration on this one, I frequently use an unit array, point array, and sometimes a 'real' array that are all assigned to a specific ability. One example of this is an ability I named "Desolation." The ability has the following variables: "DesPoint[x], DesUnit[x], DesReal[x]." When I first made the ability I was brand new and by the end of it I had used upwards of 20+ (DesUnit[20], etc.) but since then I've just cleaned up along the way and limited it to 0-3 for the index. This leads into #4...
  4. Is there anything hazardous about having too many variables? I have so many variables. I don't mind managing them, I like having a lot, but I fully expect to have it bite me in the ass in the future.
It is because of this vague ignorance that I fear something like the triggers I posted will be faulty or cause issues down the line. For all I know, any of the 3 original examples from post 1 could be abominations of an attempt to organize player/unit information & re-use it later. I have no clue.
 
Level 7
Joined
Apr 17, 2017
Messages
316
1)No there is not.
2)You can safely use them as long as you destroy them when you are done.
3)That's what people do! Arrays help you classify things better.
4)There is not unless you have like 100k variables in your map. So it's pretty unrealistic.

What he meant was posting your trigger in bb codes so that people can take a look at it faster. All you need to do is copy the trigger as text and paste it inside [ trigger][/trigger] tags.Here is the full bb code list: BB Codes | HIVE
 
Level 3
Joined
Feb 25, 2019
Messages
35
1)No there is not.
2)You can safely use them as long as you destroy them when you are done.
3)That's what people do! Arrays help you classify things better.
4)There is not unless you have like 100k variables in your map. So it's pretty unrealistic.

What he meant was posting your trigger in bb codes so that people can take a look at it faster. All you need to do is copy the trigger as text and paste it inside [ trigger][/trigger] tags.Here is the full bb code list: BB Codes | HIVE
Specifically regarding point #2, as this is something I've been very curious about, for floating text - does the permanence lifespan = destroying it?
 
Level 9
Joined
Jul 30, 2018
Messages
445
  • Yeah, I read about the "Do Nothing" action about 3-4 days ago and have stopped using it, but I need to go back and remove it from all previous code.
No biggies, it really doesn't matter if you put them. Just saves some time if you don't add them in the future. :)

  • Are you saying this because you see a lot of leaks that I don't understand?

Oh, right, not much problems there, I must have been thinking about some other thread :D

As for the other questions, they were pretty well answered already. You don't need to worry about floating texts much as as long as the permanence is disabled and it has a set life, the text will destroy itself without leaks.

I like arrays too. I'd even say it's quite smart to use them, as they are a lot less confusing when the amount of variables grows large.
 
Level 3
Joined
Feb 25, 2019
Messages
35
No biggies, it really doesn't matter if you put them. Just saves some time if you don't add them in the future. :)



Oh, right, not much problems there, I must have been thinking about some other thread :D

As for the other questions, they were pretty well answered already. You don't need to worry about floating texts much as as long as the permanence is disabled and it has a set life, the text will destroy itself without leaks.

I like arrays too. I'd even say it's quite smart to use them, as they are a lot less confusing when the amount of variables grows large.
You guys have no clue just how much of a relief this for me xD Thank you so much
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
Correct. Set its permanence to false, give it a lifespan, and you should be ok.
@iSkyi the order for floating text is important. If you don't disable permanence before you give it a lifespan, the lifespan will do nothing and the ft will never expire. Most trigger actions do not have some sort of an order requirement, FT is just different.
If I set floating text or a special effect to be attached to a unit, does that count as a location that should've been removed to prevent a leak? (I usually try to just do the point but it'd still be nice to know).
Think of the point as an object that you are telling the game to use in some action. After it's done using it the location needs to be cleaned up: if you say "do X action... at SOME_LOCATION" then the SOME_LOCATION needs to be cleaned up. If you say "do X action... on SOME_UNIT" there is no location object being used so you don't need to clean anything up.
 
Status
Not open for further replies.
Top