Author Topic: Coding Help  (Read 921 times)

Code: [Select]
if($secondPack[%client.secondPack] !$= "epauletsRankA")
%client.player.HideNode("epauletsRank");
I want this code to work with 3 more "epauletsRankX"
Like:
Code: [Select]
if($secondPack[%client.secondPack] !$= "epauletsRankA")
%client.player.HideNode("epauletsRank");
if($secondPack[%client.secondPack] !$= "epauletsRankB")
%client.player.HideNode("epauletsRank");
if($secondPack[%client.secondPack] !$= "epauletsRankC")
%client.player.HideNode("epauletsRank");
if($secondPack[%client.secondPack] !$= "epauletsRankD")
%client.player.HideNode("epauletsRank");
But I want the code to be shorter like it will say if($secondPack[%client.secondPack] !$= "epauletsRankA") or "epauletsRankB" or "epauletsRankC" or "epauletsRankD"
then

%client.player.HideNode("epauletsRank");

Does it possible to short this?
« Last Edit: November 24, 2015, 06:39:39 PM by BlockAlpha »

you can use "and" and "or" statements as follows

Code: [Select]
%a = 1;
%b = 2;
if (%a==1 && %b==2 || "t" $= "q")
    return true;
else
    return false;
the above snippet returns true.

or = || (shift-] if i recall correctly)
and = &&


This can also work:
switch$($secondPack[%client.secondPack])
{
   case "epauletsRankA" or "epauletsRankB" or "epauletsRankC" or "epauletsRankD": //Does this variable have any of these?
      %client.player.unHideNode("epauletsRank");

   default: //No? Okay, just hide the node.
      %client.player.HideNode("epauletsRank");
}

Thank you very very very very much!!!

This can also work:
switch$($secondPack[%client.secondPack])
{
   case "epauletsRankA" or "epauletsRankB" or "epauletsRankC" or "epauletsRankD": //Does this variable have any of these?
      %client.player.unHideNode("epauletsRank");

   default: //No? Okay, just hide the node.
      %client.player.HideNode("epauletsRank");
}

Wait, TS has a case or command? Huh, didn't know that

oh yay so thats how to use switches in ts

oh yay so thats how to use switches in ts
If you want to do it with a number then it's switch(%var) without the $, and you don't need the quotations for the cases.

Wait, TS has a case or command? Huh, didn't know that
Yeah, I didn't know this either until I saw it in a thread about a month ago, I thought it was very interesting. In fact, Greek2Me uses the "or" operator in his new Slayer code.

switch$ = String cases (you can use numbers too but they have to be in a string), ex:
Code: server.cs (8 lines)
switch$(%cake)
{
    case "cake" or "0":
        echo("cake is good");

    default:
        echo("oh noes!");
}


switch = number cases, ex:
Code: server.cs (8 lines)
switch(%cake)
{
    case 0 or 1:
        echo("we have a zero");

    default:
        echo("no no");
}

« Last Edit: November 25, 2015, 05:16:53 PM by Kyuande »

https://youtu.be/W2XvcI7UV0E
Well the video isn't ready yet.
In this video I uploaded the basic blockhead shooter with customization ability, but I have another problem, not shure if coding could figure it.The visor of the helmet makes everything look invisible.
Old topic:
http://forum.blockland.us/index.php?topic=283009.msg8489109#msg8489109