Pixel Game Maker MV

Pixel Game Maker MV

Not enough ratings
Help a PARENT find it's CHILD!
By erobotan
The guide's purpose is to help a parent find it's child. A short example of a parent-child relation is a soldier who can wield various weapons. The soldier holding the weapon is the parent and the weapon is the child. Wherever the parent goes, the child will follow. Now if you have 5 of these soldiers on the screen and one of the soldier decide to cast a fire enchantment on his weapon which will make the weapon glow .. we as the programmer will soon meet a problem, how do we know which weapon is his?

   
Award
Favorite
Favorited
Unfavorite
Basic Logic
For this to work we will add a new object beside the soldier and the weapons. When a parent cast an enhancement spell, he will send a message contained his INSTANCE ID to this new object. The children are always monitoring this new object and when they see the changes in this object, they all will compare the object's message with their own PARENT INSTANCE ID. If it match then they will execute the glowing weapon action.
The characteristic of the New Object
1. Because the purpose of this object is to receive messages from the parent and let the children see it, we will name this object RELAYSTATION
2. Normally, you will only need 1 (one) of this object for the entire stage
3. This object has 2 action boxes, RECEIVER and EMITTER
4. This object has 1 new variable, SENDERID
5. No link or runtime action required
6. The default action box is RECEIVER
The Parent
1. When the parent want to search for it's child, the first thing that it will do is check RELAYSTATION's action.
Create a link and use "Specified Object's Action Changes" runtime action. Object = RELAYSTATION, Action = RECEIVER
2. If it's RECEIVER then the search process will continue and the parent will send it's INSTANCE ID variable to RELAYSTATION's SENDERID variable. Otherwise the parent is required to wait because the RELAYSTATION is in use by the other parent. The link in no.1 will point to this new action box
Create a new action box & name it SEARCCHILD. Add "Changes Switch/Variable". The content is RELAYSTATION - SENDER ID = OBJECT SELF - INSTANCE ID.
3. The parent will also change RELAYSTATION's action to EMITTER. This will signall the children to start doing their part
Add "Execute Object Action". Object = RELAYSTATION, Action = EMITTER
The Child
1. The children will always monitor the RELAYSTATION, so you will need to create and add this new link to all of the action boxes or use "common action". The whole process in child's side will only run when RELAYSTATION's action is EMITTER
Add "Specified Object's Action Change". Object = RELAYSTATION, Action = EMITTER
2. Still in the same link that we created in no.1, compare the child's PARENT INSTANCE ID variable with RELAYSTATION's SENDERID variable. If they're the same then you've found the correct child.
RELAYSTATION - SENDERID = OBJECT SELF - PARENT INSTANCE ID
3. The link that we created will point to whatever action box that the parent want the child to do. And finally you need to change back RELAYSTATION's action to RECEIVER in this action box. If you don't do this, the search function can only run once.
So add "Execute Object Action". Object = RELAYSTATION, Action = RECEIVER

this is my first time writing a guide, so let me know if you have suggestions for improvement or questions. Thanks!
5 Comments
erobotan  [author] Dec 29, 2019 @ 7:11pm 
as long as you properly program the parent to keep resend its message then they won't lost/overwritten.

unless your game is something like Dynasty Warriors/Sengoku Musou which will make the delay very noticeable since you can kill more than 20 enemies at the same time
JustusPan Dec 29, 2019 @ 7:05pm 
In my scenario, there a many enemies and each of them owned a child. they may be killed together on one frame, so they will change the action of REALYSTATION together, I think there is a risk that some of them will be lost or overwritten by other one.
erobotan  [author] Dec 29, 2019 @ 6:33pm 
@justuspan: the parent will have to wait and re-send his request in the next frame
JustusPan Dec 29, 2019 @ 6:22pm 
What will happen if two parent emitter in a same frame? will both their children been notified? or one of them will lost message?
Mr. Stimpson Jul 9, 2019 @ 10:25pm 
Haven't gotten this far in learning the software yet, but thank you for he effort!