How do I deal with double toggle selections

Get help using Construct 2

Post » Thu May 26, 2016 8:22 pm

I'll try and explain as clearly as I can, I've been running around in circles with this.

I need to select 1 enemy ship to fire upon.

Now that ship has to be either
A) closest to the player
or
B) selected by the player selecting him.

In all cases it needs to be visible.
My issue comes when selecting a ship that is further away from the closest one that was selected in the code by clicking on him, I can't get it to become unselected, even though I'm making the bool set to false. I need to fix the closest to player statement somehow.

I'm using 2 booleans on the enemy ship, one is 'selected' and the other 'closest'.
I'm using the 'closest' bool to select the ship to fire upon.

Hope that makes sense!
thanks in advance

Here's what I have but it's not working.
Image
B
22
S
12
G
19
Posts: 54
Reputation: 11,554

Post » Thu May 26, 2016 9:19 pm

Is enemyshield in a container with Enemy ?

If not, Enemy is unreferenced (not picked) in event 425. So all Enemy get marked as picked.
Same for PlayerSelect, if there are more of them. In 428.

If they are in a container, it could work. Difficult to debug with a screenshot.

I would use containers, for sure. Then (i think, from my head, so untested). Combine in one event.

Conditions:
Enemy = visible ?
Pick nearest enemy to player position
Actions
Set enemy instance variable 'CanBePicked' to true

To pick with the mouse

Condtions
EnemyShield clicked by mouse (must be in a container with the enemy)
Enemy 'CanBePicked' is true
Actions
Enemy set picked

And ....

Condtion
Enemy is picked
Action
set playerselect (if there is only one) to postion of enemy (or shield, i have no idea where you want it)
set playerselect visible
Else
set playerselect invisible
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu May 26, 2016 9:25 pm

I think 426 is setting picked to false on the newly select enemy instead of the previous one? The first 3 events probably need some kind of rework. I also don't think 425 and 426 should be checking at exactly the same time, from the logic anyway.
B
47
S
17
G
81
Posts: 2,227
Reputation: 48,101

Post » Thu May 26, 2016 10:31 pm

I reworked a bit of the code but I fixed it with a 'OR' statement for my weapons.
Code: Select all
Enemy is Picked
or
Enemy is closest

This way if there's a picked enemy it doesn't take into account one that is closest, and if there is no picked enemy it uses the closest one. :)
B
22
S
12
G
19
Posts: 54
Reputation: 11,554


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests