Changing the verb when mouse moves over hotspot (SOLVED)

Started by lapsking, Sun 14/08/2022 04:11:42

Previous topic - Next topic

lapsking

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
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
the Thing is in the process, and mostly gone when it's done.

Khris

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?

lapsking

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.
the Thing is in the process, and mostly gone when it's done.

Khris

 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.

lapsking

#4
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:


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?
the Thing is in the process, and mostly gone when it's done.

Khris

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
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
    // 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)

lapsking

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.
the Thing is in the process, and mostly gone when it's done.

lapsking

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.
the Thing is in the process, and mostly gone when it's done.

Khris

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.

lapsking

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?
the Thing is in the process, and mostly gone when it's done.

Khris

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.

lapsking

#11
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:

The player selected "Use KeyCard with"


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.
the Thing is in the process, and mostly gone when it's done.

lapsking

#12
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:

Code: ags
    // 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.
the Thing is in the process, and mostly gone when it's done.

Khris

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

lapsking

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:

Code: ags
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:

Code: ags
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:

Code: ags
    // 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.
the Thing is in the process, and mostly gone when it's done.

SMF spam blocked by CleanTalk