2015-05-26 19:23:32

There is a question:
What is absolute, and this? Help do not have this information!

2015-05-26 20:17:08

absolute is a function.
It returns the absolute value of a number.

int x=absolute(-10);
if(x==10) alert("Absolute", "Absolute worked correctly!");

"this" is a keyword which refers to the instance of a class which invokes its methods.
It is not a requirement to use "this" in bgt, but it can help distinguish class properties from method parameters.

class my_class {
int x=0;
int y=0;
int hp=100;
my_class@ target=null;

my_class(int x, int y) {
this.x=x;
this.y=y;
}

bool is_threat(my_class@ other) {
return @(other.target)==@this;
}

void set_target(my_class@ new_target) {
@target=new_target; // It is not necessary to use 'this' here,
// If you wanted to use 'this' to do the same thing, it would look like:
// @(this.target)=new_target;
}

bool is_ready() {
return @target!=null;
}
}

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-05-26 20:27:49

I do not understand about this!

2015-05-26 20:58:23

it might be better to explain what an absolute value is. an absolute value is the value, that x is away from 0. for example; the absolute value of 4 is 4. because 4 is 4 away from 0. likewise, the absolute value of negative 4 is also 4. why? because negative 4 is also 4 away from 0. its not expressed negative because it doesn't matter if the number is negative or positive. you are just worried about how far x is away from 0. hope this helps.
the ways you might need an absolute value varies depending on the language and the type of thing you are trying to code. but refer to post 2 for an example of how to implement it in code.

I don’t believe in fighting unnecessarily.  But if something is worth fighting for, then its always a fight worth winning.
check me out on Twitter and on GitHub

2015-05-26 21:01:54

give an example! acceptable as checked with absolute am I against the enemy in 5 positions?

2015-05-26 21:25:16

Yes. Actually, that is one of the most common usages.

if(absolute(player.x-enemy.x)<=5) {
enemy.shoot();
}

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.