The Daily Click ::. Forums ::. Klik Coding Help ::. Placing new objects on top of randomly placed objects. MMF2.
 

Post Reply  Post Oekaki 
 

Posted By Message

Michael DeAngelo



Registered
  11/04/2012 17:20:32
Points
  22
11th April, 2012 at 11/04/2012 17:37:14 -

Hey all. I'm working on MMF2, and I've learned a lot from scouring these boards over the past few days. I am running into a block with what I currently have.

What I want to happen is this: As you proceed along a level, random gates will be populated from the first frame. This happens just as I'd prefer. At each of these gates, a baddie should appear, and patrol a certain amount of steps left and right and back again.

It creates the baddies without any problem, but it does not assign them to the gate properly. They will end up floating around randomly on the map.

My code looks to see if the alterable value of the gate is less than 3. If it is, it creates one of the gates on the map randomly, and ups to altval by 1. So, in essence, I should only have 3 gates. This seems to be working properly.

The code for the baddie is relatively similar. When the altval of the baddie is less than 3, it creates an instance of the baddie. It picks one of the gates, and creates a baddie at that gate. Now, the obvious problem here is that because it picks one of the gates, sometimes more than one baddie shows up at a gate. Is there an easy way to make it so that only one baddie shows up at each gate? Something with alterable values perhaps?




 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
11th April, 2012 at 11/04/2012 17:52:36 -

Have you tried "pick one of [gate object]" on the same event to see if that works for you?

 
n/a

Michael DeAngelo



Registered
  11/04/2012 17:20:32
Points
  22
11th April, 2012 at 11/04/2012 18:22:24 -

The actual code that I have currently is:

- Alterable Value A of "Gate" < 3
- Number of "Gate" in zone (-63,83) to (728,2500) < 3

Create "Gate" at (0,0) layer 1, set x position to Random (640), set y position to 1380 + Random (640), Add 1 to Alterable Value A of "Gate"


- Alterable Value A of "Baddie" < 3
- Pick one of "Gate"

Create "Baddie" at (0,0) from "Gate", add 1 to Alterable Value A of "Baddie"


For clarification, are you suggesting that I collapse the two events above into one event?

 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
11th April, 2012 at 11/04/2012 20:20:59 -

Well, I'm not so sure I'm understanding you correctly. But what I recommend you try to do is this:

IF [gate object] Alterable Value =/> 3
AND Flag 0 of [gate object] is OFF
THEN set Flag 0 of [gate object] to ON
AND [adjust Alterable Value to whatever...maybe (Alterable Value) -1]

IF Flag 0 of [gate object] is ON
THEN Create [baddie object] at 0,0 of Gate
AND set Flag 0 of [gate object] to OFF

That way, the Flag is the trigger (with two states of ON or OFF), instead of a changeable Alterable Value (which can have several numbers as its result, and thus more room for error and miscalculation).

Hopefully this will be useful to you...

 
n/a

Michael DeAngelo



Registered
  11/04/2012 17:20:32
Points
  22
11th April, 2012 at 11/04/2012 21:08:56 -

I'm sure it will. I'll look at it tomorrow when I get in, and I'll let you know how it worked. Thanks for the help!

 
n/a

Michael DeAngelo



Registered
  11/04/2012 17:20:32
Points
  22
11th April, 2012 at 11/04/2012 21:08:58 -

I'm sure it will. I'll look at it tomorrow when I get in, and I'll let you know how it worked. Thanks for the help!

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
12th April, 2012 at 12/04/2012 10:56:14 -

I don't understand this part:

- Alterable Value A of "Baddie" < 3
- Pick one of "Gate"

Create "Baddie" at (0,0) from "Gate", add 1 to Alterable Value A of "Baddie"


Here's what I would do:

IF number of Gates < 3
THEN create Gate object at random co-ordinates

IF Gate Alterable Flag A = 0
THEN create Baddie at Gate + set Gate Alterable Flag A to 1.

This will create 3 random gates and give them each a guard and if I'm not mistaken, is what you are trying to achieve. And as s-m-r (good bloke) suggested, feel free to use flags in place of alterable values.

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
12th April, 2012 at 12/04/2012 11:48:47 -

You shouldn't be using alterable values to count your objects, they're unique per instance. So every time you create a baddie, you're creating another fella with an alterable value A of <3 (assuming you haven't changed the starting value in object properties).

Number of gates < 3:
- Create gate at random position
- Create baddie at gate

BTW, this will take 3 frames to populate, if you want it to happen instantly you could use a fastloop, or just:

Start of frame:
-Create gate
-Create gate
-Create gate
- Set gate to random position
- Create baddie at gate

MMF won't discriminate between the three different gates, the subsequent two events will apply to all of them individually

 
n/a

Michael DeAngelo



Registered
  11/04/2012 17:20:32
Points
  22
12th April, 2012 at 12/04/2012 13:44:46 -

Thank you to everyone who replied!

I'm not up to speed yet with FastLoops (definitely going to give that a look), but Chris' code worked fine. Before that, I only had an inssue with multiple baddies showing up at the same gate.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click