Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Why on earth dosen't this work...
Why on earth dosen't this work...
2005-06-22, 7:44 AM #1
Code:
# Jedi Knight Cog Script
#
# ITEM_FIELDLIGHT.COG
#
# INVENTORY Script - Field Light
#
# [CYW & YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

thing       player
int         actorFlags

message     activated
message     pulse
message     killed

sound       lightActivate=activate04.wav
sound       lightDeactivate=deactivate04.wav

int mode=0 local

end

code

   activated:
   player = GetSourceRef();
   mode = mode + 1;
   if(mode > 3) mode = 0;
   if (mode == 1)
   SetActorExtraSpeed(player, 1);
   Print("Speed 1");
   else if(mode == 2)
   SetActorExtraSpeed(player, 2);
   Print("Speed 2");
   else if(mode == 3)  
   SetActorExtraSpeed(player, 3);
   Print("Speed 3");

return;

end


When I add the SetActorExtraSpeed() lines, it dosen't work. It works fine without them though.

Any ideas? This seems quite strange...

ReT
2005-06-22, 11:19 AM #2
Put braces (aka curley brackets) around the code for each if statement, like so :)

Code:
   activated:
   player = GetSourceRef();
   mode = mode + 1;
   if(mode > 3) mode = 0;
   if (mode == 1)
   {
      SetActorExtraSpeed(player, 1);
      Print("Speed 1");
   }
   else if(mode == 2)
   {
      SetActorExtraSpeed(player, 2);
      Print("Speed 2");
   }
   else if(mode == 3)  
   {
      SetActorExtraSpeed(player, 3);
      Print("Speed 3");
   }

return;
May the mass times acceleration be with you.
2005-06-22, 1:56 PM #3
Yeah, if you wanna do more than one command in an if block, you need to enclose it in { }. Same counts for while, etc., I guess.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-06-22, 7:46 PM #4
Incase you want to know WHY that caused it, the else statement was looking for an if statement, but instead found the print. If you use the brackets {}, then the end bracket will reference the else statement back to the if(). Otherwise, it doesn't know what "else" to do with the print :)
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2005-06-23, 10:55 AM #5
Wow, I didn't know JK read curly brackets.

Thanks everyone.

ReT

↑ Up to the top!