GMS 2.3+ Functions and Events not Running

I'm fairly new to GML2 so I was following Shaun Spalding's Action RPG tutorial. When I got to Eps 24 Enemy Basics, I wrote down all the code word for word and double-checked my code many times but the "slimes" don't move at all. They just stay stationary and run their sprite sheet (bobbing up and down). Then when I went back a few videos (because I skipped a few) to do Eps 19 Room Transitions I did the same and copied the code word for word and the rooms just don't change. Can someone help me? (Code Below)

Slime Wander:

GML:
function SlimeWander(){

sprite_index = sprMove;

//At destnation of given up

if ((x == xTo) && (y == yTo) || timePassed > enimyWanderDistance / enimySpeed)
{
    hSpeed = 0;
    vSpeed = 0;
    //end move end animation
   
    if (image_index < 1)
    {
        image_speed = 0.0;
        image_index = 0;
    }
   
    //Set New Destenation
    if (++wait >= waitDuration)
    {
        wait = 0;
        timePassed = 0;
        dir = point_direction(x,y,xstart,ystart) + irandom_range(-45,45);
        xTo = x + lengthdir_x(enimyWanderDistance, dir);
        yTo = y + lengthdir_y(enimyWanderDistance, dir);
    }
}
else //Move Twords Next Destenation
{
    timePassed++;
    image_speed = 1.0
    var _distanceToGo = point_distance(x,y,xTo,yTo);
    var _speedThisFrame = enimySpeed;
    if (_distanceToGo < enimySpeed) _speedThisFrame = _distanceToGo;
    dir = point_direction(x,y,xTo,yTo);
    hSpeed = lengthdir_x(_speedThisFrame, dir);
    vSpeed = lengthdir_y(_speedThisFrame, dir);
    if (hSpeed != 0) image_xscale = sign(hSpeed);
   
    //Colide and Move
    EnimyTileCollison();

}

}
Room transitions:

GML:
if (instance_exists(oPlayer)) && (position_meeting(oPlayer.x,oPlayer.y,id))
{
    global.targetroom = targetRoom;
    global.targetx = targetx; 
    global.targety = targety;
    global.targetDirection = oPlayer.direction;
    room_goto(targetRoom);
    instance_destroy();
}
Global variables are done correctly I check many times so I won't post them.

Video Links:

Room Transitions:
Slime:

Hope I can get some help with this.


MOD EDIT: Added code tags to make it easier to read. ;)
 
Last edited by a moderator:

rytan451

Member
Hi, for future reference, please wrap your code in code tags. They look like this:

[code=gml]
function foo() {
show_debug_message("bar");
}
[/code]

And they make your code look like this:

GML:
function foo() {
  show_debug_message("bar");
}
Reading code not formatted like code is annoying, which is not something you want to do when asking for help.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Where do you actually MOVE the instance? The code sets the custom variables hSpeed/vSpeed, but I don't see them being used... also, this is problematic:
GML:
if ((x == xTo) && (y == yTo)
You are not setting integer values for the h/vSpeed variables, so it's almost impossible that either of those statements will ever be true.

As for the room transitions, the only way I can see it not working is if the instance doing the checking doesn't have a valid collision mask. Position meeting requires a mask, so ensure that the room transition object has a sprite or a collision mask assigned to it.
 
Where do you actually MOVE the instance? The code sets the custom variables hSpeed/vSpeed, but I don't see them being used... also, this is problematic:
GML:
if ((x == xTo) && (y == yTo)
You are not setting integer values for the h/vSpeed variables, so it's almost impossible that either of those statements will ever be true.

As for the room transitions, the only way I can see it not working is if the instance doing the checking doesn't have a valid collision mask. Position meeting requires a mask, so ensure that the room transition object has a sprite or a collision mask assigned to it.
So for hSpeed/vSpeed I use as a custom variable for most of my movement and same with xTo/yTo. xTo/yTo is what I use as my destination variables so I would be able to stop the script if xTo/yTo has been reached. In my managing object, I set both sets of variables to 0 in the creat event so they are assigned integer values but they seem to not work still. For the room transitions I tried to set the rectangle and precise per frame and both of them still don't change the room when I walk into it. Is there any edit I could make to my code?
 
Top