UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: StraightArrow on March 26, 2019, 09:56:33 pm

Title: Have what I believe to be a race condition. How do I lock the variable/avoid thi
Post by: StraightArrow on March 26, 2019, 09:56:33 pm
Code Snippet
cpp
while(1)
{
//iprintln("in the while loop!");
currentweapon = players[i] getCurrentWeapon();
if(currentweapon == "m2_flamethrower_zombie_upgraded")
{
while(players [i] isfiring())
{
if(players [i] isMeleeing() == false && jump_param <200) //300 before
{
//wait .02; //the function works ok without this. the problem is tap firing. after firing there is a slight delay until the hud catches up. the wait simulates this slightly
jump_param = jump_param + 4.0;
//iprintln("in first func jump param is going up and " + jump_param );

thread flamey_jump(jump_param);

}
//there just needs to be a little wait time between these two. have too many waits now the flamethrower is jumpy
wait .05;
}
wait .2;
while ( players[i] isfiring() == false && jump_param >0 || players[i] isMeleeing() == true)
{

if (jump_param >= 200) //300 before
{
wait 1.5;
jump_param = jump_param - 3;
}
//if (jump_param >0)
//{
//thread flamey_jump(jump_param);
wait .08; //this is the problem right here, i need to wait to make the thing more sensitive but that holds up the lift up part, gotta figure it out
jump_param = jump_param - 1;
iprintln("in first func jump param is going down and " + jump_param );
//}
//continue; //thread flamey_jump(jump_param);
}




//thread flamey_jump(jump_param);

}
wait .05;


flamey_jump(jump_param)
 {
players = get_players();
for (i = 0; i < players.size; i++)
{

if (isDefined( jump_param ))
{
iprintln("in second function jump_param is " + jump_param);
}

//i think what is happening here is a race condition (especially with a while loop)
if(jump_param<200) //setting this to while causes jump_param to go beserk and change values in the loop. want to change this to while so this can execute without waiting on 1st while loop
{
// etc. etc. lets the player fly. if i check jump_param in here it is wrong by the way



I have what I believe to be a race condition. I would prefer to set the flamey_jump function's if statement to a while statement (so it can run without waiting on 'waits' in the first function), but the variable jump_param will go beserk and return the wrong values (even though they are correct with the variable check on the line just before). So the flamey_jump code will execute forever basically. I'm sure threading flamey_jump multiple times a second from the first while loop isn't helping either, but I want to constantly be feeding that variable into the 2nd function to know whether to allow flight or not.  I am a very junior scripter so I probably have this all ass backwards (go easy on me).