Reddit reviews GameMaker Game Programming with GML
We found 2 Reddit comments about GameMaker Game Programming with GML. Here are the top ones, ranked by their Reddit score.
We found 2 Reddit comments about GameMaker Game Programming with GML. Here are the top ones, ranked by their Reddit score.
Here's the gist of the state machine implementation I learned from GameMaker Game Programming with GML by Matthew DeLucas.
CREATE EVENT
//state constants, any states you want to have can go here, just assign each one a different number 0-15.
idle=0;
jump=1;
//state machine variables
//track what state you're in. I'm choosing idle to be the starting state.
state_id=idle;
//track whether your current state is different from the state you were in last step.
entered_new_state=true;
STEP EVENT
//temporary variable used for determining if our state has changed.
var current_state = state_id;
//All of the game logic for each state is going to be put into user defined events. The 0th event for idle, the 1st event for jump, etc.
event_user(state_id);
//the code that changes our state is going to be put into the user defined events. This will set entered_new_state to true if our state changed during the user defined event that happened this step.
if(current_state != state_id) entered_new_state=true;
USER DEFINED EVENT 0 (example)
//if we just entered this state, do some stuff...
if(entered_new_state){
sprite_index=spr_player_idle;
image_index=0;
image_speed=0.2;
entered_new_state=false; //turns off this variable so that this code is only run when we've just entered this state.
}
//here you can have any code that you want to happen while you are in this state.
//finally, you put your state transition code at the bottom.
if(keyboard_check_pressed(vk_space)) state_id=jump //jump when we push the space bar.
ALL DONE!
This is a very powerful and flexible system. I'd be happy to answer any questions you may have.
I bought this book. It teaches GML extensively:
GameMaker Game Programming with GML by Matthew DeLucas http://www.amazon.com/dp/1783559446/ref=cm_sw_r_udp_awd_.qF3tb0PG407M