There is a question:
What is absolute, and this? Help do not have this information!
Pages 1
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → absolute and this
There is a question:
What is absolute, and this? Help do not have this information!
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;
}
}
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.
give an example! acceptable as checked with absolute am I against the enemy in 5 positions?
Yes. Actually, that is one of the most common usages.
if(absolute(player.x-enemy.x)<=5) {
enemy.shoot();
}
AudioGames.net Forum → Developers room → absolute and this
Generated in 0.019 seconds (42% PHP - 58% DB) with 9 queries