Enforcing Single Selection

Get help using Construct 2

Post » Fri Aug 02, 2013 7:30 am

Here's the situation: I have three spawn points, each with a boolean variable 'Selected' that is by default set to FALSE. I have events that allow the player to spawn an object at these spawn points when they are selected.

The problem is, a player may select multiple spawn points and spawn a single object that gets placed in all of the selected spawn points. I want to restrict the player to only being able to spawn one object at a single spawn point. In addition, I want the user to be able to switch the selected spawn point at any time before spawning an object. For example, if the player selects spawn point A, but then selects spawn point B, I want spawn point A to no longer be selected and any object spawned will be created at the currently selected spawn point (point B).

This is more or less an abstract question of how one might implement this, but if you want to see a .capx you can use the link below:

BoardGame.capx
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 02, 2013 7:48 am

Something like this?

.capx
B
20
S
6
G
4
Posts: 347
Reputation: 4,441

Post » Fri Aug 02, 2013 7:54 am

@cvp Yes, that's perfect!

I'm a little confused though. SpawnPoint.SpawnPointNumb has no entry, so how does this work?Excal2013-08-02 07:55:04
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 02, 2013 7:55 am

Sry what to you mean by no entry?

Do you mean initial value? i hardcoded that. If you click the different spawnpoints in the layout you can see the variable is set.cvp2013-08-02 07:56:27
B
20
S
6
G
4
Posts: 347
Reputation: 4,441

Post » Fri Aug 02, 2013 7:57 am

@cvp Oh :(

I guess I will have to dynamically set the spawnpoint values then.
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 02, 2013 8:00 am

That should be no problem. if you add spawnpoints on the fly just have a global variable named spawnpointCount. Then each time you add a spawnpoint set its spawnPointNumb to spawnpointCount+1 and also count up spawnpointCount --> spawnpointCount = spawnpointCount + 1
B
20
S
6
G
4
Posts: 347
Reputation: 4,441

Post » Fri Aug 02, 2013 8:02 am

There should be a built-in variable SpawnPoint.Count that you can use, so no need to create the global variable ;)
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Fri Aug 02, 2013 8:05 am

Maybe you can use one global variable "spawnPointSelected" (for example), instead of boolean for each spawn point.
So when the player selects a spawn point, set spawnPointSelected with its name (or id, or number). And to spawn an object, use this variable to choose the good spawn point.
if spawnPointSelected = A, spawn object to point A
if spawnPointSelected = B, spawn object to point B
...
So you have only one active spawn point.

I hope it's helpful.

Oops too late !PaulPoy2013-08-02 08:06:14
B
34
S
9
G
1
Posts: 46
Reputation: 4,610

Post » Fri Aug 02, 2013 8:07 am

@Excal .... ahh true

But... then again.. that only works if you do not destroy spawnpoints. otherwise you can get 2 spawnpoints with the same number.

e.g.

spawnpointCount = 0
create spawnpoint
gets number 1

spawnpointCount = 1
create spawnpoint
gets number 2

spawnpointCount = 2
create spawnpoint
gets number 3

spawnpointCount = 3
destroy spawnpoint 1
spawnpointCount = 2
create spawnpoint
gets number 3

You see what i mean... So if you destroy spawnpoints you have to keep track of the numbering yourself.



cvp2013-08-02 08:10:05
B
20
S
6
G
4
Posts: 347
Reputation: 4,441

Post » Fri Aug 02, 2013 8:11 am

edit:
For dynamic number of spawn points, I think you can use Pick by unique ID.
So no need to use a spanwpointcount variable. When the player selects spawn point, set global variable spawnpointselected to the spawn point uid.PaulPoy2013-08-02 10:26:08
B
34
S
9
G
1
Posts: 46
Reputation: 4,610

Next

Return to How do I....?

Who is online

Users browsing this forum: Cryttexx, LaurenceBedford, luckyrawatlucky, oddreal and 13 guests