Author Topic: More cursor problems  (Read 376 times)

More cursor problems
« on: 03 Oct 2021, 04:36 »
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: Adventure Game Studio
  1. // called on every game cycle, except when the game is blocked
  2. function repeatedly_execute()
  3. {
  4.  if (player.ActiveInventory) return;
  5.  
  6.   LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  7.   if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  8.   else {
  9.     Mouse.SaveCursorUntilItLeaves();
  10.     Mouse.Mode = eModeInteract;
  11. }}

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: Adventure Game Studio
  1. // called on every game cycle, even when the game is blocked
  2. 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

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: More cursor problems
« Reply #1 on: 03 Oct 2021, 07:14 »
Try this:

Code: Adventure Game Studio
  1. // called on every game cycle, except when the game is blocked
  2. function repeatedly_execute()
  3. {
  4.   LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  5.   if (loc_type == eLocationNothing && player.ActiveInventory)  return;
  6.   else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  7.   else
  8.   {
  9.    Mouse.SaveCursorUntilItLeaves();
  10.    Mouse.Mode = eModeInteract;
  11.    }
  12. }
  13.  

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.
« Last Edit: 03 Oct 2021, 07:35 by Cassiebsg »
There are those who believe that life here began out there...

Re: More cursor problems
« Reply #2 on: 03 Oct 2021, 07:48 »
Thanks Cassiebsg, I´m getting this error

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

Code: Adventure Game Studio
  1. // called on every game cycle, except when the game is blocked
  2. function repeatedly_execute()
  3. {
  4.  LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  5.   if (loc_type == eLocationNothing && player.ActiveInventory)  return; // ← Error
  6.   else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  7.   else
  8.   {
  9.    Mouse.SaveCursorUntilItLeaves();
  10.    Mouse.Mode = eModeInteract;
  11.    }
  12. }

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: More cursor problems
« Reply #3 on: 03 Oct 2021, 12:22 »
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...

Re: More cursor problems
« Reply #4 on: 03 Oct 2021, 18:00 »
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

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: More cursor problems
« Reply #5 on: 03 Oct 2021, 18:07 »
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?
« Last Edit: 03 Oct 2021, 18:19 by Cassiebsg »
There are those who believe that life here began out there...

Re: More cursor problems
« Reply #6 on: 03 Oct 2021, 18:32 »
ummm... nope  :-[.
Let's see, this is what I get from the code as it stands:

Code: Adventure Game Studio
  1. function repeatedly_execute() // We know what this does.
  2. {
  3.    LocationType loc_type = GetLocationType(mouse.x, mouse.y); // This gets the information where the mouse is located on the screen.
  4.   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...
  5.   else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;         // put the cursor in pointer mode
  6.   else                                                                                                      // if not
  7.   {
  8.    Mouse.SaveCursorUntilItLeaves();                                                         // saves the cursor mode until the mouse leaves in...
  9.    Mouse.Mode = eModeInteract;                                                              // this mode (the yellow cursor)
  10.    }
  11. }

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: Adventure Game Studio
  1. {
  2.    LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  3.   if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  4.   else if (player.ActiveInventory!=null) Mouse.Mode = eModeUseinv; // ← This is the new line of code
  5.   else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  6.   else
  7.   {
  8.    Mouse.SaveCursorUntilItLeaves();
  9.    Mouse.Mode = eModeInteract;
  10.    }}

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: More cursor problems
« Reply #7 on: 04 Oct 2021, 17:17 »
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: Adventure Game Studio
  1.     {
  2.        LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  3.       if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  4.       else if (player.ActiveInventory!=null)
  5.       {
  6.          if (loc_type != eLocationNothing) Mouse.Mode = eModeInteract; // if mouse is over a location
  7.         else Mouse.Mode = eModeUseinv; // ← Moved after else
  8.       }
  9.       else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  10.       else
  11.       {
  12.        Mouse.SaveCursorUntilItLeaves();
  13.        Mouse.Mode = eModeInteract;
  14.        }
  15. }
  16.  

Hope it helps.   :)
« Last Edit: 04 Oct 2021, 17:19 by Cassiebsg »
There are those who believe that life here began out there...

Re: More cursor problems
« Reply #8 on: 04 Oct 2021, 17:38 »
Thanks Cassiebsg!

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

Code: Adventure Game Studio
  1. {
  2.        LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  3.       if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  4.       else if (player.ActiveInventory!=null)
  5.       {
  6.          if (loc_type != eLocationNothing) Mouse.Mode = eModeInteract; // if mouse is over a location
  7.         else Mouse.Mode = eModeUseinv; // ← Moved after else
  8.       }
  9.       else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  10.       else
  11.       {
  12.        Mouse.SaveCursorUntilItLeaves();
  13.        Mouse.Mode = eModeInteract;
  14.        }
  15. }

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: Adventure Game Studio
  1. {
  2.    LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  3.   if (loc_type == eLocationNothing && player.ActiveInventory!=null)  return;
  4.   else if (player.ActiveInventory!=null) Mouse.Mode = eModeUseinv; //
  5.   else if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  6. // 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
  7. // and somewhere there should be a command to return to the selected item if it is not over a point of interest.
  8.   else
  9.   {
  10.    Mouse.SaveCursorUntilItLeaves();
  11.    Mouse.Mode = eModeInteract;
  12.    }}

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: More cursor problems
« Reply #9 on: 04 Oct 2021, 19:56 »
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...