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

Which is faster?

Status
Not open for further replies.
Level 17
Joined
Jun 17, 2010
Messages
2,275
Is it faster to end a chain of if/then/else at the then action like so:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Random_Integer Less than or equal to 22
    • Then - Actions
      • Hero - Create Winning Lottery Ticket and give it to (Picked unit)
      • Custom script: call DestroyGroup(udg_StartingUnit_Group)
      • Skip remaining actions
    • Else - Actions
or going through every if/then/else and destroying the group at the end? Every if then else would have to contain the script.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
depends on multiple factors. Depends on how the Virtual machine handles if-else blocks, it may or may not be faster to return from function(Skip Remaining Actions in GUI) then to let the VM jump out from the ifs.

The second thing is, if you have anything outside the if-else nesting, it will never be reached.

Otherwise, no dont use it, it only compilcates your code, cause you have to create duplicates of "DestroyGroup", and even if it was faster, it would be so small performance gain that noone ever would notice it. You wouldnt even gain 1 microsecond from it, and to get 60 fps you need to make the frame run in 16.6 milliseconds
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
follow this simple rule: Destroy any created object in scope of creation(if it doesnt need to persist).

Basically, if you created the Group outside of If-else block, you should destroy it outside. It prevents potential leaks as well as removing code duplication, which in turn makes your map smaller(Ah who am I kidding, its like 20 bytes per line :D). If you created the group inside the if-else block, you should remove it in the same block(the same reasoning)

I have yet to come to a GUI script that really requires "Skip Remaining Actions"
 
Level 17
Joined
Jun 17, 2010
Messages
2,275
No i was just curious. Y'know, learning new things and all. And yeah, i created the group outside so i originally planned to put the destroy outside aswell, but then i thought i dont want the game checking every single condition before reaching the destroy group. So i just wanted to see if skip remaining actions had any merit.
 
Could you show more of what your trying to do? Maybe you could solve this with a loop check in order to cut down on function calls.

As long as there is no waits or delays and fast enough per player's units then unit group outside of the nested/not nested if's should work fine.
You don't want to create stuff for a empty unit-group after all.
 
Level 17
Joined
Jun 17, 2010
Messages
2,275
  • Untitled Trigger 002
    • Events
      • Dialog - A dialog button is clicked for Select_Luck
    • Conditions
    • Actions
      • Set Random_Integer = (Random integer number between 1 and 100)
      • Set StartingUnit_Group = (Units owned by (Triggering player))
      • Unit Group - Pick every unit in StartingUnit_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to LuckiestButton
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Random_Integer Less than or equal to 22
                • Then - Actions
                  • Hero - Create Winning Lottery Ticket and give it to (Picked unit)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to LuckyButton
            • Then - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to NonBelieverButton
            • Then - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to UnluckyButton
            • Then - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Clicked dialog button) Equal to UnluckiestButton
            • Then - Actions
            • Else - Actions
Thats the wip
 
Dialogs are for one player at a time right? Otherwise there will be problems because every click after the first player seems to return null. It is a buggy event. I even attempted to get past this bug with dialog arrays and a new dialog button array variable for each button and sadly It didn't work because it is the event itself.

Evidence: http://www.hiveworkshop.com/forums/submissions-414/system-dialog-button-254366/

I suggest to visually remake the dialog system yourself and exploit GetLocalPlayer or invisibility however looking to see what can be done about that wall.

Edit: From what I can see since it uses dialog, you can't really do much... Nested would be better if you combine it with skip remaining lines which would look better however in its current state without being nested it is fine as well as long as you add skip remaining things in each check.
 
Status
Not open for further replies.
Top