2 instances, same object type, 2 different vectors

Get help using Construct 2

Post » Thu Dec 17, 2015 9:31 pm

I am trying to solve an issue, for 3 hours straight and seem to be getting nowhere.
Im not sure if this can be achieved thus I decided to ask here all you gurus.

I have 2 instances of the same object type, lets say 2 balls.
Both are spawned randomly, at 2 different locations, one on left half of the screen the other on the right half.
So far so good.

Now comes the tricky part.

Is it possible, in order to save memory to spawn the ball on the left side of the screen to always move right, and the ball on the right side on the screen to always move left, all using 2 instances of same object type, no behaviours and done in events?

Ive been trying to find some sort of variable that could be manipulated from withing the event sheets, that could be manipulated seperately for each instance that has been created.
Ive tried families, but manipulating family instances from the event sheets cant focus on one instance, rather changes all the values for all the instances when manipulated.

I worked some time ago in another program smillar to Construct2 (will not mention which one for obvious reasons), and what I did there is I managed to add each instance created to a list, and name each instance seperately as it was created. In that way I was able to call out by name each instance and get a hold of each instance seperately (the list wasnt long, it had 5 places and the instances that left the screen had been removed from that list).

Either this is very easy and Im getting tired and my mind isnt working anymore, or its hard and the only solution is to create another object type of that object which travels right, and give it another variable seperate from that instance that travels left.

In Construct 2 I find it tricky to get a "hold" of a "unique" instance to be able manipulate only it from directly from event sheet once it was loaded by events.
Last edited by Solomon on Thu Dec 17, 2015 9:50 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Thu Dec 17, 2015 9:50 pm

Either of the following would work. Either you just specify what way you want the object to do when you create it, or you can pick it by "pick nth instance" or "pick by uid" or something.

Code: Select all
Start of layout:
--- create: ball at (random(320),random(480))
--- ball: set angle to 0
--- create: ball at (random(320,640),random(480))
--- ball: set angle to 180

every tick:
--- ball: move forward 100*dt pixels


Code: Select all
Start of layout:
--- ball: destroy
--- create: ball at (random(320),random(480))
--- create: ball at (random(320,640),random(480))

system: pick 0 instance of ball
--- ball: set x to self.x+100*dt


system: pick 1 instance of ball
--- ball: set x to self.x-100*dt
B
91
S
31
G
102
Posts: 5,234
Reputation: 67,254

Post » Thu Dec 17, 2015 10:25 pm

@R0J0hound

Wow brilliant!
Regarding the uid, that is unique so its 1 per instance, how can one get the uid of an object when an object has been spawned inside a game for the nth time?

Once again thanks for the help!
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Thu Dec 17, 2015 10:44 pm

The uid is unique per object. You can find what a created object's uid is with the .uid expression of the object. The new object is picked for the rest of that event or until another create action.

Every 1 seconds
--- create: Sprite at (random(100),random(100))
--- text: set text to Sprite.uid
B
91
S
31
G
102
Posts: 5,234
Reputation: 67,254


Return to How do I....?

Who is online

Users browsing this forum: varr and 3 guests