• 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.

Array or Simple Int,Reals?

Status
Not open for further replies.
Level 1
Joined
Jan 11, 2020
Messages
5
Hello to all hiveworkshopers. Im newcomer for W3 GUI and a newbie to programmer area. So i have a basic question that i searhed but i coudnt fiind an answer.
My question is:
First look at my script here.
  • Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Renew
      • ((Casting unit) is A Hero) Equal to True
    • Actions
      • Set reInt = 0.00
      • Set reCaster = (Casting unit)
      • Set reTarget = (Target unit of ability being cast)
      • Set reAb = (Ability being cast)
      • Set reArry[1] = (Real((Level of reAb for reCaster)))
      • Set reArry[2] = (Real((Intelligence of reCaster (Include bonuses))))
      • Set reArry[3] = (Real((Max HP of reTarget)))
      • Set reDur = (Ability Cooldown of reCaster for ability reAb, Level: (Integer((reArry[1] - 1.00))))
      • Trigger - Turn on rePeriod <gen>
You see i have and Real Array name reArry for storing my veriables.
Quetion. Is is more memory efficient than using different realVeriables instead 1 array. ( like reLevelofAbility, reMaxHp, reCasterInte...)?
 
Last edited:
Level 9
Joined
Jul 30, 2018
Messages
445
More efficient computing power wise? Just like that, I don't think there's much difference. But arrays can be utilized in a way which I think does make them a lot more efficient (at least for the human coding it, if not for the computer itself), since you can more easily use loops to quickly go through the information stored in the variables.
 
Level 8
Joined
May 21, 2019
Messages
435
You see i have and Real Array name reArry for storing my veriables.
Quetion. Is is more memory efficient than using different realVeriables instead 1 array. ( like reLevelofAbility, reMaxHp, reCasterInte...)?

The efficiency of both is so extremely high, that whatever the difference may be, you aren't going to ever notice.

There's a lot of other benefits to using arrays whenever feasible though. The simplest one, is that your variable menu isn't going to get cluttered as fast. The far more interesting one, is when you use the variable indices to optimize your code. For example, if you have an array of heroes belonging to players 1-12, you can literally refer to each and every one of them by using something like "heroes[(player number)", meaning that you can code a function for all 12 players at once, rather than copy pasting it and replacing the player every time.
It also works wonders with loops.

But in terms of optimization? Nah. Pay attention to your use of large unit groups, graphics, rapid periodic events, locations, and similar game concepts.

As a rule of thumb, your computer is extremely good at crunching numbers and running through data. It's the very thing it was initially built to do.
Your computer can easily count from 1 to 1.000.000 in the blink of an eye, but if you ask it to render a shadow on a 3D terrain cast from a 3D object, you've got yourself a heavy computational task that can take anywhere from minutes to hours per frame. This is why things like light and shadow mechanics are usually kept simple in games, and even then, often have "quality" sliders on shadows still.

The closer the thing you're doing is to something you could in theory do with a paper and pen, the faster your computer is going to be able to do it, because you're basically utilizing the primary function of a computer. In a video game, there's a million things happening all at once, all over the place, and interacting with any object in the game, may actually require adjustments on many different levels to function properly. Whether a unit is in an array or in a variable, you're really just setting a single ID reference to a unit in either case. But if you move the unit to a new location, the game needs to run who knows how many computations to take into account every single way that this affects the state of the game, all the way down to the lowest levels of abstraction. When dealing with primitive data or very simple data objects like Integers, Reals, and Strings, you're already very close to the very lowest level of abstraction, so there isn't a massive framework of complexity underneath it, and you can be certain that it will run very fast.
 
Something like Cespie mentioned, if all players have one hero, then it might be good to use arrays, as he pointed out. It's because all heroes might have the same base for usage, and can be handled efficiently with loops etc..

But things that don't have same base for usage and are handled differently, like maybe Damage, Range, LevelOfAbility etc... those things should not be put into the same array to work with.

It's not intuitive to read or to debug something like "Unit Deals <Real[12]> Damage in <Real[7]> Radius Over <Read[9]> Seconds". It's horrible in my opinion.

And as it's in the first posted code example, I also think it's bad practice to store an int (ability level) into the real array, only for the purpose you don't need an other int variable. Better store it in the correct variable type, and only convert it at an concrete usecase, if required.
 
Status
Not open for further replies.
Top