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

Marching characters on map

Hi

I would like a sentry bat character to travel from one spot to another on the game map. So it appears that the sentry bat appears at the last level finished and they march to the next level on the game map.

This is the code:

The controller (TravelMasterbk) directs the march:

GML:
draw_trail_of_bats--;

global.spacing_myTimer += 0.001;

if (global.spacing_myTimer > 1.0)
{
    global.spacing_myTimer = 1.0;
}

global.spacing_myTimer2 += 0.001;
if global.spacing_myTimer2 > 1.0
{
    global.spacing_myTimer2 = 1.0;
}
    

global.spacing_myTimer3 += 0.001;
if global.spacing_myTimer3 > 1.0
{
    global.spacing_myTimer3 = 1.0;
}
    
    
if (draw_trail_of_bats <= 0)
{
    //inst =
    //path from grasslands to forest?
    inst = instance_create(300, 371, SentryBatWalkMap);
    with (inst)
    {
        path_start(Path53, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }

    draw_trail_of_bats = room_speed;
    
    //a path from forest to snow
    inst2 = instance_create(378, 354, SentryBatWalkMap);
    with (inst2)
    {
        path_start(Path54, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer2));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer2;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
    //open up snow level
//from snow to lava
    inst3 = instance_create(464, 254, SentryBatWalkMap);
    with (inst3)
    {
        path_start(Path55, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer3));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer3;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }


}
Where SentryBatWalkMap is an instance of the marching character. Its step event is:
Code:
if path_position == 1.0
{
    show_debug_message("Destroying bat.");
    instance_destroy();
}
When I try to run this I get the following error:

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object TravelMasterbk:

invalid with reference
 at gml_Object_TravelMasterbk_Draw_64 (line 90) -               path_start(Path53, 5, path_action_stop, 0);
############################################################################################
gml_Object_TravelMasterbk_Draw_64 (line 90)
Before you jump at it, Path53 exists as a path in the map room on the map.
 

Nidoking

Member
It does matter, because drawing sprites is something you should do in the Draw event. Creating instances is not something you should do in the Draw event. Maybe try doing what you're doing in a Step event instead, and let the instances draw themselves using their own Draw events.
 
Turns out the real reason for using the Draw Event was that I was using the Draw GUI event since I thought the Draw GUI draws over every layers and I want this code to display at the very top. Is that a bad idea? Also, the code for the Step Event turns out is being used for something else right now -- detecting clicking on new levels. I put the code that was in the Draw GUI was for those reasons.

@Nidoking I moved the code from the Draw Event over to the Step event. I also am still getting that error:

GML:
############################################################################################
ERROR in
action number 1
of  Step Event0
for object TravelMasterbk:

invalid with reference
 at gml_Object_TravelMasterbk_Step_0 (line 38) -               path_start(Path53, 5, path_action_stop, 0);
############################################################################################
gml_Object_TravelMasterbk_Step_0 (line 38)
 
Last edited:
Well, it says in the debug message it's an invalid with reference. Have you double checked that SentryBatWalkMap is actually an object?
Are you using GMS2? If so, it sould be instance_create_layer (or _depth), not just instance_create()

Turns out the real reason for using the Draw Event was that I was using the Draw GUI event since I thought the Draw GUI draws over every layers and I want this code to display at the very top. Is that a bad idea?
Draw GUI will indeed draw on top, but it's thing is that it will not move with the camera. It's, as the name imply, best used for drawing GUIs. Anything that exists in the in-game world (even if "invisible" to instances, like a pointer) should be drawn in the draw event (political choice, here). You can still use draw_end if you want to make triple-sure you will draw over what's in the regular draw event.
 
Last edited:

kburkhart84

Firehammer Games
@Master Cabalist

Dude, you've got to learn to quit opening more topics for the same thing. Try fixing what they tell you instead of isolating code and then posting another topic when you've already posted that code here. This isn't the first time you've done this, making multiple topics when it doesn't go your way in one.
 
@kburkhart84

I don't know what you are talking about opening with the same topic.
One post was about traveling characters on the game map. The other topic was about the wtih command and if I could use an instance or if it had to be an object (my with error) and the last was about a character in a game room and its actual path being off from the path drawn on the room.

(edit)

@kburkhart84
1. Are you using GMS before version 2? Otherwise, that instance_create() function won't be right.

2. Can you confirm that "SentryBatWalkMap" is the name of an object, correctly written?

3. If you comment out the whole part inside the brackets of the with() statement, do you still get an error? If so, is it the same?
1. No. I'm using version 2.3
2. Yeah it is an object. I had this working before. Its supposed to (on the map) have a trail (like lemmings) from the level you just beat
to the next level you will enter. If I create an instance inst of SentryBatWalkMap how can I make that instance follow a path you create in the
room editor.
3.The error was because I used an instance in a with statement.
 
Last edited:

kburkhart84

Firehammer Games
@kburkhart84

I don't know what you are talking about opening with the same topic.
One post was about traveling characters on the game map. The other topic was about the wtih command and if I could use an instance or if it had to be an object (my with error) and the last was about a character in a game room and its actual path being off from the path drawn on the room.
Considering that you are having difficulty here with the exact same code, you very well could have asked the question about the with() statement here as well. That's why it comes across as a duplicate. And that's an easy judgement to make considering you have a history of closed duplicate topics. It is what it is.
 
Considering that you are having difficulty here with the exact same code, you very well could have asked the question about the with() statement here as well. That's why it comes across as a duplicate. And that's an easy judgement to make considering you have a history of closed duplicate topics. It is what it is.
I guess so. I didn't get the help I needed anyway. I don't understand why people get so upset about it. Not supporting the double post, but seriously, half the time it just seems like a witch hunt.
I haven't posted for a few weeks and when I get back immediately I'm getting reported and everyone has a fit about me posting two posts that were related.

And what did we get of all this? I'm stuck at the same spot I was before, with a scalding for a post. Thanks guys.

(edit)
I'm not sure if this is a duplicate post or not. For anyone who would mind helping me I have the following problem:

GML:
draw_trail_of_bats--;

global.spacing_myTimer += 0.001;

if (global.spacing_myTimer > 1.0)
{
    global.spacing_myTimer = 1.0;
}

global.spacing_myTimer2 += 0.001;
if global.spacing_myTimer2 > 1.0
{
    global.spacing_myTimer2 = 1.0;
}
   

global.spacing_myTimer3 += 0.001;
if global.spacing_myTimer3 > 1.0
{
    global.spacing_myTimer3 = 1.0;
}
   
   
if (draw_trail_of_bats <= 0)
{
    //inst =
    //path from grasslands to forest?
    inst = instance_create(300, 371, SentryBatWalkMap);
    with (SentryBatWalkMap)
    {
        path_start(Path53, 5, path_action_stop, 0);
        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer));
        show_debug_message("Path Position: " + string(path_position));
        path_position = global.spacing_myTimer;
        show_debug_message("Updated path_position" + string(path_position));
        path_end();
    }
I need to know how to make that "inst" instance's path. Is there a way to use path_start for the inst instance? I wrote this code a while back and I can't seem to
remember how it works. :)

(edit)

I changed the code:

GML:
In the Step Event of the Controller:

inst = instance_create(300, 371, SentryBatWalkMap);


in SentryBatWalkMapStep:


        path_start(Path53, 5, path_action_stop, 0);

        show_debug_message("Spacing myTimer:" + string(global.spacing_myTimer));

        show_debug_message("Path Position: " + string(path_position));

        path_position = global.spacing_myTimer;

        show_debug_message("Updated path_position" + string(path_position));

        path_end();

    }
I tried to put a debug statement in the SentryWalkMap's create event and it doesn't
show up. [/CODE]
 
Last edited:

Nidoking

Member
Are you using GMS2? If so, it sould be instance_create_layer (or _depth), not just instance_create()
Did you make this change? There's no instance_create function in GMS 2.3. It might be an obsolescence wrapper function created during an import, in which case, it would be best to stop using it and use the correct functions. There may not actually be an instance of SentryBatWalkMap created, which might account for the problem in the with statement. You can certainly use an instance ID in a with, but the instance has to exist.
 
I guess so. I didn't get the help I needed anyway.
Dude, I LITERALY told you the solution, instance_create() IS NOT A FUNCTION IN GMS 2.3, unless you made your own extension, which I highly doubt.
How much more help do you want?

There may not actually be an instance of SentryBatWalkMap created
Of course there's not, and this "function" should not even highlight orange in his IDE, this is werid if it does...
 

kburkhart84

Firehammer Games
Did you make this change? There's no instance_create function in GMS 2.3. It might be an obsolescence wrapper function created during an import, in which case, it would be best to stop using it and use the correct functions. There may not actually be an instance of SentryBatWalkMap created, which might account for the problem in the with statement. You can certainly use an instance ID in a with, but the instance has to exist.
Dude, I LITERALY told you the solution, instance_create() IS NOT A FUNCTION IN GMS 2.3, unless you made your own extension, which I highly doubt.
How much more help do you want?


Of course there's not, and this "function" should not even highlight orange in his IDE, this is werid if it does...
In that post that was closed I literally said the same thing, though I asked if He was on GMS2 or 1 instead of assuming since that post didn't show what version He is on. If this one doesn't start applying help when given, I may just not offer the help anymore.
 
In that post that was closed I literally said the same thing, though I asked if He was on GMS2 or 1 instead of assuming since that post didn't show what version He is on. If this one doesn't start applying help when given, I may just not offer the help anymore.
This reads like a page of my bio, here. This project has been a coding mess since years, but the art kind of makes me want to see it come through. I dig it.
But yeah, having a million global variables and 52 paths in essentially a Plants vs. Zombie kind of thing is not going to make things simpler for anybody, and is a clear sign of lack of organization and planning, but hey...who can throw the first stone on that? We all did this, and maybe still do from time to time, the important thing is to learn how to make things simpler for the next time around. All hope is not lost, but this guy should have a dedicated thread with a GitHub link so we can really see what's going on.
And nope, I didn't assumed anything version-wise, it was quite easy to find given the number of posts he has! ;)
 
Last edited:
This reads like a page of my bio, here. This project has been a coding mess since years, but the art kind of makes me want to see it come through. I dig it.
But yeah, having a million global variables and 52 paths in essentially a Plants vs. Zombie kind of thing is not going to make things simpler for anybody, and is a clear sign of lack of organization and planning, but hey...who can throw the first stone on that? We all did this, and maybe still do from time to time, the important thing is to learn how to make things simpler for the next time around. All hope is not lost, but this guy should have a dedicated thread with a GitHub link so we can really see what's going on.
And nope, I didn't assumed anything version-wise, it was quite easy to find given the number of posts he has! ;)
This project has been a coding mess since years, but the art kind of makes me want to see it come through. I dig it.
Is this in reference to my project? If so, its been a learning process and I have a lot of people I have to thank and a lot of people were more hindrances than help. Its nothing like Plants VS Zombie. I agree there was a lack of organization and planning in my project. I've never coded a complete game on my own and I wish people would respect that.

All hope is not lost, but this guy should have a dedicated thread with a GitHub link so we can really see what's going on.
Is it possible to put a GMS2 Project on GitHub? I'd be willing to put my project up on it. I just don't want it to be open source and to piss my work away.

Finally, it was a foolish move and I blame YoYo partly. I used instance_create instead of instance_create_depth. If I try to use instance_create the compiler should flag it. Come on, its version 2.3 and this still is an issue.
 
Is this in reference to my project? If so, its been a learning process and I have a lot of people I have to thank and a lot of people were more hindrances than help. Its nothing like Plants VS Zombie. I agree there was a lack of organization and planning in my project. I've never coded a complete game on my own and I wish people would respect that.
Maybe the PvZ reference is buried deep. And I totally get the experience coming in thing. Been there, done that, and can't even decipher some older projects I made, I'm not being dickish at all, man.
But you were working on this, asking the same type of questions in the same manner, and not organizing stuff like people told you back before my Gmail account was hacked and my digital life went cypher (lost all accounts on everything imaginable). That was over a year ago. But like I said, I'm not being an *** at all, I dig the art and the perseverence.

Is it possible to put a GMS2 Project on GitHub? I'd be willing to put my project up on it. I just don't want it to be open source and to piss my work away.
Yes. To my knowledge, you can put pretty much anything on it. And it's a must...what if your hard drives dies or something? At least you have a full project backup. And...Don't take it the wrong way, but pretty much anyone here on the forum has access to your source code, lol.

Finally, it was a foolish move and I blame YoYo partly. I used instance_create instead of instance_create_depth. If I try to use instance_create the compiler should flag it. Come on, its version 2.3 and this still is an issue.
Well, in my IDE (latest build), it doesn't pop in orange as a function would. Does it in yours? If so, and you use the latest build, this should probably be reported as a bug. Maybe you use old scripts with compatibility scripts, and such?
 

kburkhart84

Firehammer Games
Finally, it was a foolish move and I blame YoYo partly. I used instance_create instead of instance_create_depth. If I try to use instance_create the compiler should flag it. Come on, its version 2.3 and this still is an issue.
I'm on 2.3, I get a yellow triangle complaining that instance_create is a variable that is only used once. Since we can now do methods, etc... and directly call them through the variables, it makes sense that the compiler can't pick it up right away. And if I run the code anyway, I get a full stop with an error message, which makes sense because the code isn't valid. Is that not what's happening in your case? It should be.

Is this in reference to my project?
It seems like slowfingers was comparing your project to their own past, especially when they mention how we have all done it(and still do in some cases). I know I personally went through that learning phase as well, though in the case of GML not so bad because I already had programming experience elsewhere so I applied what I knew here and didn't suffer as much as many seem to. I also never suffered to get help, because I asked proper questions, explained things better, and properly attempted solutions when they were given to me.

Is it possible to put a GMS2 Project on GitHub? I'd be willing to put my project up on it. I just don't want it to be open source and to piss my work away.
I personally am using Github for version control and extra backup for my stuff with GMS2. I'm using Github Desktop to handle it for me. My stuff is not open source either. There used to be a thing(and still is with some source control services) where you can't do it for free unless its public/open source, but github is not like that. I recommend you use it if you don't have another solution. I also recommend it be done outside of GMS2 using a separate client(like Github Desktop) instead of trying to use the stuff that is integrated with GMS2. I've seen nothing but bad reviews on the integrated stuff...and by using it externally I can include my documentation and any other files that aren't part of the GMS2 project(like 3d model files that I'm pre-rendering into sprites).
 
Top