SOLVED Two issues related to?

I have two issues I think are related to how I manage memory and resources in my game. The first is that the cursor, when there are a large number of brains on screen (bad guys), sometimes vanishes. The second issue is more severe.
One of my bats (good guys), has an attack where he is gigantic and rolls across the screen pummeling any brains that are around. This attack works perfectly sometimes, but sometimes when there is more than one brain on screen
the game crashes. No error code, nothing. Just fails. I'm trying to tackle these issues. I have two levels set up in texture groups, and the interface is a texture group as well. I'm wondering if texture groups will help to solve the probllem
and how so. Just FYI, if I run the game in the debugger and attack with the muscle bat (the big guy) the debugger gives no error code either. The game just flat out dies.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
For problem 1) we'll need more info. Are you using a custom cursor? Or the windows cursor? If it's custom how is it being drawn? By a controller? By an object?

For 2) the best thing to do first is add in a LOAD of show_debug_message() calls into the bat object and see if you can't narrow down the part of the code that is creating the crash. So, before each section of code in the step event, add a message. In the collision events, add a message, etc... You can then check the output logs to see what the last message was, remove all the other ones and start adding more at a granular level after the last one before the crash.
 
Problem 1) It is a custom cursor set in the room creation code at the start of the game. Problem 2) I'll do that and check back with you.
 
It seems its dieing on this piece of code:



GML:
with (BrainParentObject)
{
    //floater = instance_create_depth(x+10, y-10, -1700, MuscleDamageIndicatorObject);
    hp_minus = irandom_range(500, 2000);
    //floater.text = string(hp_minus);
    hp = hp - hp_minus;
    instance_create(x, y, DeadBrainObject);
    instance_destroy();
    //instance_destroy();
}
 

rIKmAN

Member
It seems its dieing on this piece of code:



GML:
with (BrainParentObject)
{
    //floater = instance_create_depth(x+10, y-10, -1700, MuscleDamageIndicatorObject);
    hp_minus = irandom_range(500, 2000);
    //floater.text = string(hp_minus);
    hp = hp - hp_minus;
    instance_create(x, y, DeadBrainObject);
    instance_destroy();
    //instance_destroy();
}
instance_create() isn't a GMS2 function.

Use instance_create_layer() or instance_create_depth() like you used and commented out for the floater 4 lines above.
 
Also it is crashing when attacking the bosses. This line of code doesn't seem to run but crashes the game:


Code:
with (other)
{
    floater = instance_create_depth(x+10, y-10, -1700, MuscleDamageIndicatorObject);
    hp_minus = irandom_range(5000, 9000);
    floater.text = string(hp_minus);
    hp = hp - hp_minus;
    instance_create(x, y, DeadBrainObject);
    hp -= 900000;
}
 

rIKmAN

Member
That code has the same problem I pointed out in my last post: instance_create() is not a GMS2 function.
 
Oh geez. How could I have missed that....lol. Really old code. GameMaker should flag that by now. How about the cursor problem?
 

rIKmAN

Member
Oh geez. How could I have missed that....lol. Really old code. GameMaker should flag that by now. How about the cursor problem?
Vanilla GMS2 does flag that - typing instance_create brings up the autocomplete for you to choose either the _depth or _layer variant of the function. It doesn't highlight instance_create as a function at all and it tokenizes as an instance variable, so if yours is highlighted as a function in the code editor then you must have either a script (pre v2.3) or function (v2.3+) somewhere named that - maybe a compatibility script or maybe your own but I'd recommend removing it, fixing all references to it and changing them to the proper native GMS2 functions to prevent you using it by mistake over and over.

No idea about the cursor.

My first guess based off you saying it disappears when other things get created in the room is that you might be setting draw_set_alpha() somewhere in those new instances and not restoring it before drawing your cursor sprite so it becomes invisible.

Next guess would be that it is being drawn behind things due to depth issues
Try drawing the cursor sprite on the Draw GUI layer and see if it suddenly appears.

Other than that it'd be the same advice you always get - use lots of debug messages and the debugger to step through your code line by line and zone in on when exactly the cursor disappears and what line of code is causing it.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Are you using the cursor_sprite variable or the window_set_cursor() function? Or is it an object? If it's an object, then check it in the debugger and see what depth it has, whether it's visible, whether it even exists, etc...
 
Use search and replace to make sure you get all the instance_create() stuff.


Also, among other things, the last line of that next piece of code makes no sense, you just set the hp 2 lines previously, and now you remove 900k from it...
Code:
with (other)
{
    floater = instance_create_depth(x+10, y-10, -1700, MuscleDamageIndicatorObject);
    hp_minus = irandom_range(5000, 9000);
    floater.text = string(hp_minus);
    hp = hp - hp_minus;
    instance_create(x, y, DeadBrainObject);
    hp -= 900000;
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, well, if I'm honest, I wouldn't be surprised if that function is bugged. It's a relic from GM7 or 8 and I honestly don't think anyone really uses it much. I'd consider filing a beg report about it and in the meantime use a dedicated cursor instance.
 

rIKmAN

Member
@Nocturne How do I go about using a dedicated cursor instance?
He means using an dedicated object which draws your cursor sprite to the mouse position every step - it'll become an instance when you drag it into a room.
Also turn off the regular cursor using window_set_cursor(cr_none) just in case it appears again at any point.
 
@rIKmAN @Nocturne
OK I'm using a dedicated object called MouseOBject to draw the cursosr and I've added it to every room.I"m using the following code:

GML:
draw_sprite_ext(Gauntlet, -1, mouse_x, mouse_y, 1, 1, 0, c_white, 1);
FYI I'm using the same object for every room.

For the menu room it works just fine. For the game rooms it is off by quite a bit. I hav ethe boxes that show up fo ran invisible grid called whtie cell objects. When you move the cursor over them, these
boxes shnow up. So before eveyrthing was lined up proprely. Now, when I go to click on my top bar the wrong bat gets put into play, and the white cell objects only show up when the cursor is essentially offscreen.
 
The code for the white cell object is pretty simple.

The white cells are directly placed ina grid, one cell at a time in a room.

Then they are turned on in a mouse enter event using visible = true;

and turned offf when they trigger the mouse leave event using visible = false

And they are set as visible false to start.
 
Why does this code not draw the sprite at the location of the mouse:

draw_sprite_ext(Gauntlet, -1, mouse_x, mouse_y, 1, 1, 0, c_white, 1);
 

rIKmAN

Member
@Nidoking Thank you so much. How do I get the Draw GUI coordinates?
You type "gui" into the manual and the first hit is device_mouse_x_to_gui() and there is a corresponding device_mouse_y_to_gui() which is linked at the bottom of the page for the "x" version of the function.

On the GUI layer, 0,0 is always the top left of the screen regardless of what position you may be within the room.
Be aware the the GUI layer can also be a different resolution than your game - see display_set_gui_size(), display_set_gui_maximise() to set the size and display_get_gui_width() and display_get_gui_height() to get the size.
 
Last edited:

Nidoking

Member
That depends on your camera settings for the room. Figure out where the corners of the camera view are in the room and work from there, taking display scaling into account.
 
Top