Blockland Forums > Modification Help

Else if

Pages: (1/2) > >>

MrPickle:

How do you use Else if? like this?:


--- Code: ---function blah(%client){
if(%client.isAdmin){
//blah de blah
} else if(%client.isSuperAdmin){
//blah de blah
}
--- End code ---

Is that how you use else if's?

DarkKnight:


--- Code: ---function klol(%yourmom)
{
  if(%yourmom == 1)
   {
     // omg codes lul
  }
  else
   {
 // bend over plz
  }
}
--- End code ---


Space Guy:

Nearly, you missed a } though:

--- Code: ---function blah(%client){
 if(%client.isSuperAdmin)
 {
  //Super
 }
 else if(%client.isAdmin)
 {
  //Admin
 }
 else
 {
  //None
 }
}
--- End code ---

Also, for certain uses the switch and switch$ statements exist:

--- Code: ---function ChooseClass(%client)
{
 %classNum = getRandom(0,3);
 switch(%classNum)
 {
  case 0:
   return "Warrior";
  case 1:
   %client.player.tool[0] = bowItem;
   messageclient(%client,'msgItemPickup',"",0,nametoID("bowItem"));
   return "Archer";
  case 2:
   messageclient(%client,"","\c5You are now a White Mage! Go to the Rune Shop and buy magical Runes.");
   return "White Mage";
  default:
   echo("It's not any of the ones above, return the default:");
   return "Trader";
 }
}
--- End code ---

switch$ functions in the same way, except it checks for strings:

--- Code: ---function servercmdLoadType(%client,%filename)
{
 if(!%client.isSuperAdmin){return;}
 if(%filename $= ""){messageclient(%client,"","\c0ERROR: \c3No filename given.");return;}
 messageclient(%client,"","\c5Loading bot type from file \c3Add-Ons/Client/" @ %filename @ ".bottype\c5...");
 $BotSettings[%filename]=0;
 %file=new fileObject();
 %file.openForRead("Add-Ons/Client/" @ %filename @ ".bottype");
 while(!%file.isEOF())
 {
  %line=%file.readLine();
switch$(firstWord(%line))
{
case "DECAL":
$BotDecal[%filename] = restWords(%line);
case "FACE":
$BotFace[%filename] = restWords(%line);
case "DATA":
$BotData[%filename] = restWords(%line);
case "NAME":
$BotName[%filename] = restWords(%line);
default: //Setting appearance
$BotAppear[%filename,$BotSettings[%filename]++] = firstWord(%line);
$BotColor[%filename,$BotSettings[%filename]] = restWords(%line);
}
 }
 %file.close();
 %file.delete();
 messageclient(%client,"","\c5Finished loading. Bot type added: \c3" @ %filename);
}
--- End code ---


MrPickle:

Thanks!

Wtf's wrong with this? It just gives me this syntax:


--- Code: ---datablock TriggerData(KillBTrigger)
{
   tickPeriodMS = 100;
};

function ##K##illBTrigger::onEnterTrigger(%this,%trigger,%obj){
   %obj.kill();
}
--- End code ---


Space Guy:

It may be something further up in the code which is causing the problem. Whole/more of the script, please?

Pages: (1/2) > >>

Go to full version