"OR" Using the expression editor?

3absh3absh Member Posts: 601

I want to write this:
When attribute X = 1, or 2
but I need to write it using the expression editor not the "When ANY conditions are valid"
which of the expression editor function does this?

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited August 2016

    You could use any.

    When Any
    If x = 1
    If x = 2

    Or like this

    When All
    If x >= 1 and x <= 2

    Why does it need to be written in the expression editor/text box?

  • Two.ETwo.E Member Posts: 599

    (Game.Attribute==1)and(DOACTIONFOR1)or(Game.Attribute==2)and(DOACTIONFOR2)or(DOACTIONIFNONEAREMET)

    I use this every now and then. Not sure if its most practical solution though.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    If numeric expression: x-round(x/4) = 1

    . . . then x must be 1 or 2.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    Another way:

    If numeric expression: ceil(x/2) = 1

    . . . then x must be 1 or 2.

  • ArmellineArmelline Member, PRO Posts: 5,420

    Using Numeric Expression:

    (game.X==1)or(game.X==2) = 1

    The = 1 is the built in = and the 1 is in the right hand box. It does exactly the same as @KevinCross suggested, though. There's no advantage to this over his way.

  • BigDaveBigDave Member Posts: 2,239

    thats a lot of solutions

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @BigDave said:
    thats a lot of solutions

    There are probably an infinite amount of solutions to this (I think).

    Here's another :)

    If numeric expression: abs(floor(x*1.5)-2) = 1

    . . . then x must be 1 or 2.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    Here's another (somebody stop me !! :D )

    If numeric expression: abs(((x-1)*2)-1) = 1

    . . . then x must be 1 or 2.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited August 2016

    When numeric expression textFind("#1#2","#"..self.x,1) ≠ -1

  • ArmellineArmelline Member, PRO Posts: 5,420
    edited August 2016

    @tatiang Love it! Another (not as good) textFind option:

    max(textFind(self.X,"1",1),textFind(self.X,"2",2)) = 1

    (This breaks pretty easily though, if the conditions are too wide. Like, say, 11. That can be fixed by throwing two min(x) in there though.)

    max(textFind(min(self.X,3),"1",1),textFind(min(self.X,3),"2",2)) = 1

  • ArmellineArmelline Member, PRO Posts: 5,420

    Very similar to one @Socks already did, but different enough!

    round(sqrt(self.X)) = 1

  • SocksSocks London, UK.Member Posts: 12,822

    @Armelline said:
    Very similar to one @Socks already did, but different enough!

    round(sqrt(self.X)) = 1

    I see your square root and raise you a sine function:

    ceil(sin(min(( self.X *90)-1,181))) = 1

  • ArmellineArmelline Member, PRO Posts: 5,420

    @Socks I don't think anyone is going to beat a sin() one. One more anyway, though! We've not had any where the result has to be 2 yet.

    ceil((self.X*5)/10+1) = 2

  • 3absh3absh Member Posts: 601

    Wow, I'm overwhelmed.
    Thanks guys!!

  • 3absh3absh Member Posts: 601

    OMG I just noticed that what I actually needed was
    0 OR 1
    not
    1 OR 2
    Ultimate FAIL on my behalf.

  • ArmellineArmelline Member, PRO Posts: 5,420

    That makes it much easier. If X can only be positive numbers, just say x > 1.

    If X can be negative, it gets a little more complicated but it still very much doable.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @Armelline said:
    That makes it much easier. If X can only be positive numbers, just say x > 1.

    Then 3 (and 7,928 and 4.32 . . etc) would pass the condition ? But 0 and 1 would fail ? Maybe I misunderstand what you are saying, but either way this is highly controversial maths ;)

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    if abs((X*2)-1) =1

    Only 0 and 1 will pass this condition.

    Or (as Armelline says) if you are only using positive integers then you can simply check for x < 2.

  • ArmellineArmelline Member, PRO Posts: 5,420

    @Socks said:

    @Armelline said:
    That makes it much easier. If X can only be positive numbers, just say x > 1.

    Then 3 (and 7,928 and 4.32 . . etc) would pass the condition ? But 0 and 1 would fail ? Maybe I misunderstand what you are saying, but either way this is highly controversial maths ;)

    oop, I mean < 2. No idea why I said > 1 :D I must have transposed his question to NOT 0 or 1...

Sign In or Register to comment.