• 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] Dynamic Index recycling system

Status
Not open for further replies.
Level 16
Joined
Jun 24, 2009
Messages
1,409
I'm often attacked by the Spell moderators because of the system I made and I use. They say Hanky's method is better.(Just a little...) I still use this system because I know every single part of it and it's more suitable for me. But I want to make it a better system with no waste of memory or something else.

  • Start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spell
    • Actions
      • Comment - A part of the core of the system. It seeks for unused slots so the trigger will use this instead of creating a new maximum instance. If there is no unused slot out of the current maximum, the maximum will be increased by 1.
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Has[LastRecycled] Equal to True
        • Then - Actions
          • Set Max = (Max + 1)
          • Set Index = Max
        • Else - Actions
          • Set Index = LastRecycled
          • Set LastRecycled = RecycledList[LastRecycled]
      • Comment - Setting the values for the triggers, increasing the number of instances running and turning the checked boolean to true.
      • Set Caster[Index] = (Triggering unit)
      • ...
      • Set Has[Index] = True
      • Set Count = (Count + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Loop <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Loop <gen>
        • Else - Actions
  • Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Integer) from 0 to Max, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Comment - Checking the boolean if the instance is still used.
              • Has[Integer] Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Comment - Checking if the spell shall be turned off
                  • Time[Integer] Greater than 0.00
                • Then - Actions
                  • Comment - Actions if yes.
                  • Set Time[Integer] = Time[Integer] - 0.03
                • Else - Actions
                  • Comment - Actions if no, cleanup and instance disabler.
                  • Set Count = (Count - 1)
                  • Set Has[Integer] = False
                  • Comment - Other part of the core, storing the slot number that is just disabled.
                  • Set RecycledList[Integer] = LastRecycled
                  • Set LastRecycled = Integer
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Comment - Full cleanup if there is no running instance
                      • Count Equal to 0
                    • Then - Actions
                      • Trigger - Turn off (This trigger)
                      • For each (Integer A) from 0 to Max, do (Set RecycledList[(Integer A)] = 0)
                      • Set LastRecycled = 0
                      • Set Max = 0
                    • Else - Actions
            • Else - Actions
So the problem with the system is that it is possible that there will be empty, unused slots until the trigger turns off. That's not a really big problem because the system will jump this instance after a check anyway but I'm attacked because of that :/ I don't want to trash the system so please just make suggestions and not a full remake that throws out nearly anything.
 
How about, after this line:

  • Set Time[Integer] = Time[Integer] - 0.03
You check if Time[Integer] is now <=0.0; if it is smaller, you immediately run this trigger.

I think that might fix your problem.

Now, not to jump on the band waggon, but you've just programmed something called a stack in GUI, and you really should be learning vJass to implement things like this easier
 
Level 16
Joined
Jun 24, 2009
Messages
1,409
Hanky's method of indexing is the best of the best there is for GUI'ers, yours uses a boolean checking method (reminds me of paladon) and looping theough all indexes until there are no more instances, which is less efficient...

I know what my system does but thanks...

How about, after this line:

  • Set Time[Integer] = Time[Integer] - 0.03
You check if Time[Integer] is now <=0.0; if it is smaller, you immediately run this trigger.

wat.

Now, not to jump on the band waggon, but you've just programmed something called a stack in GUI, and you really should be learning vJass to implement things like this easier

I know it's based on stacking. Learning vJass well... I don't really have time because of school and my job and even if I have I better spend it on learning a commonly used language and not one used only by one company.

Though this is vJass, IMO your method has quite something in common with this:
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-alloc-alternative-221493/
I suggest checking that out, and improving your method according to it. It will probably not be /that/ much of a difference, but still a little..

What are these static and debug prefixes before some of the functions? Honestly, I have no idea what this code contains. I have a bit of knowledge in Pascal and C but this code :/
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
debug call AAA() will only call AAA() when the code runs if you have debug mode on. You can turn it off in jassHelper and debug mode is turned off when you dont open map trought editor.
Static is used in structs and its because struct members are converted to global arrays and static makes them to be global variables without array(meaning you cant have static integer i, this.i = something)
However, you can have static integer array i which is basically the same but I think(not tested) you cant use index.name syntax but you must use name[index] syntax

Edit: to your point of learning more usable lang. than Jass, why you then are working on GUI when this cant be used anywhere else as well ? hmm..not a valid point.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Your cleanup is not very good. If you move everything stored at the last index to the index which you are freeing and decrease the total index counter by 1, you don't have to worry about having holes in your arrays, and there's really no disadvantage. I'd hazard a guess that this is what Hanky's system does, but I haven't seen it.
 
Status
Not open for further replies.
Top