"OR" or workaround

0 favourites
  • 4 posts
  • I'll start with explanation.

    I have a 'Player sprite', few 'Detector sprites' and 'Text object'.

    There are two global variables "Language", "Player_Action"

    Each 'detector sprites' have two variables "ActionENG" and "ActionPL" - for different language setup.

    ie. for one sprite i have - > ActionENG = window, ActionPL = okno

    It basicaly sets the text object to display the name of currently overlapped instance of 'detector sprite' by 'player sprite', depending of global variable "Language"

    If Languege = ENG it will show text from "ActionENG" and opposite

    if Language = PL - display text from "ActionPL" variable from sprite.

    Main event

    +Every thick -> set text to "Player_Action"
    +If player overlapps detector sprite
    ++If "Language" = ENG -> set "Player_Action" to detector sprite "ActionENG"
    ++If "Language" = PL -> set "Player_Action" to detector sprite "ActionPL"

    My question is: how can i compare actions if player is overlapping an object with current language selected?

    The easy way would be:

    If "Player_Action" = window -> do some stuff

    If "Player_Action" = okno -> do same stuff

    I don't want to go that way cause I have many object with many events and subevents. Choosing that method will make me do everything twice.

    The best solution would be to compare values in one event, something like:

    If "Player_Action" = 'window' or 'okno' - > do some stuff

    but there is no "OR" yet I'm looking for a workaround but after a day i have nothing :/

    Any suggestions, please? :)

  • I'd use a local variable:

    local var: orvar=0

    If "Player_Action" = window -> set orvar to 1

    If "Player_Action" = okno -> set orvar to 1

    if orvar = 1 -> do some stuff

    I you use a global variable instead of a local then you need to reset orvar to 0 before that block of events.

  • One way is with a local variable:

    [Local number 'temp' = 0]

    + If condition 1

    -> Set temp to 1

    + If condition 2

    -> Set temp to 1

    + If condition 3

    -> Set temp to 1

    + If temp = 1

    -> ... a long list of actions ...

    It's not ideal, but it does at least save you duplicating the whole list of actions. It also loses the picked objects. If that's a pain, you can use a temp instance variable instead (but calling it 'pick' to make it a bit clearer):

    + Every tick

    -> Set Sprite 'pick' to 0

    + Sprite condition 1

    -> Set Sprite 'pick' to 1

    + Sprite condition 2

    -> Set Sprite 'pick' to 1

    + Sprite condition 3

    -> Set Sprite 'pick' to 1

    + Sprite 'pick' = 1

    -> ... a long list of actions on Sprite ...

    This way saves you duplicating all the actions again, and remembers the picked objects.

    (Edit: ninja'd)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Works perfectly.

    Thank to both of you.

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