The Daily Click ::. Forums ::. Klik Coding Help ::. Pick object at random
 

Post Reply  Post Oekaki 
 

Posted By Message

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 15:47:22 -

Hi guys
I have a bunch of objects grouped together, and I want to randomly pick exactly 5 of them and perform some other actions.
I wanted to use the "pick at random" event, but it mostly repeats the same selection more than one, usually leaving me with 2-3 picked objects. I tried adding extra conditions to that event, to prevent it from repeating itself, but no luck there.

So what can I do to pick exactly 5 different objects?

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
11th October, 2011 at 15:55:20 -

http://www.mediafire.com/?6917kfpo7s2kndl

Small example I whipped up. Every time you hit the space bar it will pick 5 different ones each time.

This way it has to cycle through all possible choices. When you want to reset the cycle, all you have to do is set the flag to 0 again.

The Pick at Random event gets a lot of hate around the community, but it's a powerful event if used correctly.

Edited by an Administrator

 
Craps, I'm an old man!

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 16:28:14 -

Thanks for the quick response!
Sadly this doesn't seem to work for different objects under a group. I did exactly the same with a group and it just selected all the objects.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
11th October, 2011 at 16:41:33 -

let me play with it

Done

http://www.mediafire.com/?381epliaok08xyg

Seems to work fine with groups for me?

Edited by an Administrator

 
Craps, I'm an old man!

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
11th October, 2011 at 16:46:21 -

What sort of group do you mean? A qualifiers?

 
n/a

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 16:54:51 -

Yeah, qualifiers, sorry if I was unclear.

Thanks for the file Shab, but it seems you did something different from what I meant. You definied a qualifier for the two green objects, but there are still just two of them, and then when I try to run it, first time I press Space it turns all the Active 3 to red. Afterwards it seems to work ok for the remaining objects, but they're all Active 1 and not really a group of different objects.

What I did with your example originally was use "Clone object" and made like 15 different objects that look the same, changed everything to be under a qualifier, and when I ran it, it just turns all of them red.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
11th October, 2011 at 17:44:24 -

http://www.mediafire.com/?f9fe8v7opokbp70

25 different, independent objects...There's got to be something wrong.

 
Craps, I'm an old man!

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 18:20:49 -

Are you saying it works for you? Because it still turns all the objects red on my machine.
I wonder if it's some bug that was addressed by Clickteam...I haven't used MMF2 in a while, I'll try updating my copy and see if that helps.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 18:48:24 -

Yup, works like a charm now. Let that be a lesson to me.
Thanks for all the help and effort!

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Knudde (Shab)

Administrator
Crazy?

Registered
  31/01/2003
Points
  5125

Has Donated, Thank You!Clickzine StaffKlikCast StarVIP MemberGhostbuster!Dos Rules!I donated an open source project
11th October, 2011 at 19:46:34 -

Not a problem at all.

What are you using for?

 
Craps, I'm an old man!

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
11th October, 2011 at 19:53:28 -

I'm making a boss fight that at some point in the pattern different areas of the screen explode, but those are different looking objects that are blown up that I grouped together.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
15th October, 2011 at 19:44:56 -

It appears the update also broke something else I did, unrelated to the random 5 issue, but I thought it makes sense to continue the story here:
I have a few actives (the same object) walking from from side to side back and forth. I wanted to emulate gravity so I put a detector on the floor, and whenever one of the actives isn't overlapping it, it needs to change to animation sequence "falling" and increase its Y coordinate.
It worked fine before the update, and now it doesn't if there's more than one copy of the object.

I figured that the logic behind MMF2's events is that you condition, and then it creates a "list" with all the possible candidates, and performs the actions on them. But now as long as there's still another object overlapping the ground detector, it refuses to work.

The events I have regarding that are:

* Active ISN'T overlapping detector
= Set Y of Active to Y("Active")+1
= Set animation sequence to "falling"

* Active IS overlapping detector
= Set animation sequence to "walking"

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445
   

Post Reply



 



Advertisement

Worth A Click