Spawn object into empty marker?

0 favourites
  • 14 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I have a marker and I would like to load into it a random object.

    Now the reason for this, is that I would not need to set events for each object that I load into the marker, instead set the events for the marker and the objects will load into it and retain its events.

    Basically the idea behind this is to have a random picking system which I have done so, and when a number is hit it picks out an object/sprite.

    Then, there is an event where I create the object, but I would like to be able instead of going through all the possibilities, to substititue create "object" with a variable that has been randomly picked at the beginning, if that makes sense.

    The only thing Im not sure of is how to substitute the "object" in "create object" event with a variable name that had been picked out earlier.

    All of the objects have their own animations, so using the strategy of having different sprites on different animations/frames and changing the frame numbers to get a different object loaded will not do.

    As always, thanks for the help.

  • I have a marker and I would like to load into it a random object.

    Now the reason for this, is that I would not need to set events for each object that I load into the marker, instead set the events for the marker and the objects will load into it and retain its events.

    Basically the idea behind this is to have a random picking system which I have done so, and when a number is hit it picks out an object/sprite.

    Then, there is an event where I create the object, but I would like to be able instead of going through all the possibilities, to substititue create "object" with a variable that has been randomly picked at the beginning, if that makes sense.

    The only thing Im not sure of is how to substitute the "object" in "create object" event with a variable name that had been picked out earlier.

    All of the objects have their own animations, so using the strategy of having different sprites on different animations/frames and changing the frame numbers to get a different object loaded will not do.

    As always, thanks for the help.

    Just to be sure, you have a random picking system that generates a random value that is set in the global variable. And you want to create an object(sprite) that has the name like in the global variable?

    If that is the case you can try this:

    "First Make sure the Global Variable Values are text and returns the Sprite Names when you randomize it."

    1) Make a Family and add all the sprites that you want to create.

    2) Add an Instance Variable in the Family called "Signature" (or anything you want) returning a Text value.

    3) In the Project Bar , set the Instance Variable "Signature" of each sprite the same as their name.

    4) Make this event :

    Condition: Pick by comparison.... Global Variable = Family.Signature

    Action: Create Object : Family at (X,Y)

    ----------------------------------------That is one thing or you can try using Function Plugin..-------------------------------------------

    If Global Variable = "SpriteName"

    --> CallFunction: "Create_SpriteName"

    ----------next event-----------

    On Function: "Create_SpriteName"

    --> Create Object Sprite Name at (X,Y)

    Do that for each SpriteName...

  • [quote:2udrl499]

    "First Make sure the Global Variable Values are text and returns the Sprite Names when you randomize it."

    1) Make a Family and add all the sprites that you want to create.

    2) Add an Instance Variable in the Family called "Signature" (or anything you want) returning a Text value.

    3) In the Project Bar , set the Instance Variable "Signature" of each sprite the same as their name.

    4) Make this event :

    Condition: Pick by comparison.... Global Variable = Family.Signature

    Action: Create Object : Family at (X,Y)

    Lets say I have: apple|orange|banana in my Fruit_family.

    The sprites are called apple, orange and banana respectively.

    Also I created a text variable: Random_Pick=""

    At the beginning there is a draw = pick either: apple, orange or banana.

    All is good, that all works I get the desired output when using output value to text.

    At this moment when I draw orange I get Random_Pick="orange"

    Now I would like for the Fruit_family to spawn the orange that I the system has randomly picked at the beginning at a certain location.

    I did as you suggested, added "Signature" Instance Variable to the Fruit_family, and named each of the objects as their sprites:

    apple=apple, orange=orange, banana=banana

    Then I added the compare 2 values, and compared: Random_Pick=Fruit_family.Signature.

    Then create object Fruit_family on specified layer and location.

    From what I understand, the system is now looking if the Random picked fruit is present in the family signature and if it is, it is spawning a random object from that family, and not the exact fruit that was picked at random at the beginning.

    So I am getting random spawns every time, so when the pick is apple I get a random object spawn instead of the spawning apple.

    Its a shame that there is no further optional branching after selecting the create object Family ---> pick specific object in that family to create.

    Will try the other option regarding caling the function in a couple of hours.

  • I'm sorry that it did not work, I looked up and tested it and it really did not work. As far as I know (now) you have to do this manually, there is no literal option for this but you can only make it easier by using the function plugin, arrays or commonly use variables.

  • I'm sorry that it did not work, I looked up and tested it and it really did not work. As far as I know (now) you have to do this manually, there is no literal option for this but you can only make it easier by using the function plugin, arrays or commonly use variables.

    Hey no problem, at least we both learned something which is always good.

    I really do hope there is another way to solve this faster instead of manually entering each event.

    Still hoping someone can help me on this, if not well in the end Ill just use the call functions as you mentioned.

    One thing that could work if it was possible is adding an item to a family in events, and then checking if that item is in the family by comparing the family variable instance. Need to look into it, not sure if its possible to add an item to a family with events only.

  • Lets say I have: apple|orange|banana in my Fruit_family.

    The sprites are called apple, orange and banana respectively.

    Also I created a text variable: Random_Pick=""

    At the beginning there is a draw = pick either: apple, orange or banana.

    All is good, that all works I get the desired output when using output value to text.

    At this moment when I draw orange I get Random_Pick="orange"

    Now I would like for the Fruit_family to spawn the orange that I the system has randomly picked at the beginning at a certain location.

    I did as you suggested, added "Signature" Instance Variable to the Fruit_family, and named each of the objects as their sprites:

    apple=apple, orange=orange, banana=banana

    if you use while loop and "Random_Pick"?"Signature"...Destroy ?

    like in this capx WhileDestroy.capx

    just spawn families and check "Signature2...

  • if you use while loop and "Random_Pick"?"Signature"...Destroy ?

    like in this capx WhileDestroy.capx

    just spawn families and check "Signature2...

    Yes but you are setting the animation frame to a different frame to load a sprite. I cannot do that because I have different sprites with different animations that I want to load.

    I need to reference the created object by text inside a global variable, so that the text chosen will transfer itself to the object as both will have the same name.

  • Bullshit sorry.

    That creates only random objects

  • I mean something like this..

    so when you create sprite from family c2 take a random sprite..if is random sprite =Random pick..Stop

    else destroy and create new sprite..until you find Random pick

  • I mean something like this..

    so when you create sprite from family c2 take a random sprite..if is random sprite =Random pick..Stop

    else destroy and create new sprite..until you find Random pick

    The Signature is a Family instance from what I see.

    If I understand correctly...

    Well if the family has 3 objects, the apple orange and banana, it doesnt matter which will be randomly chosen at the beginning because the signature will always = whatever has been randomly picked, as I will need to input in the signature: apple, banana, orange.

    I want to create an apple if the apple is randomly chosen, from a family where all 3 - orange banana and apple are inside the family, and not do it manually in case I end up with 50 different objects.

    So I am looking for something simillar to create by text name "". So create "text global variable" object or something equivalent would be spot on.

  • I want to create an apple if the apple is randomly chosen, from a family where all 3 - orange banana and apple are inside the family.

    I think you can't..

    you cant write... create family member with instance variable "apple"

    but if I'm right this is going to do just that...

    random_Pick="apple"

    if c2 coose apple fom family..stop loop..everithig is ok..

    else keep trying(create&destroy) until you find apple..then stop

    Of course this does not make sense with "Random_Pick" variable,you dont need two times random pick..

    (variable and family (already picking random))..but if you have variable "Specific_Pick"..

    and set variable to specific fruit.. Specific_Pick="apple"..then you'll get apple

    have you even tried this?

    ..maybe I'm wrong

  • you cant write... create family member with instance variable "apple"

    I want to create an instance variable "apple" from the family at random pick by setting up a variable text which will control and be linked to the names of the different sprites in the scene, more or less.

    Well the problem is that the family variable instances cannot be directly called upon with an event in order to spawn that particular familly member, from what I have been trying to do and what the others have suggested. There is no way to connect the name of a particular sprite to a family instance variable from what I see. Giving a family member a family instance name the same as its sprite name does not work.

    The way you have done it, it is going to work is if there are only apples in the family.

    The family is not only apples, but its all the fruits. So apples oranges and bananas.

    So if the system is going to check wether there is a fruit in the family instance variable per family object, it will find each kind of fruit to be there.

    Besides I have other sprites of the same family in the scene, and in the loop the family is destroyed and that is why all the other family members in the scene will get destroyed too, which is something I dont want.

  • If you want to create an object by name this plugin will help:

    Personally though i'd either just add a event per type to create it or put them all into animations.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Yep, I ended up creating seperate events for all. Im trying to cutback on extra plugins and not use behaviours which all comes down to more control.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)