Quick question about variables

BoterhaM

New Member
Reaction score
2
Is it better to have 1 variable for each variable type (array) or is it better to have many variables with no array?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
most of the time it doesnt change anything...

Ask yourself, would you like it more to use 1 variable with array or to use many with different names?

just imagine you got to use one and the same variable in about 100 triggers and you got to keep all used arrays in mind so you wont use it twice...i guess after 20 triggers you would give up.
 

Romek

Super Moderator
Reaction score
964
Well. It'd be much easier to do for example "Quest1_UnitToKill" than "Units[6340]" all the time :p

Efficiency-wise, I don't think it makes a difference.
 

DiFm

New Member
Reaction score
35
If Your Using Integer Loops it's more useful and overall its just easier to not have to many variables.
 

Sirroelivan

Gunnerkrigg Court
Reaction score
95
If there is an actual purpose in using arrays, use them. Otherwise use non-arrayed variables.
 

LightChaosma

New Member
Reaction score
60
when using player related vars, use arrays, each index for each player. for temporary vars, use arrays. for map controllers, for instance the player count, use non-arrays. use this advice, or dont use it, its all about what you think is easy to work with.
 

Flare

Stops copies me!
Reaction score
662
for temporary vars, use arrays.
Temporary vars don't need arrays

For the most part, I only use arrays when they are needed (if I needed to store a bundle of strings for randomized death messages, or something) - if variables are only being used temporarily, arrays aren't really needed since you're not going to overwrite values unless you fool around with waits :p
 

ManyTimes

I'm so lonesome I could cry...
Reaction score
293
for temporary vars, use arrays.
Temporary vars don't need arrays
Define temporary...

>>>Is it better to have 1 variable for each variable type (array) or is it better to have many variables with no array?
Neither, or yes, or no, what is good is to mix them, perhaps. It all depends on the situation, what you want to achieve, since you ask, do you have a trigger and you wonder if you are going to use an arrayed variable or not? If so, post the trigger, if not...

In short:
"If there is an actual purpose in using arrays, use them. Otherwise use non-arrayed variables."
 

LightChaosma

New Member
Reaction score
60
Temporary vars don't need arrays

For the most part, I only use arrays when they are needed (if I needed to store a bundle of strings for randomized death messages, or something) - if variables are only being used temporarily, arrays aren't really needed since you're not going to overwrite values unless you fool around with waits :p


sometimes i cant seem to find a way arround having to use multiple temp integers, i have a nice example the current map i'm working on:

Code:
p1 and 2
    Events
        Unit - A unit enters Region 005 Copy 2 <gen>
    Conditions
        (Custom value of (Triggering unit)) Equal to 1
        (Owner of (Triggering unit)) Equal to Player 9 (Gray)
    Actions
        Set temp_int[9] = (Random integer number between 3 and 8)
        Set temp_int[10] = 0
        For each (Integer A) from 1 to 8, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Player((Integer A))) slot status) Equal to Is playing
                    Then - Actions
                        Set temp_int[(Integer A)] = (Integer A)
                    Else - Actions
                        Set temp_int[(Integer A)] = 0
        For each (Integer B) from 1 to 8, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        temp_int[9] Equal to temp_int[(Integer B)]
                    Then - Actions
                        Set temp_int[10] = 1
                    Else - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                And - All (Conditions) are true
                                    Conditions
                                        (Integer B) Equal to 8
                                        temp_int[10] Not equal to 1
                            Then - Actions
                                Set temp_int[9] = (Random integer number between 3 and 8)
                                Trigger - Run (This trigger) (ignoring conditions)
                                Skip remaining actions
                            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 2
            Then - Actions
                Set temp_int[9] = 1
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 1
            Then - Actions
                Set temp_int[9] = 1
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 3
            Then - Actions
                Set temp_int[9] = 2
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 4
            Then - Actions
                Set temp_int[9] = 2
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 5
            Then - Actions
                Set temp_int[9] = 3
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 6
            Then - Actions
                Set temp_int[9] = 3
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 7
            Then - Actions
                Set temp_int[9] = 4
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                temp_int[9] Equal to 8
            Then - Actions
                Set temp_int[9] = 4
            Else - Actions
        Unit - Move (Triggering unit) instantly to (Center of tel_1_reg[temp_int[9]]), facing (90.00 x ((Real(temp_int[9])) + 2.00)) degrees
        Set temp_point[1] = (Position of (Triggering unit))
        Special Effect - Create a special effect at temp_point[1] using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
        Special Effect - Destroy (Last created special effect)
        Custom script:   call RemoveLocation(udg_temp_point[1])
        Wait (Random real number between 1.00 and 5.00) seconds
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Triggering unit) is alive) Equal to True
            Then - Actions
                Set temp_point[1] = (Position of (Triggering unit))
                Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Other\Doom\DoomTarget.mdl
                Special Effect - Destroy (Last created special effect)
                Unit - Set life of (Triggering unit) to ((Percentage life of (Triggering unit)) + 7.50)%
                Custom script:   call RemoveLocation(udg_temp_point[1])
                Unit - Set the custom value of (Triggering unit) to 10
            Else - Actions

if you could tell me a way to have only 1 temp int here, please tell me;)
(don't, only if its a short explenation, i need to remove the random bit from this trigger anyway)
but there are situations where in my knowledge there is no other way then having to use multiple temp ints....
 

Flare

Stops copies me!
Reaction score
662
Well, I meant in the sense of something like
Code:
Set TempLoc = Position of (Triggering Unit)
Create 1 Dummy for (Owner of (Triggering Unit)) at TempLoc facing (Default building facing) degrees
Order (Last Created Unit) to Human Mountain King - Storm Bolt (Target Unit of Ability Being Cast)
Add a 3.00 second Generic expiration timer to (Last Created Unit)
Custom script:     call RemoveLocation (udg_TempLoc)
but in the case you gave above, arrays would be a better option
 

LightChaosma

New Member
Reaction score
60
in that case you are right, but at some times when using points you have to use 2, 1 as the position of the caster, and 1 for the position where the ability has to be cast for example skill blizzard). i usually make my temp's arrays of size 100, so i never run short of places, until now i've used a max of 13 in 1 trigger
 

Flare

Stops copies me!
Reaction score
662
i usually make my temp's arrays of size 100
(In most cases) the size specified doesn't make a difference - that only determines how many of the array indexes are initialized to a value, and that doesn't really matter with most types other than unit groups (if you are using the groups for 'long-term' storage), timers (since they have to be created before being used, and if you don't specify an adequate array size you will be starting non-existant timers) and, possibly, player groups (not sure about these)
 

ManyTimes

I'm so lonesome I could cry...
Reaction score
293
It all depends on how you use the variables...jesus. If you use "set" then initialization size does not matter, if you use "add" or, not set, which mean you do not initialize it then the size does matter, because it needs to be initialized whatsoever.
Code:
Set unitgroup[3523] = (Units in (Playable map area))
Size does not matter
Code:
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Unit Group - Add (Picked unit) to unitgroup[232])
Here size matters.

And the trigger of chaosma is lol, if he only bothered to also describe what the trigger should do... well, at least it can be optimized.
 
General chit-chat
Help Users
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top