Game Maker programming question
I'm pretty new to game maker (well since I've actually taken up programming anyway). Since then I used to do my own things from scratch, or work with unity.
I often use method overriding. It's just the most useful thing I got from OOP. Though I'm not sure what I can do in game maker which would be similar. Is there an alternative? I know about scripting, but how can I change a script to be customised for each child object?
I often use method overriding. It's just the most useful thing I got from OOP. Though I'm not sure what I can do in game maker which would be similar. Is there an alternative? I know about scripting, but how can I change a script to be customised for each child object?
Comments
I may have two objects. Each has an AttackOpponent function. Inside each has a Shoot function, which I want to "customise" so to speak, for each child object I make (say, one will shoot bullets, the other one rockets - so the shoot function for each will be unique, but yet they are both still considered a shoot function)
AttackOpponent
{
//similar code for all children here
shoot()
}
In other languages, I can put the AttackOpponent method in a base class, and have a Shoot() method which is overridable in some way. Then I can make the child classes, and extend this base class, and simply override the Shoot method, each implementing it in its own unique way. So then I can just generically call my AttackOpponent function for any child and know it will do what it should both the common code as well as the customised code as it should.
Does that make any sense whatsoever?
**************
ooh, I think the key is user-defined events
I'm not even sure whta you're talking about with user-defined events...
* And game maker has these user defined event things. If you go to an object, and add an event, one option is a user-defined event. So in my script I can call user-defined event 0, for instance, and then it will do the custom code for each object that uses the script
e.g.
Object Step:
Script "scr_shoot_bullet":
Otherwise I would suggest each shooting type you just dedicate and argument to the choice, so argument0 would be an integer for what shooting type to do.
I think you also need to make sure that one of each object exists in the game, then
pass the shoot_bullet or shoot_rocket to the script and in the script call event_perform_object(argument0,ev_other,ev_user0)
edit:
ok so as long as you reference the object id in the event_perform_object you don't need an instance of it in game
using the user0 event also lets you code the bullet_obj and rocket_obj as normal but be able to pass them to the script to change the way stuff shoots
I'll build a basic enemy class that has all the logic for cooldown and target detection and all that jazz, but when it fires, it calls event_perform(ev_other, ev_user0). Then in each different enemy type, I populate their user0 event with what I want their firing behavior to be like.
It's a little annoying and sloppy sometimes, but I've used this for all sorts of behaviors before - everything from collision response to network-synced events.