What do you do if you want your character to say "That doesn't work" when using two items together that don't do anything?
(Without having to put in the command for absolutely every different object/item/character combination).
The unhandled_event function is called everytime you do something for which you haven't defined an interaction:
// main global script
function unhandled_event(int what, int type) {
if (what == 5) { // if clicked on an inventory item
if (type == 3) { // if inv item cursor mode used
DisplaySpeech(GetPlayerCharacter(), "That doesn't work.");
}
}
}
Check the manual for all number combinations you can use.
Thanks, but where do you put the code?
....Dont worry, I've done it now.
From AGS editor, click on "Inventory items".
Click on item you want to add message for (let's say for example, inventory item 3).
Click on the "Interaction" button.
From the option that should appear, right-click on the:
"Use inventory on this item" option, then select "New action...".
From the Drop-Down list select "Run script", and then from the Script Configuration box that appears, click on the "Edit script" button.
The script for that option will now open up so you can edit it.
To the script, now add in the following line:
Display("That doesn't work.");
Then from the Script Editor top menu, click on "File" then choose "Exit and save changes", then on the script Configuration box, click on the "OK" button.
That should do it.
If you wanted the display message to appear in one of the characters speech or have a character activate his "Talking view" then you might use script command of:
DisplaySpeech(EGO,"That doesn't work.");
Ã, Of course "EGO" could be replaced with whatever your character's script name is you want to have speak, and you can enter in whatever message you want.
Good luck.
** Edit --- Just in case you WANTED two different items to do something when used together, then, you would need to enter in the commands for that choice.. SO, for example, let's say still using inventory item 3 as an example, then from AGS editor and "Inventory items". If there's already commands entered under "Use inventory on this item" options added, then, on the most top option, right-click on it and select "Add action before this", then from drop down menu select "Conditional - If inventory item was used" then click "Change" button to select what inventory number, example, item 1, you would type in "1" in the value field, then OK, then on the new action created (By default it's "Do nothing", right click on that and choose "Run Script" (or whatever option you'd like to happen), then you can program into the script like: Display("Hey, that worked!");
Or whatever... :P
hogie:
Put strazer's code anywhere in the global script (Ctrl-G to open), provided it's not in another function.
As a personal preference, I'd add a little variation with a Random (x) command, e.g.:
function unhandled_event(int what, int type) {
if (what == 5) { // if clicked on an inventory item
if (type == 3) { // if inv item cursor mode used
int resp = Random (2);
if (resp == 0) DisplaySpeech(GetPlayerCharacter(), "That doesn't work.");
else if (resp ==1) DisplaySpeech(GetPlayerCharacter(), "They don't go together.");
else if (resp == 2) DisplaySpeech(GetPlayerCharacter(), "I can't use this like that.");
}
}
}
(Only, less boring.)
Barbarian:
Quote(Without having to put in the command for absolutely every different object/item/character combination).
hogie, or click menu "Script" -> "unhandled_event". This takes you directly to the function within the global script if it is already present.
Edit: I see you have worked it out. Good job.
Thanks, that's all worked fine.
New problem:
What is the script for combining items with objects and/or characters that are "unhandled events".?
function unhandled_event(int what, int type) {
if (what == 5) { // if clicked on an inventory item
if (type == 3) { // if inv item cursor mode used
int resp = Random (2);
if (resp == 0) DisplaySpeech(GetPlayerCharacter(), "That doesn't work.");
else if (resp ==1) DisplaySpeech(GetPlayerCharacter(), "They don't go together.");
else if (resp == 2) DisplaySpeech(GetPlayerCharacter(), "I can't use this like that.");
}
}
else if (what == 3) { // characters
if (type == 3) { // inv item cursor mode
int resp = Random (2);
if (resp == 0) DisplaySpeech(GetPlayerCharacter(), "I won't give that away.");
else if (resp ==1) DisplaySpeech(GetPlayerCharacter(), "I don't think that would be appreciated.");
else if (resp == 2) DisplaySpeech(GetPlayerCharacter(), "No, I might need it later.");
}
}
// else if (what == 2) { // objects
// ...
}
Quote from: strazer
Check the manual for all number combinations you can use.
I get it now.
Thanks!
What about unhandled_event interaction with hotspots?
http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm
if (what == 1) {
That's what I thought
I typed in this; but nothing happens in game.:
else if (what == 1) { // hotspot interact
if (type == 2) { // inv item cursor mode
int resp = Random (1);
if (resp == 0) DisplaySpeech(GetPlayerCharacter(), "I don't need that.");
else if (resp ==1) DisplaySpeech(GetPlayerCharacter(), "Why would I want one?");
}
}
}
Keep in mind that the unhandled_event function isn't called if you have defined an interaction for "Any click" on the hotspot since AGS can't know which cursor mode you might check in there.
Sorry, I don't get it...?
Freydal is speaking for Freydall because I can't be bothered to log in and Freydall is speaking for hogie who isn't here right now...
Don't worry, all fixed. We were just being lazy. There were only a couple of hotspots that needed messages and I have dealt with them.
Prob. Solved!
OK how would we adjust this for looking at hotspots for example.
Looking at a monkey (hotspot name monkey) wold return thats a monkey (changing monkey to be whatever the hotpot name is)
if (what == 1) {//Hotspot
if (type == 1) { // Look at
string name;
GetHotspotName (GetHotspotAt(mouse.x, mouse.y), name);
DisplaySpeech(EGO, "That's a %s.", name);
}
}
Or
if (what == 1) {//Hotspot
if (type == 1) { // Look at
string name;
Hotspot *theHot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
theHot.GetName (name);
cEgo.Say ("It's a %s.", name);
}
}
Depending on how the rest of your game works, it might be better to add the a/an/some to the hotspot name ('a monkey', 'an apple', 'some wires' instead of 'monkey', 'apple', 'wires') rather than the display command ("That's %s.", not "That's a %s."), so you don't get things like "It's a wires" or "It's a apple."
EDIT: Corrected GetHotspotName (mouse.x, mouse.y, name); to GetHotspotName (GetHotspotAt(mouse.x, mouse.y), name);
I suppose I could always break apart the string of the hotspot name, if it begins with a vowel use AN, if it ends with an S use some else use A. Does AGS have a function to break apart names into characters and get the string length so we can find the beginning and end?
There's StrLen() and StrGetCharAt(). So:
if (what == 1) {//Hotspot
if (type == 1) { // Look at
string name;
GetHotspotName (GetHotspotAt(mouse.x, mouse.y), name);
int str = StrLen (name); // first letter = 0, last = length-1
if (StrGetCharAt (name, str-1) == 's') DisplaySpeech (EGO, "It's some %s.", name) ; // Last letter is S
else if (StrGetCharAt (name, 0) == 'a'|| StrGetCharAt (name, 0) == 'e' || StrGetCharAt (name, 0) == 'i' || StrGetCharAt (name, 0) == 'o' || StrGetCharAt (name, 0) == 'u') DisplaySpeech (EGO, "It's an %s.", name); // First letter is a vowel
else DisplaySpeech(EGO, "That's a %s.", name);
}
}
There might be a simlper way than that long if (a or e or i or o or U) line, though.
EDIT: Corrected GetHotspotName (mouse.x, mouse.y, name); to GetHotspotName (GetHotspotAt(mouse.x, mouse.y), name);
yea, cool, thats pretty much what I had in mind, although there may be a rare chance where something will end in an S and not be plural, such as refering to a character called James, this can be overcome by simply manually editing the look script, rather than leaving it up to an unhandled event.
Edit - I keep getting an error, String with non-string on this line:
GetHotspotName (mouse.x, mouse.y, name);
any suggestions?
Yes, change it to GetHotspotName (GetHotspotAt(mouse.x, mouse.y), name).
Sorry, I typed it on the fly, then corrected it in AGS, but forgot to change my post. Can't believe I didn't spot that.
Also, characters would be handled by a different bit of the unhandled_event script anyway, wouldn't they? So you could set that up however you wanted. E.g.
if (what == 3 ) { // Characters
if (type == 0) { /Look at
DisplaySpeech (EGO, That person is called %s.", character[GetCharacterAt(mouse.x, mouse.y)].name);
}
}
But, yeah, for individual hotspots (and objects, inventory items, etc) ending in 's', you'd probably have to script the response manually.
Cheers, I may compile this into a small little tutorial for my site.
EDIT - Also anyone else planning on using this, you have to include upper and lower-case vowels as it will be case sensitive.