As a side note, you don't need a var equal to 1 to make a while loop, just "while(1)" is all you need. If a condition is used, then that's a different case.
To make the text disappear, have:
info1.visible = off;
before the wait instruction in the first if statement. To make it reappear, have the same thing copied just after the else part only with "on" instead of "off". Like this:
Code:
text info1
{
pos_x = 4;
pos_y = 10;
layer = 15;
string = "";
flags = visible;
}
entity* Max2_MDL_001;
action displayinfo1
{
Max2_MDL_001 = me;
var i=1;
while(i)
{
if(vec_dist(me.x, plBiped01_entity.x) > 150)
{
info1.visible = off; // too far, text is invisible
wait(1);
}
else
{
info1.visible = on;
info1.string = "this text appears when u get near the char";
i=0;
wait(1);
}
}
//i=1;
}
}
I provided the tabbing so you can better see the structure.
Color-coded notes:
Red - hazardous - often causes compiler errors
Orange - caution - avoid doing these
Yellow - a note - otherwise harmless
Green - a fix I made
Red - Going down the list, in the text object declaration, you do not need to declare a string right away. Although this won't do anything, it is not essential and you can go without.
Orange - To get a while loop to work, having this is not neccessary. Although it won't do much damage, it can cause a slowdown (extremely slight) and use up 4 bytes of memory (extremely miniscule).
Green - This makes the text object invisible. If the distance is greater than 150 quants, the text will not be visible.
Green - This makes the text object visible. If the above condition is not true (within 150 quants), the text will become visible.
Orange - Having this, given your while loop, it could become false. Unless you want to terminate the loop, you do not need this.
Green - If the else condition is always used the while loop will run indefinitely long and cause the engine to terminate showing an error of a possible endless loop. This fixes this bug. Not all while loops use the wait(1); instruction, most commonly in those that can become false.
Orange - Although commented out, because this is outside the while loop, it won't have any effect at all. All instructions within a while loop are repeated.
Red - You have an extra brace which will likely cause compiler errors or strange, unexpected effects if this code is added on to. It's best to get rid of it.
Hopefully this'll explain a few things that need to be pointed out.