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

System refuses to become MUI/ does not work

Status
Not open for further replies.

Ardenian

A

Ardenian

Hello,

I worked the couple last days on a TD system as it is seen in Power Towers.
A 'simple' system that allows one to constantly add mana to targets.

However, although the system is not finished yet, I cannot get ride of a certain problem:
Only the first unit being a supplier supplies, every new supplier does not.

There is also another issue with suppliers ( the first supplier) not supplying mana to other suppliers.

My debug does not show any mistakes or issues.

I would appreciate if you could help me.



  • PS Configuration
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: local integer i = 1
      • Set PS_GeneratorUnitType[1] = Small Generator
      • Set PS_GeneratorUnitType[2] = Big Generator
      • Set PS_ManaAmount[1] = 10.00
      • Set PS_ManaAmount[2] = 20.00
      • -------- --------
      • Set PS_Ability = Add Power Link
      • -------- --------
      • Hashtabelle - Create a hashtable
      • Set Hash_PowerSystem = (Last created hashtable)
      • -------- --------
      • Set PS_TempUnitType[0] = Small Generator
      • Custom script: set udg_TempInteger_1[0] = udg_PS_TempUnitType[0]
      • Hashtable - Save (Integer(PS_ManaAmount[PS_Index2])) as 0 of TempInteger_1[0] in (Last created hashtable)
      • Set PS_Index2 = (PS_Index2 + 1)
      • -------- --------
      • Set PS_TempUnitType[0] = Big Generator
      • Custom script: set udg_TempInteger_1[0] = udg_PS_TempUnitType[0]
      • Hashtable - Save (Integer(PS_ManaAmount[PS_Index2])) as 0 of TempInteger_1[0] in (Last created hashtable)
      • Set PS_Index2 = (PS_Index2 + 1)
      • -------- --------
      • Custom script: loop
      • Custom script: exitwhen udg_PS_GeneratorUnitType[i] == null
      • Custom script: set udg_TempInteger = udg_PS_GeneratorUnitType[i]
      • Hashtabelle - Save True as 0 of TempInteger in Hash_PowerSystem
      • Custom script: set i = i + 1
      • Custom script: endloop


  • Index Supplier
    • Events
      • Unit - A unit finishes construction
    • Condition
    • Actions
      • Set TempUnit = (Constructed structure)
      • Custom script: set udg_TempInteger = GetUnitTypeId(GetConstructedStructure())
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Condition
          • (Load 0 of TempInteger from Hash_PowerSystem) Equal True
        • 'THEN'-Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Conditions
              • (TempUnit is in PS_GeneratorGroup) Equal False
            • 'THEN'-Actions
              • Set PS_Index = (PS_Index + 1)
              • Set PS_Generator[PS_Index] = TempUnit
              • Unit Group - Add TempUnit to PS_GeneratorGroup
              • Set PS_Counter[PS_Index] = 0
              • Unit Group - Add TempUnit to PS_SupplyGroup[PS_Index]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Conditions
                  • PS_Index Equal 1
                • 'THEN'-Actions
                  • Trigger - Turn on Loop <gen>
                • 'ELSE'-Actions
            • 'ELSE'-Actions
        • 'ELSE'-Actions


  • Add Remove Supplied Units
    • Events
      • Unit - A unit starts casting an ability
    • Conditions
      • (Ability being cast) Equal PS_Ability
    • Actions
      • Set TempUnit = (Target unit of ability being cast)
      • For each (Integer TempInteger2) from 1 to PS_Index, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Conditions
              • (Casting unit) Equal PS_Generator[TempInteger2]
            • 'THEN'-Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Conditions
                  • (TempUnit is in PS_SupplyGroup[TempInteger2]) Equal False
                • 'THEN'-Aktionen
                  • Unit Group - Add TempUnit to PS_SupplyGroup[TempInteger2]
                • 'ELSE'-Actions
                  • Unit Group - Remove TempUnit from PS_SupplyGroup[TempInteger2]
            • 'ELSE'-Actions


  • Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer TempInteger2) from 1 to PS_Index, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • 'IF'-Conditions
              • (PS_Generator[TempInteger2] is alive) Equal True
            • 'THEN'-Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Copnditions
                  • PS_Counter[TempInteger2] Equal 20
                  • (PS_SupplyGroup[TempInteger2] is empty) Equal False
                • 'THEN'-Actions
                  • Set PS_TempUnitType[0] = (Unit-type of PS_Generator[TempInteger2])
                  • Custom script: set udg_TempInteger_1[0] = udg_PS_TempUnitType[0]
                  • Set TempInteger_1[1] = (Load 0 of TempInteger_1[0] from Hash_PowerSystem)
                  • Custom script: set bj_wantDestroyGroup = true
                  • Unit Group - Pick every unit in PS_SupplyGroup[TempInteger2] and do (Actions)
                    • Loop - Actions
                      • Set PS_TempUnitType[TempInteger2] = (Unit-type of PS_Generator[TempInteger2])
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • 'IF'-Conditions
                          • (Unit-type of (Picked unit)) Not equal PS_TempUnitType[TempInteger2]
                        • 'THEN'-Actions
                          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + (Real(TempInteger_1[1])))
                          • Set PS_Counter[TempInteger2] = 0
                        • 'ELSE'-Actions
                • 'ELSE'-Actions
                  • Set PS_Counter[TempInteger2] = (PS_Counter[TempInteger2] + 1)
            • 'ELSE'-Aktionen
              • Unit Group - Remove PS_Generator[TempInteger2] from PS_GeneratorGroup
              • Unit Group - Remove all units from PS_SupplyGroup[TempInteger2]
              • Set TempUnit = PS_Generator[TempInteger2]
              • Set PS_Generator[PS_Index] = TempUnit
              • Set PS_Counter[TempInteger2] = PS_Counter[PS_Index]
              • Set PS_Index = (PS_Index - 1)
              • Set TempInteger2 = (TempInteger2 - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • 'IF'-Conditions
                  • PS_Index Equal 0
                • 'THEN'-Actions
                  • Trigger - Turn off (This trigger)
                • 'ELSE'-Actions

 
Last edited by a moderator:
What comes in my eyes is that your unit groups do not exist, but only for first index.
If you create an handle array variable in GUI only index [0] and [1] are initialisized. So Group[0] and Group[1] do exist. Others not.

You create a group via CreateGroup() function, so
  • Custom script: set udg_myGroup = CreateGroup()

Why do you use arrays in init trigger for temp variables?

I think in init you need to increase the Index2 as first action in your blocks, not as last action.

Have not really checked rest now.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
If you create an handle array variable in GUI only index [0] and [1] are initialisized. So Group[0] and Group[1] do exist. Others not.

Not exactly.
If you create a global array variable, you can also set the "size" of the array.
Ofcourse we all know that it doesnt really change the actual size of the array but it does set the default (an empty group) under every index from 0 to the given "size".
So if I create a unit group array of size 10, I have 11 groups (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) because the default value is an empty unit group.

So if his size is correct, then he does have unit groups.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
IcemanBo meant that by default, only indexes 0 and 1 are created.

Looking at the map, the initial size is indeed 1 (the default), and thus the groups are not created. He identified the issue correclty.

I never adjust initial sizes, I create everything dynamically.
 

Ardenian

A

Ardenian

I don't think I understand what you mean.
IcemanBo said:
I think in init you need to increase the Index2 as first action in your blocks, not as last action.
Maker said:
Looking at the map, the initial size is indeed 1 (the default), and thus the groups are not created.

I can fix it by setting the initial Index2 to '0' instead of '1' and moving the
  • Set PS_Index2 = (PS_Index2 + 1)
at the beginning of each part ?

IcemanBo said:
Why do you use arrays in init trigger for temp variables?
Just took what Wietlol explained me for that particular block. I guess I can remove the array.

IcemanBo said:
What comes in my eyes is that your unit groups do not exist, but only for first index.

I don't understand why the unit groups are not created.
I don't touch the unit groups in the map initialization, but only use them if I index a unit, like creators do in many other spells/systems/...
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
What happens is that PS_SupplyGroup is not a unit group, that variable is empty (with the exception of PS_SupplyGroup[0] and PS_SupplyGroup[1].
So PS_SupplyGroup[2], PS_SupplyGroup[3], PS_SupplyGroup[4], etc are all empty so do not have a group.
What you have to do is add the custom script: "set udg_PS_SupplyGroup[udg_PS_Index] = CreateGroup()" to your "Index Supplier" trigger just before you add TempUnit to the group. (That is where you use that group for the first time.)

On the other hand, when you de-index that unit/group/etc, you have to destroy that group like you fix group leaks.
 

Ardenian

A

Ardenian

Oh, now it is working, thank you!

Tho, it only did after I removed the custom script in the Loop to destroy the group.

By the way, any idea why the supply does not work on other suppliers ? I think the groups interfere somehow.

EDIT: Yep, since the trigger checks whether the supplier is in any group, he is not added to the new one.
 
Last edited by a moderator:
Status
Not open for further replies.
Top