Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lapsking on Sun 14/08/2022 04:11:42

Title: Changing the verb when mouse moves over hotspot (SOLVED)
Post by: lapsking on Sun 14/08/2022 04:11:42
Hi, a basic question from a below basic coder. I'm using AGS 3.5.1 Tumbleweed template. All I want is to change cursor mode when mouse moves over hotspot. I have found the code in manual and forum I guess:
Code (ags) Select
function hCastle_MouseMove()
{
    Mouse.SaveCursorUntilItLeaves();
    Mouse.Mode = eModeWalkto;
}

And I've set the hotspot Event for Mouse moves over hotspot, but still when mouse moves over hotspot my cursor remains default which is eModeLookat. Sorry for such a silly question but what am I missing?

Any help would be appreciated
Title: Re: Mouse mode doesn't change over hotspot
Post by: Khris on Sun 14/08/2022 17:05:08
All cursor modes use the same crosshair sprite. Your code works but you can't see the change of cursor mode. Unless you have assigned a different sprite to the walkTo mode?

The more important question is, what do you want to achieve? The Tumbleweed template doesn't really use different cursor modes (like the Sierra games / template), everything is based on the activated verb.

Do you want to show an exit arrow or something like that?
Title: Re: Mouse mode doesn't change over hotspot
Post by: lapsking on Sun 14/08/2022 18:01:03
Thanks for your reply Khris. I don't need the sprite of cursor to  change. I just want Look At in action bar/status bar to change to Walk To when mouse moves over hotspot so with a click the player can change room. I'm making a first person point and click adventure game, that's why I changed default to Look At instead of Walk To since there is no player on screen to walk anywhere, but still I want the action bar/status bar  tochange to Walk To on specific hotspots for exit and changing room. I hope it makes sense.
Title: Re: Mouse mode doesn't change over hotspot
Post by: Khris on Sun 14/08/2022 21:00:01
 I see, you don't need to mess with cursor modes for that.
Simply append  >er  to the name of the hotspot. That's an exit to the right. Use el, eu, ed for the other three directions.
You can also read about this in the PDF that comes with the template in the "Exit Extensions" section.
Title: Re: Mouse mode doesn't change over hotspot
Post by: lapsking on Mon 15/08/2022 05:35:58
Hi Khris, thanks, but I've tried that >e extension after hotspot name and still the action bar remains "Look at" when mouse moves over hotspot and doesn't change to "Walk to" as you can see in the picture:
(http://www.lapsking.com/example.jpg)

Maybe because I changed the default to "Look at" instead of "Walk to"? But I want the default to be "Look at". I just want when mouse hovers on Castle hotspot, whatever verb the player has activated to be forced to change to "Walk to" and left clicking on hotspot trigger what "Walk to " verb was defined to do. I also want when mouse leaves hotspot to change back to whatever verb it was selected before moving on hotspot. Is that possible?
Title: Re: Mouse mode doesn't change over hotspot
Post by: Khris on Mon 15/08/2022 11:30:12
That means you want to fundamentally change how the template works, so you need to edit its script accordingly, not do this on a per-hotspot basis.
Also, the template doesn't really use the different cursor modes but stores the selected verb.

I gave it a try and it seems to work, but no guarantees wrt side-effects later:

1. open Scripts/Tumbleweed/Edit Script and scroll all the way down to line 2495

2. directly above the repeatedly_execute function you will find, add:
Code (ags) Select
bool was_hovering_exit = false;
Action prev_action;


3. inside the function there's a main block checking  !IsGamePaused() && !Verbs.IsGuiDisabled(). Directly inside this block, add
Code (ags) Select
    // walk to exit hotspots
    bool is_hovering_exit = Verbs.ExtensionEx(1,  verbsData.location_ex) == 'e';
    if (is_hovering_exit && !was_hovering_exit) {
      prev_action = verbsData.global_action;
      verbsData.global_action = eGA_WalkTo;
    }
    else if (!is_hovering_exit && was_hovering_exit) {
      verbsData.global_action = prev_action;
    }
    was_hovering_exit = is_hovering_exit;

(note the indentation, the above is indented by 4 spaces because it's two blocks in: the function itself and the if block inside)
Title: Re: Mouse mode doesn't change over hotspot
Post by: lapsking on Mon 15/08/2022 13:13:02
You are so brilliant. The understanding of the script is beyond my knowledge   ???, but it's working smoothly (nod). I'm sorry to say that but we might see each other again soon (laugh). Thank you so much Khris.
Title: Re: Changing the verb when mouse moves over hotspot (solved)
Post by: lapsking on Thu 22/12/2022 10:40:22
Hi again, it's working great but with a little glitch which I just realized now. If the player is selecting an inventory item with Use/Give and moves the cursor on exit hotspot still the action bar text updates to Walk To but clicking doesn't do anything. Is it possible to solve this issue too? Thanks.
Title: Re: Changing the verb when mouse moves over hotspot
Post by: Khris on Thu 22/12/2022 16:48:02
I'm afraid I can't reproduce this: I opened the game where I tested the above code and gave it a try and leaving the room via clicking the hotspot did work for me fine, both for Use and Give.
Not sure what's different with your game.
Title: Re: Changing the verb when mouse moves over hotspot
Post by: lapsking on Thu 22/12/2022 18:13:44
Hi Khris, I can change room both with use and give too. But it doesn't work with use and give after selecting an item, I mean when an item is selected with use and give verbs. "Use X with" or "Give x to". The action bar changes to "Walk To" but clicking doesn't do anything. Have you tried that too with using an inventory item on exit?
Title: Re: Changing the verb when mouse moves over hotspot
Post by: Khris on Thu 22/12/2022 22:18:02
Yes, that's what I tried and it worked. As it should I believe, because my code changes the internally used action, which is the one that is checked when you click on an exit. I don't know why it doesn't work for you.

Here's my VerbGUI.asc: https://pastebin.com/wFYFx9hz
Try replacing yours with mine, that's the only thing I can think of.
Title: Re: Changing the verb when mouse moves over hotspot
Post by: lapsking on Fri 23/12/2022 05:59:45
It has nothing to do with my game, because I even started a new game both with AGS 3.5.1 and AGS 3.6 with Tumbleweed template and copy pasted your VerbGUI.asc but still doesn't change room with left click with "Use item with" or "Give item to". As you can see in pictures:
(https://lapsking.com/wp-content/uploads/2022/12/test1.jpg)
The player selected "Use KeyCard with"

(https://lapsking.com/wp-content/uploads/2022/12/test2.jpg)
As mouse hovers on exit hotspot action bar changes to Walk To but left clicking doesn't do anything.

As you see it has nothing to do with my game, it must have something to do with when an item is selected/active with Use or Give verbs blocking running any script for the hotspot.
Title: Re: Changing the verb when mouse moves over hotspot
Post by: lapsking on Fri 23/12/2022 06:48:42
Okay Khris, I got somewhere. if I add "player.ActiveInventory = null" to your script then it works. As I thought active inventory is blocking hotspot script. But now the problem is when mouse leaves hotspot activeinventory is not saved. Is it a way to save active inventory before hovering on hotspot, then make it null, and when left hotspot make the same saved inventory item active? Just like what you did with verbs.

Edit: Okay, I think I sorted it out. Made a GlobalVariable InventoryItem* called invitem and added this to your script:

    // walk to exit hotspots
    bool is_hovering_exit = Verbs.ExtensionEx(1,  verbsData.location_ex) == 'e';
    if (is_hovering_exit && !was_hovering_exit) {
      prev_action = verbsData.global_action;
      invitem = player.ActiveInventory;
      player.ActiveInventory = null;
      verbsData.global_action = eGA_WalkTo;
      mouse.ChangeModeGraphic(mouse.Mode, 279);
    }
    else if (!is_hovering_exit && was_hovering_exit) {
      verbsData.global_action = prev_action;
      mouse.ChangeModeGraphic(mouse.Mode, 220);
      player.ActiveInventory = invitem;
    }
    was_hovering_exit = is_hovering_exit;

Edit: Code fixed.

Thank you again Khris.
Title: Re: Changing the verb when mouse moves over hotspot
Post by: Khris on Fri 23/12/2022 08:38:03
Glad you fixed it!
I can also reproduce this issue now; I added a new exit and the same thing happened for me. The existing exit still works without the fix though.

The reason was that I still had the code from your first post in my game, so clicking my exit happened with a cursor changed to eModeWalkTo.  :P
Title: Re: Changing the verb when mouse moves over hotspot (SOLVED)
Post by: lapsking on Mon 18/03/2024 21:44:20
Okay, don't laugh, but after a year and half I'm getting somewhere with this piece of script. The codes above will cause a glitch with whether use/useinvitem or other verbs after cursor leaves exit hotspot. So hopefully this one will go smoothly.

1. in room script:

function hCastle_MouseMove()
{
 Mouse.SaveCursorUntilItLeaves();
 Mouse.Mode = eModeWalkto;
 mouse.ChangeModeGraphic(mouse.Mode, 279);
}

2. open Scripts/Tumbleweed/Edit Script and scroll all the way down to line 2495

3. directly above the repeatedly_execute function you will find, add:

bool was_hovering_exit = false;
Action prev_action;

4.  inside the function there's a main block checking  !IsGamePaused() && !Verbs.IsGuiDisabled(). Directly inside this block, add:

    // walk to exit hotspots
    bool is_hovering_exit = Verbs.ExtensionEx(1,  verbsData.location_ex) == 'e';
    if (is_hovering_exit && !was_hovering_exit) {
      prev_action = verbsData.global_action;
      verbsData.global_action = eGA_WalkTo;
    }
    else if (!is_hovering_exit && was_hovering_exit) {
      verbsData.global_action = prev_action;
      mouse.ChangeModeGraphic(mouse.Mode, 220);
    }
    was_hovering_exit = is_hovering_exit;

That's how a blind man finds a needle in a sack of hay, by turning each hay upside down one by one. Hope I won't find another issue with it later.