• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Get your art tools and paintbrushes ready and enter Hive's 34th Texturing Contest: Void! Click here to enter!

Quick Custom Script Question.

Status
Not open for further replies.
Level 14
Joined
Oct 18, 2013
Messages
724
Just a quick tidbit. My syntax is incorrect for this, but idk what's wrong xD

Also, I need advice for efficiency. Statboost[0] needs to be a real because it varies from .1 to .3. However, Statboost[1] is converted to an integer anyways when it is added to a heroes stat. So should I just use an integer variable for Statboost[1]? Converting a real to an integer for statboost[0] would just be:
R2I(udg_StatBoost[0]) right?

set udg_StatBoost[1] = (GetHeroStr(udg_Hero[2], true) * (udg_StatBoost[0])
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
Also, I need advice for efficiency. Statboost[0] needs to be a real because it varies from .1 to .3. However, Statboost[1] is converted to an integer anyways when it is added to a heroes stat. So should I just use an integer variable for Statboost[1]? Converting a real to an integer for statboost[0] would just be:
R2I(udg_StatBoost[0]) right?
The JASS interpreter (well its sort of a virtual machine but interprets all named types) is so slow that there is practically no measurable difference between real and integer. Where as in Java and C/C++ the integer would clearly be the best choice (since floats are slow), in JASS it just makes no real difference. I would stick with reals purely for convenience.

Only use arrays if you intend for the index to be accessed dynamically at some stage. If It is always constant then use non-array globals as JASS does not optimize out the static array access.
 
Level 14
Joined
Oct 18, 2013
Messages
724
Only use arrays if you intend for the index to be accessed dynamically at some stage. If It is always constant then use non-array globals as JASS does not optimize out the static array access.
So you suggest I use 2 real variables for this?

For different variable types I've sometimes used arrays for ease of not having to create multiple variables. Replacing all the variable arrays with variables would probably more time than it is worth, but I'll keep that in mind for the future.
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
So you suggest I use 2 real variables for this?
Yes, unless you plan on doing something iterative with the array, using it as an index system etc.

In C/C++ you would find that constant indexes would be optimized out into direct non-array accesses thus making no difference in the end. For example.
Code:
// volatile is used to force memory writes, otherwise it would just inline everything.
volatile int result;

// this code...
volatile int somearray[2];
somearray[0] = 1;
somearray[1] = 2;
result = somearray[0] + somearray[1];

// should (not 100% sure) compile identically to this code...
volatile int someint;
volatile int anotherint;
someint = 1;
anotherint = 2;
result = someint + anotherint;
Sadly I doubt JASS is that smart.
 
Status
Not open for further replies.
Top