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

Problem with locals

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi!

I'm learning a bit of JASS; and found that locals are faster than globals, and works only in the designed function, but my locals include some 'variable' variables.

  • Damage Itself
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • Custom script: local real PDam = ( LoadRealBJ(1, udg_I_DS, udg_DamageHash) * ( 1 - LoadRealBJ(2, udg_I_DU, udg_DamageHash) ) )
As you can see, I work with "udg_I_DU" and "udg_I_DS" which means "ID of Damaged Unit" and "ID of Damage Source" respectively. My DamageSource and DamagedUnit works differently (in the data retrieve) if they're a Hero Unit, or if they're a common creep. Hero data is retrieved by player number, while creep data is based on the unit-type Id.

The thing is, locals have to be at the top of the function, and I can't declare I_DS and I_DU (depending on if it's a hero or not) before setting the locals.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can write

JASS:
local varType a = value
local varType b = a

You can also write

JASS:
local varType a
//do stuff
set a = value

Locals may be slightly faster than globals in reading and writing but their creation/release also takes some performance, not that it should be noticeable though.
 
Level 12
Joined
Oct 16, 2010
Messages
680
if u try to set a local which depends on some sort of conditions
than you should make a function that sorts it out for u

something like this:

function IsHero takes unit u returns *i think integer cus that is the type of Ids*
//make your calculations or anything here
endfunction


local integer I_DS = IsHero(*the unit you want to check*)
local integer I_DU = IsHero(*the other unit*)
Custom script: local real PDam = ( LoadRealBJ(1, udg_I_DS, udg_DamageHash) * ( 1 - LoadRealBJ(2, udg_I_DU, udg_DamageHash) ) )
but in this case u should do the whole in custom text, that would be clearer i think but your choice

i could imagine something like this
 
Are "udg_I_DS" & "udg_I_DU" meant to be locals, or you're actually using them as globals? If you what those ints to be ids of DamagedUnit/DamageSource respectively you can either:

  • Damage Itself
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • Custom script: local real PDam = LoadReal(udg_DamageHash, GetHandleId(udg_GDD_DamageSource), 1)*( 1 - LoadReal(udg_DamageHash, GetHandleId(udg_GDD_DamagedUnit), 2))
Or if you really want to work with those two global vars:
  • Damage Itself
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
    • Actions
      • Custom script: local integer I_DS = GetHandleId(udg_GDD_DamageSource)
      • Custom script: local integer I_DU = GetHandleId(udg_GDD_DamagedUnit)
      • Custom script: local real PDam = LoadReal(udg_DamageHash, I_DS, 1)*( 1 - LoadReal(udg_DamageHash, I_DU, 2))
      • Custom script: set udg_I_DS = I_DS
      • Custom script: set udg_I_DU = I_DU
Additionaly: why not pure jass if everything is CS anyways?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I don't do pure jass because I still get confused and don't feel really comfortable with JASS yet.

Spinnaker, the thing is that "IF" the DaamgedUnit or DamageSource is a hero, I_DS or I_DU = Player Number of Owner of Unit"; and "IF" The DamagedUnit or DamageSource is a creep, I_DS or I_DU = the hashtable value.

So far, I think I'll leave it like it is :) Is easier, and Locals aren't really that needed in this.

Thanks!
 
Avoid using BJ's coz it's calling another function and/or native, but not all BJ's are bad...

  • Custom script: local real PDam = LoadReal(udg_DamageHash, GetHandleId(udg_GDD_DamageSource), 1)*( 1 - LoadReal(udg_DamageHash, GetHandleId(udg_GDD_DamagedUnit), 2))
setting a global to local's value is not needed coz the the DamagedUnit and
DamageSource is already a global and you can retrieve their ID via those units
even in another trigger/function...
 
Status
Not open for further replies.
Top