ID:161316
 
Jus' because I haven't used them in so long, and experimenting is a luxury i have no time for, in a text string how do I do if's in the square brackets?

world << "1+1=[if(1+1=2)WHAT??]"
obviously isnt how, example of what i need xD
DarkBelthazor wrote:
Jus' because I haven't used them in so long, and experimenting is a luxury i have no time for, in a text string how do I do if's in the square brackets?

world << "1+1=[if(1+1=2)WHAT??]"
obviously isnt how, example of what i need xD

world << "1+1=[(1+1==2 ? 2 : "Sanity Check Fails")]"


Try that. Look up the ? operator in DM reference.

Essentially, you can shortcut an if statement into

BooleanCheck ? True : False

Generally you'll want to enclose that in parenthesis as I did above to avoid conflicting and confusing order of operations stuff.

Also, your check of "1+1=2" will not work, as the = sign is the assignment operator. Essentially you're trying to assign the value of 2 to the 1 on the other side of the = sign . . . and DM will yell at you :) To compare values, use a double = sign (1+1==2 should always return 1, or TRUE).
In response to CriticalBotch
lol, tried the double equals and it said bad expression =P but your example works, cheers!, how do you do else ifs then? :S lke, ummmm, if 1+1=2 do this, else if 1+1=3 do this, else, jus do this xD
In response to DarkBelthazor
DarkBelthazor wrote:
lol, tried the double equals and it said bad expression =P but your example works, cheers!, how do you do else ifs then? :S lke, ummmm, if 1+1=2 do this, else if 1+1=3 do this, else, jus do this xD

In a similar manner:

world<<"This should say 1: [(1+0==3 ? 3 : (1+0==2 ? 2 : (1+0==1 ? 1 : "ERROR") ) )]"


Remember that
boolean ? TRUE : FALSE

is simply a short hand for the if-then structure.
1 ? TRUE : FALSE

is the same as
if(1)
TRUE
else
FALSE


and as such you can replace the TRUE or FALSE with additional statements, including further if statements.
In response to CriticalBotch
thanks heh =P never bothered learning bout ? operators etc, never needed to, XD