Object won't move cos of if statement? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Object won't move cos of if statement? (
/showthread.php?tid=457389)
Object won't move cos of if statement? -
Dokins - 11.08.2013
Basically, if I remove the if(dooropen == 0)
the object moves like it's supposed to, but I need the if statements to allow it to be used in the manner I need it.
dooropen is a global variable
chaindoor is the object under ongamemodeinit
pawn Код:
CMD:door(playerid, params[])
{
if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
printf("door open = %d", dooropen);
if(IsPlayerInRangeOfPoint(playerid,3.0,321.45309, 310.08768, 998.14099))
printf("range check");
{
if(dooropen == 0)
{
printf("door open = %d", dooropen);
MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,-90);
printf("objectid = %d", chaindoor);
printf("object moved");
dooropen = 1;
printf("door open = %d", dooropen);
}
if(dooropen == 1)
{
printf("door open = %d", dooropen);
MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,360);
dooropen = 0;
}
}
return 1;
}
Re: Object won't move cos of if statement? -
Misiur - 11.08.2013
This line completely changes your code flow, remove it or move it.
You need an else clause. Learn to use it
pawn Код:
if(dooropen == 0)
{
printf("door open = %d", dooropen);
MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,-90);
printf("objectid = %d", chaindoor);
printf("object moved");
dooropen = 1;
printf("door open = %d", dooropen);
} else {
printf("door open = %d", dooropen);
MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,360);
dooropen = 0;
}
https://sampwiki.blast.hk/wiki/Control_Structures#else
Re: Object won't move cos of if statement? -
Dokins - 11.08.2013
Quote:
Originally Posted by Misiur
This line completely changes your code flow, remove it or move it.
You need an else clause. Learn to use it
pawn Код:
if(dooropen == 0) { printf("door open = %d", dooropen); MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,-90); printf("objectid = %d", chaindoor); printf("object moved"); dooropen = 1; printf("door open = %d", dooropen); } else { printf("door open = %d", dooropen); MoveDynamicObject(chaindoor,321.45309, 310.08768, 998.14099,1.0,0,0,360); dooropen = 0; }
https://sampwiki.blast.hk/wiki/Control_Structures#else
|
Much appreciated, however, I AM learning, that's why I asked.