SOLVED object don't work right

Methudek

Member
If I create new object, my code
GML:
if (position_meeting(mouse_x, mouse_y, id)) {
    cursor_sprite = spr_cursor_find;
}
don't work on any object and at any room
 

FrostyCat

Redemption Seeker
Is that code in a Step event like it should be?

Is there other code also trying to set cursor_sprite?
 

Gamebot

Member
Does the objects in question have their own sprites and is the collision mask ( mask_index ) in your sprites the same size as your images.

The full code along with the events they belong wouldn't hurt to post either. So we can see exactly what is going on.
 

Alice

Darts addict
Forum Staff
Moderator
The last two objects (obj_sofa and obj_table_plant) have "cr_non"e passed to position_meeting instead of "id".
You really ought to drop that habit of using cr_none as an argument for collision check functions... ^^'
 

Prrz

Member
this all photos where is I used position_meeting to cursor
except for the first photo
First things first, Do not post screenshots or videos of your code.

Secondly as mentioned before, cr_none is a constant, check out this page in the manual for more cursor related constants. What that snippet is saying (with cr_none) is "if a collision has been found at the mouse_x and mouse_y position with... some constant value that never changes... then set the cursor sprite". The last argument in position_meeting() is obj: The object (or instance id, or the keywords "all" or "other") to check for a collision with. Cr_none is not an object, it is not a instance ID, and it is not a "special keyword" - it is some constant value set by GameMaker.

Third, something else must be going on here - calling position_meeting() in the step event like that should absolutely work as intended and change the cursor sprite. My best guess is that some other piece of code somewhere is trying to set the cursor sprite too, most likely every step.

Go to Windows -> Search Results and search for everything in your code that says "cursor_sprite". Press Shift + Control + F if the search window does not pop up at first - then just use the "search" feature and press "find all". This will list everywhere in your code that "cursor_sprite" appears and show it to you in the Search Results window.
 
Last edited:

Methudek

Member
First things first, Do not post screenshots or videos of your code.

Secondly as mentioned before, cr_none is a constant, check out this page in the manual for more cursor related constants. What that snippet is saying (with cr_none) is "if a collision has been found at the mouse_x and mouse_y position with... some constant value that never changes... then set the cursor sprite". The last argument in position_meeting() is obj: The object (or instance id, or the keywords "all" or "other") to check for a collision with. Cr_none is not an object, it is not a instance ID, and it is not a "special keyword" - it is some constant value set by GameMaker.

Third, something else must be going on here - calling position_meeting() in the step event like that should absolutely work as intended and change the cursor sprite. My best guess is that some other piece of code somewhere is trying to set the cursor sprite too, most likely every step.

Go to Windows -> Search Results and search for everything in your code that says "cursor_sprite". Press Shift + Control + F if the search window does not pop up at first - then just use the "search" feature and press "find all". This will list everywhere in your code that "cursor_sprite" appears and show it to you in the Search Results window.
is this right
GML:
cursor_sprite = spr_cursor;
window_set_cursor(cr_none);
 
Last edited:

FrostyCat

Redemption Seeker
is this right
GML:
cursor_sprite = spr_cursor;
window_set_cursor(cr_none);
If that is in your project and it is running the Step event, then no wonder your other attempts to set cursor_sprite also in the Step event are failing.

This is why I asked about other code trying to set cursor_sprite, and also why Prrz is saying this:
My best guess is that some other piece of code somewhere is trying to set the cursor sprite too, most likely every step.
When multiple sources are all constantly trying to set a single variable, only the one coming last will succeed, the others will fail by being overwritten. Educated developers know this is a classic race condition. In your case, that coveted variable is cursor_sprite, and the race is instance ordering. Any educated GM user knows how flimsy code can get when they become dependent on instance ordering.

You need to fix this race by changing the event for cursor_sprite = spr_cursor; to Begin Step. That way the special cursor sets in the Step events elsewhere will always win over it when they apply. And when none of them apply (i.e. the mouse is not over anything special), the default winner will come out to be the normal cursor.
 
Top