Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Scrungo on Mon 04/03/2024 21:20:10

Title: How to add custom verbs in the Sierra style?
Post by: Scrungo on Mon 04/03/2024 21:20:10
Hello, I have begun work on a new game, and most of my endeavors in the past were with Thumbleweed, so I am like a fish out of water in this Sierra environment.

I am wanting to add a few custom verbs for this game, not sure about all of them just yet, but one I have thought of is a "Sniff" verb, basically allowing the character to smell things (this isnt just useless flavor text, i have thought of several puzzle ideas for it, i do know excessive verbs like this get a bad rep). So far, I have created a little nose icon for the cursor, and the mouse detects it when scrolling through all of the cursor types, which is a good sign so far. However, when I click on anything with the Smell verb active, nothing happens!

I have the cursor named "Sniff", and the room code for a test is as follows:

function cEgo_Sniff()
{
Display("Smells like... Blueberries?");
}
and
function hGlowingOrb_Sniff()
{
Display("Smells a bit burnt...");
}

I cannot for the life of my find out where in the scripts verbs/actions are handled, so I cant even cross reference my new cursor with one that already works, like say "LookAt". Any help at ALL would be greatly appreciated, thank you so much!!!!
Title: Re: How to add custom verbs in the Sierra style?
Post by: Crimson Wizard on Tue 05/03/2024 11:41:39
Quote from: Scrungo on Mon 04/03/2024 21:20:10I cannot for the life of my find out where in the scripts verbs/actions are handled, so I cant even cross reference my new cursor with one that already works, like say "LookAt". Any help at ALL would be greatly appreciated, thank you so much!!!!

In AGS there's a built-in verb mechanic, but also you may script your own. Each template presents some starting idea, but it may be changed or expanded.

If you are using built-in verb mechanic, as in Sierra-style template, then for each verb in game there's a "cursor mode" and there's a "event" associated with that cursor. You can find the cursors under "Mouse cursors" in the project tree, and you may edit and add more.
You can see associated events on the event tab of each game object (except for GUI, which have their own events). Refer to this article in the manual, and check out the screenshots:
https://adventuregamestudio.github.io/ags-manual/acintro3.html
Especially this one:
https://adventuregamestudio.github.io/ags-manual/images/acintro3_02.png

As you may notice, there are 2 extra interactions there, called Usermode1 and Usermode2. These are 2 reserved events for custom actions. If you rename an existing cursor type, then these events will be renamed automatically.

The easiest way to connect a script function to the event is by pressing the "..." button after event's name. Then AGS will generate a function for you. If you have already wrote a function yourself, you may copy its name into the event's list. This will connect this function to event.

You may change existing cursors to your needs, or add more cursors, even beyond these 2 extras. But if you make even more cursors than that, I think that you will have to use "Any click" event, because AGS does not create more events. When in the script function you'll have to check for which cursor mode specifically that is.

Example:
Code (ags) Select
function oObject1_AnyClick()
{
    if (mouse.Mode == eModeSniff)
    {
    }
    else if (mouse.Mode == eModeBark)
    {
    }
}


Some templates, like Thumbleweed template for instance, actually use custom verb system, not connected with the AGS own system. AFAIK they lock the mouse cursor to some "pointer" or "interact" mode, and store the active "custom verb" in a variable to know which verb is currently activated. But that's a separate topic.
Title: Re: How to add custom verbs in the Sierra style?
Post by: Scrungo on Tue 05/03/2024 15:27:54
Thank you so much for your response!! I have a few follow up questions, but I think I am getting the hang of this.
Quote from: Crimson Wizard on Tue 05/03/2024 11:41:39As you may notice, there are 2 extra interactions there, called Usermode1 and Usermode2. These are 2 reserved events for custom actions. If you rename an existing cursor type, then these events will be renamed automatically.
So, before I had just created an entirely new cursor, and it wouldn't work. When I used your advice and made a carbon copy of the new cursor onto Usermode1, it worked, and showed up in the events of the hotspot! Does this mean I can only have two extra verbs? How can I get a newly created cursor to show up in events when I use up both Usermodes?

Secondly, when I sniff the walkable area hotspot, the game crashes with Error:
RunScriptFunction: error -18 ()trying to run 'hHotspot0_Mode8'  (Room 1)I have not defined Sniff to do anything when interacting with the walkable area, or defined it to interact with whatever 'hHotspot0' is, do I need to include something just so it doesn't crash like this? Is it because I have Standard Mode enabled on the edited Usermode1 cursor that I made into Sniff?

And lastly, the Sniff action still does not do anything when trying to use it on ego! I followed suit in the global script with this code:

function cEgo_Talk()
{ //this code isnt mine, but I am including it to show that this action works as intended when trying to talk to Ego...
  Display("Talking to yourself is a sign of madness!");
}

function cEgo_Sniff()
{ //And this is my code, which does not produce the same expected dialogue box as using the other actions on ego, and also sniffing the orb works, so I am not sure why this doesn't
  Display("Smells like... Blueberries?");
}

I even tried to use the code you provided, and attempted this:
function cEgo_AnyClick()
{
    if (mouse.Mode == eModeSniff)
    {
      Display("Smells like... Blueberries?");
    }
}
Which also did not work! What am I doing wrong?

And again, thank you so much for your help!! :D
Title: Re: How to add custom verbs in the Sierra style?
Post by: Crimson Wizard on Tue 05/03/2024 16:00:13
Quote from: Scrungo on Tue 05/03/2024 15:27:54Does this mean I can only have two extra verbs? How can I get a newly created cursor to show up in events when I use up both Usermodes?

You don't, like I mentioned, in the case of any more verbs you will have to use "AnyClick" event and check active mode using "mouse.Mode".

Quote from: Scrungo on Tue 05/03/2024 15:27:54Secondly, when I sniff the walkable area hotspot, the game crashes with Error:
RunScriptFunction: error -18 ()trying to run 'hHotspot0_Mode8'  (Room 1)

This error usually means that you have some function name inserted into events table of this given hotspot, but the actual function does not exist, so engine cannot run it.

Quote from: Scrungo on Tue 05/03/2024 15:27:54And lastly, the Sniff action still does not do anything when trying to use it on ego! I followed suit in the global script with this code:

Do you actually connect the functions in the events table, or just type them in the script?
Title: Re: How to add custom verbs in the Sierra style?
Post by: Scrungo on Tue 05/03/2024 17:37:39
Quote from: Crimson Wizard on Tue 05/03/2024 16:00:13This error usually means that you have some function name inserted into events table of this given hotspot, but the actual function does not exist, so engine cannot run it.
Oh my gosh, ok. I finally understand how events work, I guess it just wasn't clicking in my head until just now. I was able to stop that error, and also able to get the Sniff action to work with Ego after realizing this too, sorry for my ignorance ^^"

Quote from: Crimson Wizard on Tue 05/03/2024 16:00:13You don't, like I mentioned, in the case of any more verbs you will have to use "AnyClick" event and check active mode using "mouse.Mode".
So, I have tried this. I made a dummy cursor just to test having more cursors, and called it "Bark", inspired by your example in your first reply. However, when I use this code in the globalscript:
function cEgo_AnyClick()
{
    if (mouse.Mode == eModeSniff)
    {
      Display("Smells like... Blueberries?");
    }
    else if (mouse.Mode == eModeBark)
    {
      Display("Don't yap your mouth!");
    }
}
absolutely nothing happens.
The Sniff action will still work if I use the code I posted last time now that I have properly set up the event, but not when I try to use it using AnyClick. And like you said, AGS only supports events up to that 2nd usermode, so I cant just create an event in Ego with the Bark action. I feel like its super simple in the same way I misunderstood how events worked, but am just too ignorant.
You have been such a great wealth of knowledge, thank you so much for your time and for being patient with me!!
Title: Re: How to add custom verbs in the Sierra style?
Post by: Crimson Wizard on Tue 05/03/2024 17:49:01
Quote from: Scrungo on Tue 05/03/2024 17:37:39So, I have tried this. I made a dummy cursor just to test having more cursors, and called it "Bark", inspired by your example in your first reply. However, when I use this code in the globalscript:

 absolutely nothing happens.

The Sniff action will still work if I use the code I posted last time now that I have properly set up the event, but not when I try to use it using AnyClick.

To double check, have you put cEgo_AnyClick function to corresponding AnyClick event in the events table?
Title: Re: How to add custom verbs in the Sierra style?
Post by: Scrungo on Tue 05/03/2024 18:50:04
Quote from: Crimson Wizard on Tue 05/03/2024 17:49:01have you put cEgo_AnyClick function to corresponding AnyClick event in the events table?
Oh my gosh, you were right... I just overlooked the "AnyClick" event on Ego... My biggest problem with anything is that I always overlook the simplest of things!!!! Thank you so much for your time and wisdom!!! :D