• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Multiple Characters, One Script!!

H

Herlander

Guest
I'm fairly new to the community but already loving it. Posted a question and was answered immediately. Here's the question and response:

"hi, I'm kind of new to game maker and need some help.. was hoping you could help me out:

I wanted to know if there is a way to code your main player and have other player objects inherit it in a way that you only have to change the sprites to make a brand new character, given that the mechanics will be the same... Hopefully, you can help me on this"

"What you're looking for is parenting. Here is a link: https://docs.yoyogames.com/source/dadiospice/001_advanced use/more about objects/parents.html "

Now, how I implemented this was, I made the main character without any sprites, all the basic mechanics. Then i created various sprite variables and left them empty (i.e. spr_idle = ""; spr_run = ""; etc.). I declared the variables in the main character (sprite_index = spr_idle; etc..) and made it a parent of other player objects. so now all i have to do in the create event is define the variables (i.e. spr_idle = megaman_idle) to create many characters without having to code them all.

P.s.: I know this is hellah basic, but i made this thread on behalf of all the noobs such as myself lol
 
A

Alex_Beach

Guest
you're on the right track, but remember that using an event in a child will override the parent's same event, so you should use event_inherited(); before you declare your sprite code.
 
Top