Mouse over, need help with last detail...

Started by Chomba, Sat 25/09/2021 08:38:29

Previous topic - Next topic

Chomba

Hello again!

Well, as I'm re-building my game (I went from 3.6.0 to 3.5.0) and I had to redo a lot of things, I realized that there are some things that I don't even remember how I managed to do them in the first place. Some others I was able to optimize and even improve  :-D

One of them is the function to change the mouse pointer while hovering over a hotspot or an object... I don't know how I did it before but it worked fine, I tried to track it down from the 3.6.0 project but I couldn't find it.
I remember it wasn't similar to how I'm doing it now either....

But it doesn't matter. The thing is that I found through the forums this way to handle the issue and it works quite well, there is only one detail (or 2, but only one is really important):

Code: ags
function repeatedly_execute()
{
   LocationType loc_type = GetLocationType(mouse.x, mouse.y);
   if (loc_type != eLocationNothing)
   {
     Mouse.SaveCursorUntilItLeaves();
     if (loc_type == eLocationHotspot)
     {
       Mouse.Mode = eModeInteract;
     }
     else if (loc_type == eLocationObject)
     {
       Mouse.Mode = eModeInteract;
     }
     else if (loc_type == eLocationCharacter)
      Mouse.Mode = eModeInteract;
   }
   else if (loc_type == eLocationNothing)
      Mouse.Mode = eModePointer;
}


My problem is that now when I select an inventory item, it no longer leaves the cursor that I have predefined for that situation, but it goes back to the "pointer" cursor.
I would need some way to create an exception so that if I have an item selected, it does not refresh the pointer or at least does not return it to "pointer". But I don't have much idea how to do it

Cassiebsg

Uhm... if (player.ActiveInventory!=null) return; // as in do nothing, guess break can also be used. (not sure which works best, or exactly difference in behavior).
Or you can  use if (player.ActiveInventory==null) and then your own code of ifs.
There are those who believe that life here began out there...

Chomba

Thanks for the help Cassie, but I don't quite understand how to use those functions you mention.... :P

Khris

This should do it:
Code: ags
function repeatedly_execute() {

  if (player.ActiveInventory) return; // exit function here

  LocationType loc_type = GetLocationType(mouse.x, mouse.y);
  if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
  else { 
    Mouse.SaveCursorUntilItLeaves();
    Mouse.Mode = eModeInteract;
  }
}

Chomba

Thanks Khris! It works great!  :grin: :grin: :grin:

so if I understood correctly, the lines would be doing something like this:

Code: ags
function repeatedly_execute() {
 
  if (player.ActiveInventory) return; // exit function here
 
  LocationType loc_type = GetLocationType(mouse.x, mouse.y);
//The one before tracks de mouse location on the screen.
  if (loc_type == eLocationNothing) Mouse.Mode = eModePointer;
//if the mouse is not on any point of interest (hotspot, object, character), then converts the cursor to pointer mode
  else 
//otherwise, if it's on top of any of that elements
{ 
    Mouse.SaveCursorUntilItLeaves();
    Mouse.Mode = eModeInteract;
//it uses the interact mode
  }
}


and I have configured a pointer from the general preferences for when an item is selected
I guess it is this line that allows that cursor to appear. Isn't it?
Quoteif (player.ActiveInventory) return; // exit function here

Khris

That if line simply prevents the rest of the code from running if the player has currently selected an inventory item.

Glad it's working :)

SMF spam blocked by CleanTalk