For example, which of the following methods is better:
Code: Select all
GetRandomReal(0, 1) <= 0.33
GetRandomInt(1, 100) <= 33
And any general notes on stuff like this would be appreciated
Code: Select all
GetRandomReal(0, 1) <= 0.33
GetRandomInt(1, 100) <= 33
So the integer IS better, because there are a finite number of integers between 1 and 100, and an infinite number of numbers between 0 and 1?Oxygen wrote:Less numbers and less calculus = more efficient :]
That would sound so right!Greenspawn wrote:So the integer IS better, because there are a finite number of integers between 1 and 100, and an infinite number of numbers between 0 and 1?Oxygen wrote:Less numbers and less calculus = more efficient :]
So would it be better to:Rectifier wrote:Computers use a lot of resources for iterative processes, like calling a function within a function, and algorithms that solve abstract problems, like calculus.
Code: Select all
SetUnitPositionLoc( GetEnumUnit(), GetUnitLoc(GetSpellAbilityUnit()) )
Code: Select all
local unit u = GetEnumUnit()
local unit v = GetSpellAbilityUnit()
SetUnitPositionLoc(u, GetUnitLoc(v) )
Code: Select all
SetUnitPosition(GetEnumUnit(), GetUnitX(GetSpellAbilityUnit()), GetUnitY(GetSpellAbilityUnit())
bobo!TheDeathstalker wrote:Next to Vex himself, I don't think there's too many people who are on the same tier as Dusk in terms of both knowledge of JASS
yuck nevermindTheDeathstalker wrote:and contribution to the community as a whole.
What about when creating special effects at a point? Or creating units at a point?Rising_Dusk wrote:The better solution is to not use locations at all, but rather use coordinates and then SetUnitX() and SetUnitY(). The thing with what you're doing in the first one is that you're leaking the location returned by GetUnitLoc(). Coordinate reals don't leak, though, so you could inline it.Code: Select all
SetUnitPosition(GetEnumUnit(), GetUnitX(GetSpellAbilityUnit()), GetUnitY(GetSpellAbilityUnit())
Code: Select all
call AddSpecialEffectLoc("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", Location(GetLocationX(GetUnitLoc(GetEnumUnit())), GetLocationY(GetUnitLoc(GetEnumUnit()))) )
Code: Select all
native Location takes real x, real y returns location