Bat Trail

Hi


I'm finishing up my map code and I'd like to do the following:

There are two for every pair of levels. What I mean is, when the map is displayed it shows two exes. One ex is black and represents completed levels,
and the other ex is yellow and represents the next level to go to. The exes are just draw on the current map.

So that's some background. I'd like to have a trail of mini bats go from the old, finished level, and follow a path to the next level. When a mini bat
reaches the next level it is destroyed and another one is spawned at the last level.

So the following code is for spawning a mini bat:

GML:
if (global.completed_level1 == true && inst == noone)// && global.completed_level2 == false && inst != noone)
{
    show_debug_message("Completed trail one");
    inst = instance_create_depth(path_get_point_x(GrasslandsToForestTrail, 0), path_get_point_y(GrasslandsToForestTrail, 0),-1000, SentryBatWalkMap);
    if (instance_exists(inst))
    {
        show_debug_message("Trail Instance Exists")   
    }
    else
    {
        show_debug_message("Trail Instance Doesn't Exist")   
    }
}

///path from forest to snow
if (global.completed_level2== true && global.completed_level3 == false && inst2 == noone)
{
    show_debug_message("Completed trail two");
    
    inst2 = instance_create_depth(path_get_point_x(ForestToSnowTrailbk, 0), path_get_point_y(ForestToSnowTrailbk, 0),-1000, SentryBatWalkMap2);
    //inst2 = instance_create_depth(464, 254,
    
}

//snow to lava
if (global.completed_level3 == true && global.completed_level4 == false && inst3 == noone)
{
    show_debug_message("Completed trail three");
    inst3 = instance_create_depth(path_get_point_x(SnowToLavaTrailbk, 0), path_get_point_y(SnowToLavaTrailbk, 0),-1000, SentryBatWalkMap3);
    
}
Output:

Code:
Before Completed trail one.
Completed trail one
Creating path for GrasslandsToForestTrail
Trail Instance Exists
GrasslandsToForestTrail is a path in the room "GrasslandToForestMap"

ForestToSnowTrailbk is a path in the room "ForestToSnowPath"

SnowToLavaTrailbk is a path in the room "SnowToLavaPath"


Thanks everyone.


-TW
 

Nidoking

Member
It looks like you've already got a path. You can use the path_get_point functions to get points other than the start of the path and draw your bats. You could use instances, or just one controlling object that has an array of points and draws the sprites at those locations.
 
@Nidoking
You could use instances, or just one controlling object that has an array of points and draws the sprites at those locations.
Yeah I think I had it doing it that way before - using instances. Drawing them with an array of points seems like it would be more work
than using instances but i'm not sure how to use instances to do it. Could I possibly use points on the path and move the instances according
to the points on the path?
 

TailBit

Member
make a script and call it:
draw_path_points
GML:
var path = argument0;
var len = path_get_length(path);
var space = 15 / len; // space between points
var range = 40 / len; // how far from the start it should begin

for(var i = range + space/2;i<1-range;i += space){
    draw_sprite(spr_point,0,path_get_point_x(path,i),path_get_point_y(path,i))
}
Then you could do:
draw_path_points(GrasslandsToForestTrail)
ofc, change the sprite

You could have something like that which just creates the point instances on the path instead
 
Hey @TailBit
I copied your script in a draw_path_points script. I went to my first room and created an object with a step event that calls draw_path_points(GrasslandsToForestTrail). I moved the object into the Grasslands level in the map but when I compiled everything and took care of it and nothing happened.
 
SO this doesn't work...

draw_path_points(GrasslandsToForestTrail)

For this code:

GML:
(script)

var path = argument0;
var len = path_get_length(path);
var space = 15 / len; // space between points
var range = 40 / len; // how far from the start it should begin

for(var i = range + space/2;i<1-range;i += space){
    draw_sprite(MiniSentrySprite,0,path_get_point_x(path,i),path_get_point_y(path,i))
}
 
Ok. Since my post was deleted I'll go over it again.

My controller works like this:

GML:
if (mouse_check_button_released(mb_left))
{
    
    //Forest of Anguish
    if mouse_x < 390 && mouse_x > 340  && mouse_y > 320  && mouse_y < 370
    {
        if global.lastEx = 1
        {
            global.lastEx = 2
            global.game_map = 7;
            room_goto(SecondLevel)
        }
        
    }
}
        
//go to level 3
//Avalanche
if (mouse_check_button_released(mb_left))
{
    if (global.lastEx == 2)
    {
        if mouse_x < 649 && mouse_x > 500  && mouse_y > 297  && mouse_y < 330
        {
            //global.game_map = 6;
            global.game_map = 20;
            global.lastEx = 3
            room_goto(ThirdLevel)
        }
    }
}


//////////************LEVEL FOUR*************************/////////////


//The Forge
if (mouse_check_button_released(mb_left))
{
    if global.lastEx == 3
    {
        if mouse_x < 905 && mouse_x > 713 && mouse_y > 267  && mouse_y < 375
        {
            global.lastEx = 4
            global.game_map =30;
            show_debug_message("GLOBALGAMEMAP " + string(global.game_map));
            room_goto(FourthLevel)
        }
    }
}

//Deep Jungle
if (mouse_check_button_released(mb_left))
{
    
    //if mouse_x < 489 && mouse_x > 900  && mouse_y > 501  && mouse_y < 950
    ///{
    
    if mouse_x < 920 && mouse_x >650 && mouse_y > 500 && mouse_y < 628
    {
        if global.lastEx == 4
        {
            global.lastEx = 5
            
            global.game_map = 40;
            room_goto(FifthLevel)
        }
    }
}

etc..
The game starts in the First Level, First Stage. When you complete the First Level you are taken to the world map. The last level you were in, in this case the first level, is marked with a black ex. The next level has a yellow ex and when you click on it it is supposed to go to the next level. It does this correctly. So I go into level 2 and that works too and I can complete the level. So I am taken to the next level. Again, the previous level is marked with an ex and a yellow ex for the next level. So I click on the yellow ex and NOTHING happens. So I'm not sure what's wrong. I think it has something to do with the code above.
 
The game starts in the First Level, First Stage. When you complete the First Level you are taken to the world map. The last level you were in, in this case the first level, is marked with a black ex. The next level has a yellow ex and when you click on it it is supposed to go to the next level. It does this correctly. So I go into level 2 and that works too and I can complete the level. So I am taken to the next level. Again, the previous level is marked with an ex and a yellow ex for the next level. So I click on the yellow ex and NOTHING happens. So I'm not sure what's wrong. I think it has something to do with the code above.
I'm confused. What does this have to do with drawing the bat trail? You already have a topic about not being able to transfer to the next level:

So surely you would want to be continuing the conversation in that topic, instead of hijacking one of your other topics which is about a different issue (the trail not being drawn) and is now just going to lead to confusion on what problem you want us to help you with?
 

TailBit

Member
Oh, the script, change the path_get_point_x and y into path_get_x and y as you are not really after the points on the path but positions on the path .. you could draw on the points, but that would be a bit different code.

I can't see anything wrong with the map code, have you debugged it to see how far it get towards the room change?
 
Last edited:
I'm confused. What does this have to do with drawing the bat trail? You already have a topic about not being able to transfer to the next level:

So surely you would want to be continuing the conversation in that topic, instead of hijacking one of your other topics which is about a different issue (the trail not being drawn) and is now just going to lead to confusion on what problem you want us to help you with?
Because the one topic was deleted because the moderator said I was duplicating topics and the the topic you are referring to was deleted so i was to repeat that topic in this thread since this was supposed one of the pair of "duplicate topics." and it can't be two seperate threads.

(edit)

This moderator was supposed to pm me according to @Nocturne but has yet to contact me.

(edit)

I can't see anything wrong with the map code, have you debugged it to see how far it get towards the room change?
2020-10-08_12-27-03Debug.png
So above is a clip of the game map., maybe this will clear up some notions. The black ex is the completed Grasslands level. The yellow ex is the next level, the Forest level.
The blue creature is the Sentry Bat. Now, the Sentry Bat is supposed to be moving one bat at a time, not overlapping. Also the bats are supposed to walk from the black ex and the yellow ex . Finally, the Sentry Bat is supposed to be a lot smaller. Probably by a quarter or more.
 
Last edited:
Oh, the script, change the path_get_point_x and y into path_get_x and y as you are not really after the points on the path but positions on the path .. you could draw on the points, but that would be a bit different code.

I can't see anything wrong with the map code, have you debugged it to see how far it get towards the room change?
It works properly for the first two levels. After that, it is supposed to transition to the third level but it doesn't respond to any input.
 
Because the one topic was deleted because the moderator said I was duplicating topics and the the topic you are referring to was deleted
Yes, you duplicated a topic and that is why it was deleted. No your original topic that I linked to is not deleted and is sitting on page 3 of the Programming forum. If it was deleted I wouldn't be able to link it. So that is why I am wondering why you are now confusing your current topic about the path with a problem that you already have a (still open) topic about.
This moderator was supposed to pm me according to @Nocturne but has yet to contact me.
Why would they contact you when they have not deleted your original topic?
 

TailBit

Member
It works properly for the first two levels. After that, it is supposed to transition to the third level but it doesn't respond to any input.
That's why I asked if you have debugged it..

like how many of the if leading to the 3rd room change is it able to pass .. and if it doesn't pass one, have it print the values ..

with "doesn't respond to any input" you mean that it doesn't even pass the mouse_check_button_released?

GML:
//go to level 3
//Avalanche
if (mouse_check_button_released(mb_left))
{
    if (global.lastEx == 2)
    {
        if mouse_x < 649 && mouse_x > 500  && mouse_y > 297  && mouse_y < 330
        {
            //global.game_map = 6;
            global.game_map = 20;
            global.lastEx = 3
            room_goto(ThirdLevel)
        }else show_debug_message("Level3: mouse outside area " + string(mouse_x)+","+string(mouse_y))
    }else show_debug_message("Level3: lastEx is " + string(global.lastEx))
}
And I hope the edit to the script that I mentioned fixed it?
 
Last edited:
Yes, you duplicated a topic and that is why it was deleted. No your original topic that I linked to is not deleted and is sitting on page 3 of the Programming forum. If it was deleted I wouldn't be able to link it. So that is why I am wondering why you are now confusing your current topic about the path with a problem that you already have a (still open) topic about.

Why would they contact you when they have not deleted your original topic?
@Nocturne said they deleted the topic because it was a duplicate. Which it wasn't.

That's why I asked if you have debugged it..

like how many of the if leading to the 3rd room change is it able to pass .. and if it doesn't pass one, have it print the values ..

with "doesn't respond to any input" you mean that it doesn't even pass the mouse_check_button_released?
This has to be run through the debugger. Thanks to @TailBit . I'll be back in a bit.

(edit)

It's not going inside the boundaries. I should have checked before posting. I'm not sure if its working but that's one possible.
GML:
if mouse_x < 649 && mouse_x > 500  && mouse_y > 297  && mouse_y < 330 //stops here
        {
            show_debug_message("Passed border lines Ex")
            //global.game_map = 6;
            global.game_map = 20;
            global.lastEx = 3
            room_goto(ThirdLevel)
        }
 
Last edited:

Nidoking

Member
What are the actual screen coordinates of the X you're trying to click on? If I remember from the thread where you originally asked this question, they weren't the numbers you're checking there. This is why you should keep one question in one thread. You're not going to get a more satisfying answer by asking again elsewhere.
 

TailBit

Member
Well, I've had one game where the view scaling had messed with the mouse coordinates, so I had to recalculate the mouse position, to check if this is the case you can simply draw a line to the mouse:
draw_line(0,0,mouse_x,mouse_y)
and if it is the case then it should fail to follow the position of the mouse the more you go from the top left corner if I remember correct
 
Last edited:
GML:
SO this doesn't work...

draw_path_points(GrasslandsToForestTrail)

For this code:

GML:
(script)

var path = argument0;
var len = path_get_length(path);
var space = 15 / len; // space between points
var range = 40 / len; // how far from the start it should begin

for(var i = range + space/2;i<1-range;i += space){
    draw_sprite(MiniSentrySprite,0,path_get_point_x(path,i),path_get_point_y(path,i))
}
Twilight Raven Games
The idea is to make a trail of little guys move from one point to another by following a path.

path_get_point(xpath, i) is meant to get the x coordinate and y coordinate along
each i iteration following the path from start to finish
 

Nidoking

Member
I've lost track of what question you're trying to get answered at this point. The last thing I see in the thread is "this doesn't work" with no description of what it's doing that you don't want it to do.

One thing that leaps out at me is that the values 15 / len and 40 / len seem completely arbitrary, especially when you're comparing i (a point along the path) to range (presumably a kind of normalized value). What is the value 1-range supposed to represent as an end of loop condition?
 
I've lost track of what question you're trying to get answered at this point. The last thing I see in the thread is "this doesn't work" with no description of what it's doing that you don't want it to do.

One thing that leaps out at me is that the values 15 / len and 40 / len seem completely arbitrary, especially when you're comparing i (a point along the path) to range (presumably a kind of normalized value). What is the value 1-range supposed to represent as an end of loop condition?
I've lost track of what question you're trying to get answered at this point. The last thing I see in the thread is "this doesn't work" with no description of what it's doing that you don't want it to do.

One thing that leaps out at me is that the values 15 / len and 40 / len seem completely arbitrary, especially when you're comparing i (a point along the path) to range (presumably a kind of normalized value). What is the value 1-range supposed to represent as an end of loop condition?
So, I messaged you because what I'm doing isn't working. That is, I think the river has run dry. I was hoping that you could help me. You certainly have more experience with GMS2 than I do.
 

TailBit

Member
Already told you how to fix the script:
Oh, the script, change the path_get_point_x and y into path_get_x and y as you are not really after the points on the path but positions on the path .. you could draw on the points, but that would be a bit different code.
EDIT:
What is the value 1-range supposed to represent as an end of loop condition?
when using path_get_x/y then 0 is the start and 1 is the end of the path .. I wanted the path markers to keep a distance from the beginning and the end, in this case 40 pixels, which I convert to a scale to 0 to 1 by dividing it on the path length .. so the path starts at 40 pixels into the path and ends 40 pixels before the end.
 
Last edited:
Top