Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Mötley on Jul 25, 2016, 05:49 PM

Title: While/if on player command
Post by: Mötley on Jul 25, 2016, 05:49 PM
Okay so I happened to have a busy life style and happened to get around to re understanding squirrel again.

The following words if while are reserved words by the squirrel language and cannot be used as identifiers. Sometimes I wondered why I never seen while in a command system instead of just if,

I really got curious when I got around to a very strong command system where as I feel that while would have different usage than if in these next two scripts

Version: 1
function UnknownCommand(plr) {
  MessagePlayer( "Invalid command", plr );
}

function onPlayerCommand( plr, cmd, args )
{

local level = USER_LEVEL[plr.ID];

// Process commands here
// Every command should return 1 or true to say its a valid command

if ( ProcessAccountingCommands( plr, level, cmd, args ) )
return 1;

if ( ProcessAdministratorCommands( plr, level, cmd, args ) )
return 1;
 
// Now lets validate incorrect commands

UnknownCommand(plr);

  return 1;
}

Version: 2

function UnknownCommand(plr) {
  MessagePlayer( "Invalid command", plr );
}

function onPlayerCommand( plr, cmd, args )
{

local level = USER_LEVEL[plr.ID];

// Process commands here
// Every command should return 1 or true to say its a valid command

while ( ProcessAccountingCommands( plr, level, cmd, args ) )
return 1;

while ( ProcessAdministratorCommands( plr, level, cmd, args ) )
return 1;
 
// Now lets validate incorrect commands

UnknownCommand(plr);

  return 1;
}

Just a simple question I know either works I just like to ask questions sometimes
Title: Re: While/if on player command
Post by: Stormeus on Jul 25, 2016, 06:22 PM
Why would you? The functions only run once. Using while over if the way you suggest would technically work, but it also makes it far more difficult to figure out what your code is trying to do at a glance.
Title: Re: While/if on player command
Post by: Mötley on Jul 25, 2016, 06:26 PM
THANK YOU!!

@Stormeus that's the answer I was looking for. I noticed it happened to work as well but the definition I was referring to was off and wrong and not what you stated.

QuoteUsing while over if the way you suggest would technically work, but it also makes it far more difficult to figure out what your code is trying to do at a glance.