• 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!

stopping at distance in platformer??

heres my monster code, in a perfect world he walks up to him and swings his sword, however he keeps ping ponging back and forth and not swinging.

any help or idea with my code?



if moving=true and hiding=false and see=false{
sprite_index=banditmove
if dir=1{hspeed=-1}
if dir=2{hspeed=1 }
}

//if hiding=true{
//hspeed=0
///sprite_index=mondead
//}

if hiding =true and hurt=false {
hurt=true alarm[0]=60}

if see=true and hiding=false{
hspeed=0
sprite_index=banditstand
}

if distance_to_object(owen)<70 and see=false and stopsee=false and fallow=false{
see=true}
if distance_to_object(owen)>80 and see=false and stopsee=true and fallow=true{
stopsee=false
fallow=false}


if see =true and stopsee=false {
stopsee=true alarm[1]=30}
{
if fallow=true and hiding=false {
if self.x-30 > owen.x{hspeed =-2 dir=1}
if self.x+30 < owen.x{hspeed =2 dir=2}
sprite_index=banditmove}

else

if fallow=true and hiding=false {
if self.x-10 > owen.x{hspeed =0 dir=1}
if self.x+10 < owen.x{hspeed =0 dir=2}
sprite_index=banditattack}



}
 

Slyddar

Member
That code seems...complex. Have you considered using state machines? It would simplify the amount of flag checks you are using and make this process much simpler.
 

Slyddar

Member
im using gm8. i dont like studio since it saves every time you run it.
The version is not relevant. GM8 still supports state machines. Yoyo's official tutorial shows how to use them on GMS2, but it's the same concept - https://www.yoyogames.com/blog/555/coffee-break-tutorials-finite-state-machines-gml

With that kind of knowledge you could set up your objects with various states, which will allow you to control the object much more effeciently. Once you have it working, you will wonder how you did without it. Believe me, we've all been at the stage you are, trying to juggle many flags in one step event, with each flag changing tripping over another. State machines will solve that problem for you.
 

FrostyCat

Redemption Seeker
I don’t think enum works in GM8… how would you implement the states in GM8. Just curious.
You would implement them as regular string literals.
GML:
state = "idle";
GML:
switch (state) {
    case "idle":
        /* ... */
    break;
    case "walking":
        /* ... */
    break;
    case "running":
        /* ... */
    break;
}
And besides, enums wouldn't be the only thing in the tutorial that won't work in GM8. Inline var assignments, instance_create_layer, and audio_play_sound are all changes that happened well after GM8's sunset. Choosing a decade-old version of GM just to avoid saving before running has its consequences, not the least of which is having almost no community support.
 

KodiBoz

Member
Thank you🙏

I have been playing around with Enigma and LateralGM. I swear it looks almost Identical to the older game maker.(pre-studio) and you can even load gm6, gm6, gmx files and even export to different format.
Unfortunately, I can’t seem to get it to work. Lol @myself.
 
Last edited:

KodiBoz

Member
You would implement them as regular string literals.
GML:
state = "idle";
GML:
switch (state) {
    case "idle":
        /* ... */
    break;
    case "walking":
        /* ... */
    break;
    case "running":
        /* ... */
    break;
}
And besides, enums wouldn't be the only thing in the tutorial that won't work in GM8. Inline var assignments, instance_create_layer, and audio_play_sound are all changes that happened well after GM8's sunset. Choosing a decade-old version of GM just to avoid saving before running has its consequences, not the least of which is having almost no community support.
Thank you
 
Top