local inrad = LocalPlayer():GetShootPos():Distance( self:GetPos() ) < self.Params.UseDistance
I was reading this from an addon. It’s defining inrad to a vector, but what does it mean to put < self.Params.UseDistance at the end?
local inrad = LocalPlayer():GetShootPos():Distance( self:GetPos() ) < self.Params.UseDistance
I was reading this from an addon. It’s defining inrad to a vector, but what does it mean to put < self.Params.UseDistance at the end?
It’s basic math, the < checks if the side on the right is bigger and for > it would be if the side on the left is bigger
As Zombie said, it’s checking if a number (distance) is less than another number (.UseDistance)
As a result, inrad will be a boolean of either true or false.
Oh I see, thanks for clearing that up.
[editline]15th December 2014[/editline]
I have another question.
local rb_selected = cactive and inrad and canrecharge and
cx >= rb_x and cx <= rb_x + rb_w and
cy >= rb_y and cy <= rb_y + rb_h
What is the ‘and’ doing in this?
It’s just checking to see if all of those variables and conditions exist and are true.
They should learn to use brackets -.-
iirc brackets can only be used in tables
I meant this mess:
[lua]
local rb_selected = cactive and inrad and canrecharge and
cx >= rb_x and cx <= rb_x + rb_w and
cy >= rb_y and cy <= rb_y + rb_h
[/lua]
Writing it like this improves readability:
[lua]
local rb_selected = cactive and inrad and canrecharge and
(cx >= rb_x) and (cx <= (rb_x + rb_w)) and
(cy >= rb_y) and (cy <= (rb_y + rb_h))
[/lua]
For people that can’t handle a little bit of operator precedence.
It does improve readability though. If im skimming through code I prefer not having to waste time deciphering expressions.
As a fan of excessive parentheses, the code here is well formatted:
local rb_selected = cactive and inrad and canrecharge and
cx >= rb_x and cx <= rb_x + rb_w and
cy >= rb_y and cy <= rb_y + rb_h
And adding parentheses does not improve anything.