How do I spawn specific object from family

Get help using Construct 2

Post » Wed Sep 10, 2014 3:41 pm

Hi,

I'm working on a tactical game where you can choose several different characters for a team. I don't want to create a block of code for each character for every action, for instance, selecting the character with the mouse to put in your team.

I tried to putting all of the characters into a family and giving them all a "name" variable. So I can click on a character from the family, then pick it based on the comparison of the name, and then spawn a new one over in the team queue.

The pick seems to work correctly if I use "set text" or something to view the result, but when I spawn "characters", it just grabs a random one out of the group still. I looked through the forums and found someone said to "pick all" first. This didn't work. It didn't sound like the same problem, but I thought I would try it.

Does anyone have any suggestions? Thank you for your time!
B
6
G
1
Posts: 9
Reputation: 931

Post » Wed Sep 10, 2014 3:46 pm

I think the only vanilla C2 solution is to spawn the specific object directly (not through the family), however the nickname plugin can spawn an object by name
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Wed Sep 10, 2014 4:33 pm

Message: hippie can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I do not know if this could serve but read this section of the manual
https:// www.scirra.com /manual/ 130/ common- features
remove space
B
8
S
2
Posts: 34
Reputation: 570

Post » Wed Sep 10, 2014 5:21 pm

Thanks for the help, I'll check into these suggestions later. If I can't find a good solution I may make a request to scirra to let us spawn objects by expression. I know I'm not the only person that would benefit from this.

Thanks again!
B
6
G
1
Posts: 9
Reputation: 931

Post » Thu Sep 11, 2014 12:28 am

FootSoldier wrote:Hi,

I'm working on a tactical game where you can choose several different characters for a team. I don't want to create a block of code for each character for every action, for instance, selecting the character with the mouse to put in your team.

I tried to putting all of the characters into a family and giving them all a "name" variable. So I can click on a character from the family, then pick it based on the comparison of the name, and then spawn a new one over in the team queue.

The pick seems to work correctly if I use "set text" or something to view the result, but when I spawn "characters", it just grabs a random one out of the group still. I looked through the forums and found someone said to "pick all" first. This didn't work. It didn't sound like the same problem, but I thought I would try it.

Does anyone have any suggestions? Thank you for your time!


Use Animation Name, example:

On click on character selection x
if character selection x animation name = "fluffy"

character creator set animation.name (which will be the sprite fluffy) and that's how you spawn and keep the characters name.

or doesn't use direct value at all:

make a persistent object x to store the animation.name

on click on button x, get animation.name > sprite create and/or switch to persistentobject.x (its the animation value)

Does this makes sense to you?
Image
B
30
S
5
G
1
Posts: 125
Reputation: 3,231

Post » Fri Sep 12, 2014 1:56 pm

Thanks for the suggestion lwgames, I ended up using the nickname plugin which let's you create an instance of an object using an expression, so at selection I saved Characters.name to objectClicked then used Nickname to "create objectClicked". Works very well and reduces dupicate code. Thanks a lot @aphrodite for suggesting the plugin!
B
6
G
1
Posts: 9
Reputation: 931


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests