Spawn object depending on instance variable

Get help using Construct 2

Post » Fri Feb 21, 2014 11:57 am

Hi again!

A little problem is bugging me!

I have object with all unique instance variable. For this example i will take:
Object 1. : Instance Variable: [number] = 1
Object 2. : Instance Variable: [number] = 2
Object 3. : Instance Variable: [number] = 3

Now i want to:
IF Instance Variable [number] = 1 SPAWN Object : Spawn1
IF Instance Variable [number] = 2 SPAWN Object : Spawn2
IF Instance Variable [number] = 3 SPAWN Object : Spawn3

How i started:
For each Object ( family for Object 1, Object 2 and Object 3 )
???????????????????????

Object Spawn ??????????????

I am thinking in a way of calling all instance variables the name of the object i want to spawn.
But as far as i know there is no way to spawn a object with the name of a instance variable am i right?
Though that is what i try to make.

I will try with another example:
Object: Apple , instance variable: fruitName = Apple
Object: Pear , instance variable: fruitName = Pear
Family: Fruit ( including Apple, Pear )

EVENT:
For each Fruit

ACTION:
Spawn {{OBJECT: Fruit.fruitName}}
But that isn't possible..

I hope i made myself clear once again.

Thanks in advance!
B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Fri Feb 21, 2014 12:06 pm

All in the same event, no loop:

event:
compare 2 variables: object1.variable equal 1
compare 2 variables: object2.variable equal 1
compare 2 variables: object3.variable equal 1
action:
spawn
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri Feb 21, 2014 12:11 pm

Hi Lennaert,

Thanks for your reply. Yet i do not understand what you mean..

Can you take the Fruit example for this one? Thanks ;-)!
B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Fri Feb 21, 2014 12:23 pm

I thought you wanted to compare three fruits to select one item to spawn ... somehow lol

Anyway, you will need to create some sort of list which assosciates a variable with an object.

fruits.fruitname
event
compare 2 variables: fruits.fruitname = apple
action
spawn apple

event:
compare 2 variables: fruits.fruitname = pear
action: spawn pear


event:
compare 2 variables: fruits.fruitname = banana
action: spawn spawn banana
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests