Author Topic: Switches and cases  (Read 1315 times)

Is this the proper format for a switch based on the datablock of the brick being checked?
Code: [Select]
function fxDTSbrick::exceptionValueCheck(%brick)
{
%Datablock = %brick.getDatablock
switch$(%datablock)
{
case "bricknonTreasureChestData":
%result = "TreasureChest;
case "brickTreasureChestData":
%result = "TreasureChest;
case "brickTreasureChestOpenData":
%result = "TreasureChest;
case "brick1x1MugData":
%result = "Ceramics";
case "brick2x2fPlateData":
%result = "Ceramics";
case "brick1x2fKeyboardData":
%result = "Electronics";
case "brick1x2fKnifeNForkData":
%result = "Silver";
case "brick2x3x2Computer1Data":
%result = "Electronics";
case "brick2x3x2Computer2Data":
%result = "Electronics";
default:
%result = "NothingSpecial";
}
return %result
}

Also, is there a way to simplify it so, for instance, all cases with the same result can be grouped together?

Pretty close, the line
Code: [Select]
%Datablock = %brick.getDatablockShould be
Code: [Select]
%Datablock = %brick.getDataBlock();
Mind the capitalization of DataBlock in getDataBlock(), it will not work otherwise.

this should be this
return %result
return %result;

but yeah.

no, there isn't a way to do case "blah" || "asdf": to my knowledge. you'd need to use if and else if statements.

this should be this
return %result
return %result;

but yeah.

no, there isn't a way to do case "blah" || "asdf": to my knowledge. you'd need to use if and else if statements.
Oh, woops. That's the kind of thing I miss and crash my server seven times trying to figure out what went wrong.

no, there isn't a way to do case "blah" || "asdf": to my knowledge. you'd need to use if and else if statements.
I believe the syntax is literally the word "or". I read it on a garage games thread a while ago, never tried it myself though

I believe the syntax is literally the word "or". I read it on a garage games thread a while ago, never tried it myself though
I think it's ||.


One more question, can a switch have multiple variables, like
switch$(%color, %colorfx, %shapefx)?

Not for case statements
ah, got it

I believe the syntax is literally the word "or". I read it on a garage games thread a while ago, never tried it myself though
I'd like to know if this actually works.

I'd like to know if this actually works.
it does, tested it earlier.

function blegh(%dafuq)
{
switch$(%dafuq)
{
case "dafuq" or "something entirely different":
OBJECTION!();
default:
echo("herpy derpy derp");
}
}

will work just fine (as long as you don't include the bbcode or the exclamation point)
« Last Edit: August 11, 2012, 11:24:17 PM by wizzlemanizzle »

Sweet, but can someone answer my other question? I wanted to know if I can use a
switch$(%whatever, %whocares, %wtf)
In other words, can a switch have more than one local variable assigned to it?

What is the end result you'd like to see?


What is the end result you'd like to see?
I want to determine a brick's material based on it's Color, ColorFX, and ShapeFX.

I want to determine a brick's material based on it's Color, ColorFX, and ShapeFX.

if ( %color == 0 && %color_fx == 2 && %shape_fx == 1 )
{
    code block
}

if ( %color == 18 && %color_fx == 6 && %shape_fx == 0 )
{
    code block
}