• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GML Defining States with Objects - GMWolf

G

Guest

Guest
This is an intriguing way to set states, but I'm not sure what the advantage is over the traditional method of:
  • Make your actor's step event one line, executing scr_states.
  • Make scr_states just a megaswitch telling your actors what script to run depending on their state (i.e., switch (state) { case (specific_state): scr_specific_state(); break; }).
  • Write scr_specific_state and all its friends so that they do their thing and then shunt your actor back into some benign waiting state like idle or patrol or whatever.
  • Trigger your actors into different states (state = specific_state) as appropriate, based on checks located internally to the actors themselves, externally in other actors who do something alarming like get close or attack, or in an input system.
Aren't you basically just shifting the specific_state scripts to objects?

Also, this is a different way of thinking than I'm used to. Is this an implementation of a particular approach to object-oriented architecture? I've been reading about object-oriented basics (classes, structures, etc.) as well as the entity component system approach. If you're implementing "real programming language" architecture into GML, I'd love it if you explained that, as a sort of translator or bridge between the wider world of game dev and GameMaker.
 
Last edited by a moderator:

GMWolf

aka fel666
Aren't you basically just shifting the specific_state scripts to objects?
Not really.
All an object is is a mapping from events to scripts.
This means that youu can describe the behaviour of multiple events in a single object.
Basically: a single state object can describe the behaviour of multiple events.
However, a script can only describe a singe event.

Internally GM will compile this down to a switch statement. So there isn't really a point to do it yourself when objects will make things easier.

Is this an implementation of a particular approach to object-oriented architecture?
Not really. It's a pretty GM thing to do.
But it is quite close to OO state machines in that each state has it's own class.

If you're implementing "real programming language" architecture into GML, I'd love it if you explained that, as a sort of translator or bridge between the wider world of game dev and GameMaker.
I have already made an OO in gamemakers video. It probably need a a small update, but I still think its a useful video to check out.
 
S

Snayff

Guest
I am just starting to learn about state machines so this sounds interesting.

@Fel666 if you were to rate the difficulty would you say that using objects instead of scripts is easier, harder, or about the same? (trying to judge whether to learn traditional or this first!)
 

GMWolf

aka fel666
I am just starting to learn about state machines so this sounds interesting.

@Fel666 if you were to rate the difficulty would you say that using objects instead of scripts is easier, harder, or about the same? (trying to judge whether to learn traditional or this first!)
I would suggest you check out my other state machine video first. Then learn this system.
This system my be a little trickier to understand, but it is easier in the long run.
 
Last edited:
Top