path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);
// Get next node - actual vector location
// I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
I think the error may lie with "vec_next_node".
WRONG!!
This is in fact quite wrong... path_getnode is like vec_set but you only have the one vec to fill so the function finds the node you name "3" and puts it's real vec into vec_next_node
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on
}
if(pathSetNum == 2)
{
my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO
// 4.
}
This is where the error happens. You are seeing it running twice. first it runs if(pathSetNum == 1) then it runs if(pathSetNum == 2), That is why you see the back and forth.
So how is that happening?
1) the code that sets pathSetNum = X is setting it back and forth to 1 and 2.
2) there are two instances of path_setter() running, one set at pathSetNum = 1 and the other at pathSetNum = 2. These to running loops are fighting each other.
My bet is Number 2 - and this is how we will test -here is your new code, if this fixes, than the error is number 2, if not the error is at number 1
This code is a test - How to use this. Run this function and watch the debug_var(test_var,525); It should always be 0 or 1 never higher.. If it's higher you have many running function. Then use script 2 to fix.
action path_setter()
{
var TEST_VAR=0;
VECTOR vec_next_node;
path_set(my,"path_001");
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
}
if(pathSetNum == 2)
{
my.NODE_NEXT=4; // SET THE NODE
}
while(1)
{
TEST_VAR=proc_status2 (path_setter, my)
// PATH NODE DETECTION AND FACING //////////////////////////////////
if(vec_dist(my.x,vec_next_node.x) < 80)
{
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on
}
if(pathSetNum == 2)
{
my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO
// 4.
}
}
path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);
// Get next node - actual vector location
// I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new
// node
DEBUG_VAR(my.NODE_NEXT,500);
DEBUG_VAR(TEST_VAR,525);
wait(1);
}
}
Script 2 fixes the issue, however fixing your bad code is perfered to killing functions.
action path_setter()
{
proc_kill2(path_setter,my);
VECTOR vec_next_node;
path_set(my,"path_001");
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
}
if(pathSetNum == 2)
{
my.NODE_NEXT=4; // SET THE NODE
}
while(1)
{
// PATH NODE DETECTION AND FACING //////////////////////////////////
if(vec_dist(my.x,vec_next_node.x) < 80)
{
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on
}
if(pathSetNum == 2)
{
my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO
// 4.
}
}
path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);
// Get next node - actual vector location
// I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new
// node
wait(1);
}
}
Your home work - read up on proc_kill and proc_status.
Mal