Author Topic: comparisons/ variable logic error  (Read 689 times)

I am trying to make a server command that when you type /rof, it automatically turns you right and mousefires
i have
Code: [Select]
function servercmdrof()
{
if(%on<=0)
{
mousefire();
turnright(1);
%on=1;
echo(%on);
break;
}
else if(%on>=1)
{
mousefire();
turnright();
%on=0;
echo(%on);
break;
}
else
{
%on=0;
echo(%on);
break;
}

}
it works the first time i type /rof, so it spins me and fires, but the second time i use it it just stops mousefire and continues to spin.
am i missing something?

1. You're breaking instead of returning. break; exits loops, return; exits functions
2. In the second conditional shouldn't it be turnright(0); to turn it off?


You're mixing clientside code/functions and serverside functions.

mousefire and turnright are clientside only commands that can't be called from the server. You're also using %on which is a local variable and doesn't exist at the top of the function so the program will always go into the first condition only. Basically its a mess.

Just to clarify, the /command will only work for you and if anyone else on the server does it, it'll just make you spin and fire - not them.

You're mixing clientside code/functions and serverside functions.

mousefire and turnright are clientside only commands that can't be called from the server. You're also using %on which is a local variable and doesn't exist at the top of the function so the program will always go into the first condition only. Basically its a mess.

Just to clarify, the /command will only work for you and if anyone else on the server does it, it'll just make you spin and fire - not them.

That makes much more sense, ill try to fix it, thanx ephi.

that also explains why it only echoed 1

edit: works perfectly now as far as i can tell

Code: [Select]
function servercmdrof()
{
if($on<=0)
{
mousefire();
turnright(1);
$on=1;
echo(%on);
return;
}
else if($on>=1)
{
mousefire();
turnright(0);
$on=0;
echo(%on);
return;
}
else
{
$on=0;
echo(%on);
return;
}

}
« Last Edit: April 09, 2009, 01:52:46 PM by Healbadbad »

Tom

That would work---- as clientside code.