Simplify variable comparison

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello!

    I need to check if my object's variable contain one of the possible values.

    I know that I can use something like this:

    + System: Every tick
    + MapInOutCheck: MapInOutCheck = "upleft"
    ----+ MapInOutCheck: TypeChecked = "ULDR"
    ----+ OR MapInOutCheck: TypeChecked = "LDR"
    ----+ OR MapInOutCheck: TypeChecked = "UDR"
    ----+ OR MapInOutCheck: TypeChecked = "ULR"
    ----+ OR MapInOutCheck: TypeChecked = "DR"
    ----+ OR MapInOutCheck: TypeChecked = "UR"
    ----+ OR MapInOutCheck: TypeChecked = "LR"
    ----+ OR MapInOutCheck: TypeChecked = "R"
    ----+ OR MapInOutCheck: TypeChecked = ""
    -----> MapInOutCheck: Set Entrance to True
    

    But I was asking myself if there is a better and simple way to do it, like this for example:

    + System: Every tick
    + MapInOutCheck: MapInOutCheck = "upleft"
    + MapInOutCheck: TypeChecked = "ULDR"|"LDR"|"UDR"|"ULR"|"DR"|"UR"|"LR"|"R"|""
    -> MapInOutCheck: Set Entrance to True
    

    This isn't working, even if I read that "|" means "or"

    So maybe you guys have a solution for me?

  • This is how you’d use that or operator in an expression:

     System: pick MapInOutCheck by comparison: (MapInOutCheck.TypeChecked = "ULDR" | MapInOutCheck.TypeChecked = "LDR" | MapInOutCheck.TypeChecked = "UDR" | MapInOutCheck.TypeChecked = "ULR" | MapInOutCheck.TypeChecked = "DR" | MapInOutCheck.TypeChecked = "UR" | MapInOutCheck.TypeChecked = "LR" | MapInOutCheck.TypeChecked = "R" | MapInOutCheck.TypeChecked = "" )
    = 1

    But for something like that I’d utilize the find expression. The list of values are comma separated with commas before and after, and we surround the variable value by commas and find it in the list.

    System: pick MapInOutCheck by comparison: find(“,ULDR,LDR,UDR,ULR,DR,UR,LR,R,,”, “,”& MapInOutCheck.TypeChecked&”,”)>-1
  • Your first solution is working fine.

    The second one with the find expression looks great and more elegant but it seems there is an extra " somewhere…

  • Probably should work if you retype the quotes. By default my phone uses different quotes than construct uses.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes that's it!

    Here is the good version:

    + System: Every tick
    + MapInOutCheck: MapInOutCheck = "upleft"
    + System: Pick MapInOutCheck where find(",ULDR,LDR,UDR,ULR,DR,UR,LR,R,,", ","& MapInOutCheck.TypeChecked&",") > -1
    -> MapInOutCheck: Set Entrance to True
    

    Thanks for your help!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)