• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Will this work ?

Status
Not open for further replies.
Level 6
Joined
Feb 16, 2014
Messages
193
So i want it that everytime a unit is created then a custom value will be assigned to that unit, and when a unit dies then every unit that has a bigger custom value than that dying unit will be decreased, i managed to create it but just curious though, will it work properly? and also should i change "Dying Unit" and "Trained Unit" to "Triggering Unit" ?
  • OnUnitCreate
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Set Max_Value = (Max_Value + 1)
      • Unit - Set the custom value of (Trained unit) to Max_Value
  • OnUnitDie
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Picked unit)) Greater than (Custom value of (Dying unit))
            • Then - Actions
              • Set Max_Value = (Max_Value - 1)
              • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 1)
            • Else - Actions
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
I suggest you start learning Linked List. You can change Dying Unit to Triggering Unit but DON'T changed Trained Unit.
Basically, Triggering Unit refers to the Unit that causes the Event to Run. E.g. in the ' A Unit Dies' Event, the 'A Unit' is the Triggering Unit. In the 'A Unit Finishes Training a Unit', the 'A Unit' is triggering unit which is most likely the building that trains the unit.
 
Level 6
Joined
Feb 16, 2014
Messages
193
I suggest you start learning Linked List. You can change Dying Unit to Triggering Unit but DON'T changed Trained Unit.
Basically, Triggering Unit refers to the Unit that causes the Event to Run. E.g. in the ' A Unit Dies' Event, the 'A Unit' is the Triggering Unit. In the 'A Unit Finishes Training a Unit', the 'A Unit' is triggering unit which is most likely the building that trains the unit.

It will work without bugs I suppose.

Ok thx guys :thumbs_up:
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,206
If this is used as an indexing system then it will bug as the custom value numbers are used to reference structs instances (array indexes in parallel arrays) so cannot be mutable without corrupting the unit's corresponding data. In this case the solution is to use a free list in the form of an integer array with a few helper global integers.

It will also bug if used as a simple unit counter system since Max_Value can be decremented more than it is incremented. The decrementing of Max_Value must only occur once per unit death, like how the incrementing only occurs once per unit training.

It leaks a large unit group once per unit death. This is a pretty major leak due to the size of unit group involved (every unit in playable map area).
 
Level 6
Joined
Feb 16, 2014
Messages
193
If this is used as an indexing system then it will bug as the custom value numbers are used to reference structs instances (array indexes in parallel arrays) so cannot be mutable without corrupting the unit's corresponding data. In this case the solution is to use a free list in the form of an integer array with a few helper global integers.

It will also bug if used as a simple unit counter system since Max_Value can be decremented more than it is incremented. The decrementing of Max_Value must only occur once per unit death, like how the incrementing only occurs once per unit training.

It leaks a large unit group once per unit death. This is a pretty major leak due to the size of unit group involved (every unit in playable map area).

How can i do the "Free List" thing? , it sounds complicated for me :vw_death:
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
When you decrease all custom values of the units with a higher custom value than the unit itself, you can simply replace the removed unit with the last one in the list.
Wg4atoR.png


However, that will ruin the MAX_VALUE pretty much because you cannot lower it.
(Thou shall NOT EVER CHANGE the custom value of a unit.)

So, you will not reduce the MAX_VALUE.
This will mean that we just keep going up and up and up.
The reason for using an indexer is basically to have a handle index below 8191 so arrays can be used better.
When you reach 8191, you will set MAX_VALUE back to 1 again. (0 is for non-existant units)
At that moment, every new unit must get a value that is not used by another unit.
The easiest way is to make a boolean array and set the value to true if the index is created and false if the unit is removed.
When a new unit is created, you loop from MAX_VALUE upwards until you reach a false and that index will be the new index.

Even though this is a very simplified version of indexing, it gets quite complicated pretty fast.
But that is one of the ways how this can be done.
If you also have a way to remove the dummies in the creation, you will be having a pretty good indexing as well.

But there is also one other thing you can do... just download an indexing system from the spell section. :D
 
Level 6
Joined
Feb 16, 2014
Messages
193
When you decrease all custom values of the units with a higher custom value than the unit itself, you can simply replace the removed unit with the last one in the list.
Wg4atoR.png


However, that will ruin the MAX_VALUE pretty much because you cannot lower it.
(Thou shall NOT EVER CHANGE the custom value of a unit.)

So, you will not reduce the MAX_VALUE.
This will mean that we just keep going up and up and up.
The reason for using an indexer is basically to have a handle index below 8191 so arrays can be used better.
When you reach 8191, you will set MAX_VALUE back to 1 again. (0 is for non-existant units)
At that moment, every new unit must get a value that is not used by another unit.
The easiest way is to make a boolean array and set the value to true if the index is created and false if the unit is removed.
When a new unit is created, you loop from MAX_VALUE upwards until you reach a false and that index will be the new index.

Even though this is a very simplified version of indexing, it gets quite complicated pretty fast.
But that is one of the ways how this can be done.
If you also have a way to remove the dummies in the creation, you will be having a pretty good indexing as well.

But there is also one other thing you can do... just download an indexing system from the spell section. :D
Please give a short example, it's still a little hard for me to understand :/
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well... This one works... kind of.
  • Indexing
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
    • Actions
      • For each (Integer CurrentIndex) from CurrentIndex to 8191, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrentIndex Greater than or equal to 8190
            • Then - Actions
              • Set CurrentIndex = 1
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • UnitOfIndex[CurrentIndex] Equal to No unit
            • Then - Actions
              • Set UnitOfIndex[CurrentIndex] = (Triggering unit)
              • Unit - Set the custom value of UnitOfIndex[CurrentIndex] to CurrentIndex
              • Skip remaining actions
            • Else - Actions
Just make sure that CurrentIndex starts with 1 and not 0.
With booleans and removal and stuff, you can optimize this but this works afaik.

EDIT:
I forgot, at map initialization, you also have to loop through all pre-placed units.
 
Last edited:
Level 6
Joined
Feb 16, 2014
Messages
193
Well... This one works... kind of.
  • Indexing
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
    • Actions
      • For each (Integer CurrentIndex) from CurrentIndex to 8191, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CurrentIndex Greater than or equal to 8190
            • Then - Actions
              • Set CurrentIndex = 1
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • UnitOfIndex[CurrentIndex] Equal to No unit
            • Then - Actions
              • Set UnitOfIndex[CurrentIndex] = (Triggering unit)
              • Unit - Set the custom value of UnitOfIndex[CurrentIndex] to CurrentIndex
              • Skip remaining actions
            • Else - Actions
Just make sure that CurrentIndex starts with 1 and not 0.
With booleans and removal and stuff, you can optimize this but this works afaik.

EDIT:
I forgot, at map initialization, you also have to loop through all pre-placed units.

Thx dude :thumbs_up:
 
Status
Not open for further replies.
Top