Spawn object into empty marker?

Get help using Construct 2

Post » Thu Dec 17, 2015 8:03 am

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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 17, 2015 9:21 am

Solomon wrote: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...
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
67
S
22
G
90
Posts: 1,125
Reputation: 60,036

Post » Thu Dec 17, 2015 11:29 am

"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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 17, 2015 1:49 pm

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.
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
67
S
22
G
90
Posts: 1,125
Reputation: 60,036

Post » Thu Dec 17, 2015 2:49 pm

chadorireborn wrote: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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 17, 2015 3:31 pm

Solomon wrote: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...
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Thu Dec 17, 2015 3:58 pm

korbaach wrote: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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Post » Thu Dec 17, 2015 4:03 pm

Bullshit sorry.
That creates only random objects
Last edited by Asmodean on Thu Dec 17, 2015 4:12 pm, edited 1 time in total.
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Thu Dec 17, 2015 4:12 pm

Image
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
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Thu Dec 17, 2015 4:44 pm

korbaach wrote:Image
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.
Brick by brick, stone by stone.
B
56
S
25
G
18
Posts: 273
Reputation: 13,363

Next

Return to How do I....?

Who is online

Users browsing this forum: Bootfit and 24 guests