I was going to do that, which would be a little more work, but then I started thinking. Why would this work...
I have about 6 dynamic lights set up and this works perfectly to shut them off one at a time when I get too far away from them.
Code:
while(1)
{
wait(1);
if(vec_dist(player.pos,my.pos)>=2000)
{
my.lightrange=0;
}
if(vec_dist(player.pos,my.pos)<2000 && lightsoff!=1)
{
my.lightrange=200;
}
}
why won't this work? It only changes the stealth_trigger variable at one of the six light spots I have set up. Yet will use the same vec_dist to check whether or not the variable should be changed and doesn't work at all.
Code:
while(1)
{
wait(1);
if(vec_dist(player.pos,my.pos)>200)
{
stealth_trigger=1;
}
if(vec_dist(player.pos,my.pos)<200)
{
stealth_trigger=0;
}
}
Would it be because, what is changing in the first part is something that is related to entity itself? And the variable stealth_trigger is sort of global in comparison to the light ranges I'm changing with the other section of code.
Okay I went back just now and tried something else. It seems that the code works. I just forgot one important fact, that when I'm testing the distance of these entitys, that if I tell the program that stealth_trigger=0 when I'm too far away from that paticular light source or entity, that it will be setting that variable to zero as long as I'm too far away from that light source or entity.
I have a terrible solution to this, but it actually worked for me. instead of even finding out whether or not to shut off stealth trigger when I'm too far away, I shut it off indefinitely, and then when I'm close enought to the light source, turn it on. It serves it's purpose, but in a weird spastic kind of way. So the variable is turning on and off rapidly. I guess that's better than it not turning on and off at all. Either way, when the player is detected near a light source it works all the same.
Thanks for all the suggestions and help.