More cursor problems

Started by Chomba, Sun 03/10/2021 04:36:59

Previous topic - Next topic

Chomba

Yes, it's me again.

I'm having this problem that I don't know how to solve:

I have a code made so that the cursor changes when the mouse is over a hotspot or object and returns to normal when it´s not (thanks Khris!).

GlobalScript.asc
Code: ags
// called on every game cycle, except when the game is blocked
function repeatedly_execute()
{
 if (player.ActiveInventory) return;
 
  LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  else { 
    Mouse.SaveCursorUntilItLeaves();
    Mouse.Mode = eModeInteract;
}}


But now I have this strange problem, where if I select an item and move the mouse quickly, the pointer of the selected item disappears and returns to the normal pointer even if the item is still selected.
Here I attach a video showing what happens:



Does anyone know how to solve this?

I tried changing the code to the section of
Code: ags
// called on every game cycle, even when the game is blocked
function repeatedly_execute_always()

but the same thing keeps happening

PS:
I tried it and tried to fix it for a while longer before posting (yes, I saved the message in case I couldn't solve it). I noticed that the cursor doesn't change only by the movement speed, sometimes it does it also by going slow, or even never changes to the item selection one.

Cassiebsg

#1
Try this:

Code: ags

// called on every game cycle, except when the game is blocked
function repeatedly_execute()
{
  LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing && player.ActiveInventory)  return;
  else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  else
  { 
   Mouse.SaveCursorUntilItLeaves();
   Mouse.Mode = eModeInteract;
   }
}


PS: I haven't tested it.
PS2: You might have to save the mouse.x and mouse.y before the GetLocationType check. As in: mouse.x=MouseX; and then use MouseX and MouseY in the check.
There are those who believe that life here began out there...

Chomba

Thanks Cassiebsg, I´m getting this error

Type mismatch: cannot convert "int" to "inventory item" in this line:

Code: ags
// called on every game cycle, except when the game is blocked
function repeatedly_execute()
{
 LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing && player.ActiveInventory)  return; // ← Error
  else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  else
  { 
   Mouse.SaveCursorUntilItLeaves();
   Mouse.Mode = eModeInteract;
   }
}

Cassiebsg

Uhm, try changing player.ActiveInventory to player.ActiveInventory!=null.

But I think there's still a logic fail in here. (unless the cursor is meant to change when there's an active inventory item and a location?).
There are those who believe that life here began out there...

Chomba

Well, I made the change and it worked to some extent.

The pointers change well, except that now the hotspot pointer also works even if an item is selected (in my case, it turns red when you select an item and yellow when you are over a hotspot or object. Now even if it is red, it also turns yellow when you are over the hotspots and turns back to red when it is not). But this doesn't bother me, maybe it's even better.

The issue is that sometimes with an item selected (and only in that condition) the pointer gets stuck in yellow after passing over a hotspot or object.

Cassiebsg

#5
I would have to test the code, as I'm one that codes by trial and error.

If you read the conditions out loud to your self, they'll make sense and will help you code them as you want them to react.

Try commenting this line out:    Mouse.SaveCursorUntilItLeaves();

Does it help?

Otherwise you might want to get the player.ActiveInventory!=null check inside the loc_type == eLocationNothing by in self.
In other words, you have LocationType line 1st, then check if (loc_type == eLocationNothing and then check if ( player.ActiveInventory).

I'm use to be able to see the cursor hold the active inventory sprite, not just a color change. So unless you specify exactly how the cursor should work it's hard to figure the correct code for me (I just don't have the needed experience). Maybe Khris or CW will answer and give a better code that does exactly what you want.

PS: After reading your "problem" I can think that you do not want to use return; and maybe set it to your inventory cursor mode instead?
There are those who believe that life here began out there...

Chomba

ummm... nope  :-[.
Let's see, this is what I get from the code as it stands:

Code: ags
function repeatedly_execute() // We know what this does.
{
   LocationType loc_type = GetLocationType(mouse.x, mouse.y); // This gets the information where the mouse is located on the screen.
  if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return; // If you are not over a point of interest and you have an element selected, return to...
  else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;         // put the cursor in pointer mode
  else                                                                                                      // if not
  { 
   Mouse.SaveCursorUntilItLeaves();                                                         // saves the cursor mode until the mouse leaves in...
   Mouse.Mode = eModeInteract;                                                              // this mode (the yellow cursor)
   }
}


So I thought of adding a line to clarify that if an item is selected, the pointer is in "selected item" mode.

Apparently it worked! it no longer turns yellow when there is a selected item and you go over a point of interest (which I kind of liked), but it seems to work!

The code is like this (let's see what you think, if it can generate some kind of problems):

Code: ags
{
   LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  else if (player.ActiveInventory!=null) Mouse.Mode = eModeUseinv; // ← This is the new line of code
  else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  else
  { 
   Mouse.SaveCursorUntilItLeaves();
   Mouse.Mode = eModeInteract;
   }}


Cassiebsg

#7
Yup, that's what I meant in my PS above.  (nod)

If you want the cursor to change when above an intractable hotspot/object, you just need a bit of a tweek:

Code: ags

    {
       LocationType loc_type = GetLocationType(mouse.x, mouse.y);
      if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
      else if (player.ActiveInventory!=null) 
      {
         if (loc_type != eLocationNothing) Mouse.Mode = eModeInteract; // if mouse is over a location
        else Mouse.Mode = eModeUseinv; // ← Moved after else
      }
      else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
      else
      { 
       Mouse.SaveCursorUntilItLeaves();
       Mouse.Mode = eModeInteract;
       }
}


Hope it helps.   :)
There are those who believe that life here began out there...

Chomba

Thanks Cassiebsg!

QuoteYup, that's what I meant in my PS above.
Well, it worked  :grin:.

Code: ags
{
       LocationType loc_type = GetLocationType(mouse.x, mouse.y);
      if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
      else if (player.ActiveInventory!=null) 
      {
         if (loc_type != eLocationNothing) Mouse.Mode = eModeInteract; // if mouse is over a location
        else Mouse.Mode = eModeUseinv; // ← Moved after else
      }
      else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
      else
      { 
       Mouse.SaveCursorUntilItLeaves();
       Mouse.Mode = eModeInteract;
       }
}


This one didn't quite work out. The yellow pointer over the points of interest and turning red when selecting an item works. But when I pass with a selected item over an object, the pointer turns yellow and stays that way.


What I would like to achieve now (with the code I was able to come up with, which so far seems to be the one that gave me the best answer to the situation of the pointers "dropping") is that when I have an item selected and pass over a point of interest, the cursor changes to usermode2.

I don't know if the logic is right, I made some try and error but nothing came out of it.

Code: ags
{
   LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  else if (player.ActiveInventory!=null) Mouse.Mode = eModeUseinv; // 
  else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
// I guess there should be a command here that says that if I have an item selected and I pass over a point of interest, the pointer changes to usermode2
// and somewhere there should be a command to return to the selected item if it is not over a point of interest.
  else
  { 
   Mouse.SaveCursorUntilItLeaves();
   Mouse.Mode = eModeInteract;
   }}

Cassiebsg

I need to go sleep, but I still don't think you need this line at all Mouse.SaveCursorUntilItLeaves();, you are already checking for mouse changes 40 times a second. So it seems redundant (to me anyway).

There are those who believe that life here began out there...

SMF spam blocked by CleanTalk