Pick A Random Family [C2] [SOLVED]

Just started using Construct 2? Post your questions here

Post » Tue Jul 11, 2017 6:28 pm

AmpedRobot wrote:
plinkie wrote:Just realized I could do a random roller for several different instance variables.


Yep looks like you've got it now.
B
47
S
17
G
82
Posts: 2,232
Reputation: 48,611

Post » Wed Jul 19, 2017 5:48 pm

Would there be a way of grouping many different sprites on screen for comparison purposes?

I just discovered the "pick all instances" and "is on screen".

So how to use that for say 5 different ship/sprite types on screen and then pick a random instance out of all that?

Is that possible?
B
39
S
20
G
18
Posts: 264
Reputation: 12,983

Post » Wed Jul 19, 2017 6:08 pm

Assuming they are still in a family, pick random family instance, family is on screen.
B
47
S
17
G
82
Posts: 2,232
Reputation: 48,611


Post » Wed Jul 19, 2017 6:53 pm

Dude, read your PM's from dayssssssssss ago. Example in there.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jul 21, 2017 5:13 pm

@99Instances2Go

Thanks, man. You obviously know what you're doin, but I've already implemented my ROJO modified code for this. I will process your solution at some point because it seems to be a long time programmer's solution.

@99Instances2Go

@plinkie

Still tryin to do the shooting though with multiple image points. Not hard to setup with instance variables for each ship type, but gets complicated trying to control the rate of fire of many different ships.

The simplest solution I had before, which worked very well, was:

Every x seconds
Pick a random instance Sprite -> Sprite - spawn bullet

Replacing Sprite with a Family of say 20 sprites did not work (think they all fire simultaneously).

Is System ->Pick Random Instance equivalent to Pick a Random Family Instance? Where is the family random instance picking or is it the same?

Maybe I'm just not seeing that option anywhere.

Found a Scirra tutorial on picking family instances and it will take hours to test absorb, but I do not believe I want to mess with UIDs or anything that fancy.
Last edited by AmpedRobot on Fri Jul 21, 2017 5:46 pm, edited 1 time in total.
B
39
S
20
G
18
Posts: 264
Reputation: 12,983

Post » Fri Jul 21, 2017 5:43 pm

Whatever he sent you in PM can't be too difficult, it's quite simple to set up variables like this. The Family becomes an object, instead of picking a single object you are picking from all the objects in the family. Pick random instance > sprite, or you use Pick random instance > family. If you're going to make a game with some complexity you should get your head around the debug mode and looking at objects to see what their current states and variables are, then you'll have an idea of what has changed and what is set as you expected.

As an example, you have ships. Ship A, Ship B and Ship C are all in a family called Ships.

Pick a random instance Ship A. That will choose one object, a randomly selected Ship A.

Pick a random instance Ships. That will choose one object, a randomly selected Ship A, Ship B or Ship C.

You select a Family as though it is just another object but really it represents all the objects within it.
They are useful for when you want to sometimes group events.
For example in this game, if you wanted to say :

Bullet A can damage Ship A
Bullet B can damage Ship A
Bullet A can damage Ship B
Bullet B can damage Ship B

You put the bullets into a bullets Family and the ships into a ships Family and then it becomes one event applied to all :

Bullets (family) can damage Ships (family)
B
47
S
17
G
82
Posts: 2,232
Reputation: 48,611

Post » Fri Jul 21, 2017 6:32 pm

Scratch this.

It does actually work!

Just made a simple capx from scratch, so no idea what happened ha ha.

Thanks for all the replies.

This concludes tonight's presentation.
B
39
S
20
G
18
Posts: 264
Reputation: 12,983

Previous

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests