I'm sure a thread on this exists but I can't find it.
How would I make associations between objects such that each 'enemy' object has a 'weapon' object associated with it? Furthermore, how can create some sort of hierarchy of control (ie. does the enemy object control the weapon object, or does the weapon object control the enemy object?)
As always, mmf isn't the most cooperative software. So far I've tried doing this:
Start of Frame
- spead value 0 in 'enemy' value A
Start of Frame
- if weapon is overlapping enemy
THEN
- 'weapon' value A = 'enemy' value A
if weapon value A = enemy value A
- set weapon at (0,0) relative to enemy
This doesn't work. I tried the same method with fixed values as opposed to the spread value. No luck. Any ideas?
Shab:
No, the code executes when the program begins
Whats actually happening is the values of the weapons are messed up. For example, lets say I've got enemy1, enemy2, weapon1 and weapon2. enemy1 is overlapping weapon1 when the frame starts and enemy is overlaping weapon2 when the frame starts. For some reason, weapon1 gets the value of enemy2 and weapon2 gets the value of enemy1.
^^BUT DISREGARD ALL THAT^^ I just wrote all that to demonstrate how much of an illogical bitch, mmf can be.
I'm looking for new ways to create associations between two objects.
1. If the number of enemies and weapons are different, strange things will happen
2. There is no relation made between the enemy and weapon therefore neither object can 'talk' with the other. For example, if the enemy shoots a bullet, I can't tell the relative weapon to play the shooting animaton.
3. Similar to the point above, if an enemy dies, there is no way to tell which weapon is associated with that enemy (and therefore also needs to be destroyed)
The whole point of this thread is asking how to acreate ASSOCIATIONS between objects. Not simply sticking two objects together.
You last line:
if weapon value A = enemy value A
- set weapon at (0,0) relative to enemy
should be in a loop (two loops I think, one that goes through all enemies and one that goes through all weapons). MMF only goes through every event just once, so it'll take the last weapon created and last enemy created and starts comparing, whereas you want all weapons and all enemies to be examined.
Toxic Avenger's example does work. Even though there isn't anything that relates weapons and enemies, MMF does some magic and it'll work. Doesn't make sense, but I think it's an exception CT build in.
First, assign an unique ID to all guns and enemies using "spread a value":
* Always
- Enemy: Spread value 0 in Value A
- Gun: Spread value 0 in Value A
Then, balance the number of enemies and guns using a fastloop:
* Always
- Run loop "foo" NObjects("Enemy") times
* On loop "foo"
* NObjects("Enemy") < NObjects("Gun")
* Pick one "Gun"
- Gun: Destroy
* On loop "foo"
* NObjects("Enemy") > NObjects("Gun")
- Create "Gun" at (-100, -100)
Then, use a fastloop and the IDs you just assigned to the objects to associate them to each other. As an example, I will attach them to each other, like so:
* Always
- Start loop "bar" NObjects("Enemy")
* On loop "bar"
* Value A of "Enemy" == LoopIndex("bar")
* Value A of "Gun" == LoopIndex("bar")
- Gun: Set position to (0,0) from "Enemy"
Axel's fast loop suggestions should fix everyting in MMF. Since I've discovered the ways of the loop, things that I once thought were impossible are now easy as Yoshi's Story for the Nintendo 64. ;D
Originally Posted by axel First, assign an unique ID to all guns and enemies using "spread a value":
* Always
- Enemy: Spread value 0 in Value A
- Gun: Spread value 0 in Value A
Then, balance the number of enemies and guns using a fastloop:
* Always
- Run loop "foo" NObjects("Enemy") times
* On loop "foo"
* NObjects("Enemy") < NObjects("Gun")
* Pick one "Gun"
- Gun: Destroy
* On loop "foo"
* NObjects("Enemy") > NObjects("Gun")
- Create "Gun" at (-100, -100)
Then, use a fastloop and the IDs you just assigned to the objects to associate them to each other. As an example, I will attach them to each other, like so:
* Always
- Start loop "bar" NObjects("Enemy")
* On loop "bar"
* Value A of "Enemy" == LoopIndex("bar")
* Value A of "Gun" == LoopIndex("bar")
- Gun: Set position to (0,0) from "Enemy"
Hope this helps!
Edited by the Author.
Using NObjects("Enemy")+1 makes it glitch less, I've found.