How do I this condition?

0 favourites
  • 4 posts
From the Asset Store
Publish and Subscribe to events in event sheets and from the scripting interface
  • Hello, can someone please help me with this?

    Example:

    I have three instances of the same sprite object on screen, this object has a private variable called "var"

    Object 1 var = 10

    Object 2 var = 5

    Object 3 var = 7

    I need to know if there is an on-screen object with var = 4, if it does not exist, then I have to create a sprite object with var = 4

    If I make this condition in C2:

    If (sprite.var! = 4)

    This collects the 3 objects

    If I do this:

    If (sprite.var == 4)

    This does not collect any object and the condition will be false, I will not be able to create the object with var = 4

    So how should I do the condition ?.

  • Object > Compare instance variable > var .. Equal to .. 4 <--- picks all instances of Object with var= 4

    ________(no actions)

    Else <--- when that previous picklist is empty, parent condition is untrue, so the else runs

    _____Create Object somewhere

    _____set var to 4

  • Object > Compare instance variable > var .. Equal to .. 4 <--- picks all instances of Object with var= 4

    ________(no actions)

    Else <--- when that previous picklist is empty, parent condition is untrue, so the else runs

    _____Create Object somewhere

    _____set var to 4

    That is valid although it is a strange condition for me but it serves to avoid the use of "for each".

    I thought of using for each to check the values one by one and if there is any value 4 then put a local variable to 0 to avoid the creation of the object.

    Thanks.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, this works when there are just no instances of 'object'. Your rules apply also in that situation. But you can not compare non existing objects. You would not catch that exception.

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