0 Favourites

Spawn object depending on instance variable

  • 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!

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Hi Lennaert,

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

    Can you take the Fruit example for this one? Thanks !

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 14,518
DMT2005's avatar
DMT2005
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,380
rexrainbow's avatar
rexrainbow
Unread hot topic
123 14,877
Zebbi's avatar
Zebbi