Windows Programming a Complex Series of Events

SanDeity

Member
Hello everybody! I am somewhat new to Game Maker and I am using Game Maker 2. This is my first post on here and I have used the community without making an account for a long time to help solve issued I had with programming but I have recently run into a slight issue with a big project I am working on. Unfortunately I don't want to give away too much information about what I am creating because I like to keep things secret and a surprise. Anyway I will present a scenario with what I am trying to do and what I want to do and see if anyone can help me out!

To start, I am trying to create a section of a game where you are in one room and different things can happen. The player is not free roam so I have an object in a location where the player can be. I would like the player to be able to hold right or left and have the object move to 2 different locations while holding down the direction. In all three of these locations they will have multiple different actions say: jump, dodge, attack, ect. While jumping they should have different interactions with a collision than if they were attacking. I am struggling to figure out a way to get this to work smoothly.
The complex part about this is that while blocking I would like them to be able to hold down the block button and have the sprite change to blocking sprite, with a different interaction than if they were to press nothing. However when they attack or jump I need the sprite to change for a set amount of time, and set a cool down on that so they can't infinitely jump giving I-frames at all times.

Now: what I have done is I set up a default object that if you press nothing, it does nothing. I have about 9 separate objects that will move to location on screen if a button is held and will move off if it is not pressed. The way I am doing this is on the main object I have global.stance set to 0 and it changes to -1 for left or 1 for right. Then it also changes to -2 for left and blocking, 2 for right and blocking. I also have some extra events fit in where if you are in stance 1 or 2 the background will move.
I am running into multiple issues with this setup and and having trouble finding different ways to code this room. Is there a better setup I can run where the object moves and switches sprites, and as certain events are activated (such as jumping) it will swap the sprite and hit box to a different one with a different interaction for room_speed setting off an alarm to set up a cool down for it and changing back to original sprite? Or is there another way I just don't know about yet that would work even better?

Thank you for your time and please let me know what resources I can use to figure this out or how I can code this whole sequence better.
 

Alexx

Member
Welcome to the forums!
I would look into using enums and states for this.
This would make it easy to keep track of what is happening.

For cool down time look at using an alarm or two.

Have a search around the forums (and google) you can probably find lots of info and examples.
If you need help with any code, then post what you have and someone can point you in the right direction.
 

SanDeity

Member
Heck yeah, thanks for the advice!
The thing I love most about Game Maker is there is just so much more to explore and learn. I don't know how I haven't heard of enums and I haven't used states yet.
I'll post again if I come to situations I can't figure out!
 

Evanski

Raccoon Lord
Forum Staff
Moderator
sprite_index and number will help you with sprite things

enums and state machines will help you control the character with certain things

mouse_check_pressed(mouse button) will help you with the mouse clicks

https://docs2.yoyogames.com/ here is your codenomicon

youtube is pretty good just find the right person to teach guides I recommend friendly cosmonaut GMwolf and pixelated pope

google will hold the ability to find some answers sometimes

welcome to the forum, please check out the rules https://forum.yoyogames.com/index.php?threads/community-guidelines.4/
 

SanDeity

Member
Thank you EvanSki, I always have the manual open and use it frequently, I also use YouTube and search the forums often as well.
However not knowing all of GML I just want to make sure I get the right foundation for working on this project as I don't want to put it a ton of work and then have to bail to find out I should do something a different way. I have many things in this project working correctly and it get's me more excited each time I work on it.
 
Z

zendraw

Guest
you can just use if (statement) {} else {}; and nest them. if its hard for you to do it in code, draw it, its logic.
 
Nested if statements can get wildly out of hand quickly. The previous suggestions for building a finite state machine are much better than nested ifs.
 
Top