"OR" or workaround

Get help using Construct 2

Post » Mon Sep 12, 2011 8:39 pm

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
[code]+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"[/code]

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:
[code]If "Player_Action" = 'window' or 'okno' - > do some stuff[/code]
but there is no "OR" yet I'm looking for a workaround but after a day i have nothing :/

Any suggestions, please? :)
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Mon Sep 12, 2011 9:29 pm

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.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Sep 12, 2011 9:39 pm

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)Ashley2011-09-12 21:40:32
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Mon Sep 12, 2011 10:38 pm

Works perfectly.
Thank to both of you.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170


Return to How do I....?

Who is online

Users browsing this forum: flemmig, Jarnopa, nimos100, semaso, Skebab and 10 guests