Unhandled event not working

Started by Raider, Mon 01/05/2006 10:54:41

Previous topic - Next topic

Raider

Okay so I have my unhandled event working for my items that don't 'combine' with other items. If i have two items that combine for example a bottle and cork. They go together to make a plugged bottle. The problem is if I use any other object with either the cork or the bottle nothing is displayed. I have searched the manual and the forums for this solution but can't find it. I hope I have explained in full. How do I get the game to display "I can't use these things together." when say the cork is used with another object.

Ashen

IIRC, unhandled_event won't be called for an interaction that has any conditions - so if there's script for using item 2 on an item, using item 3 doesn't count as 'unhandled'. The (slightly longwinded) solution is to manually tell the script to run unhandled_event when needed, e.g.:
Code: ags

if (player.ActiveInventory == iKey) {
  // Do stuff
}
else if (player.ActiveInventory == iChicken) {
  // Do other stuff
}
else unhandled_event(5,3); // 'Use inv on inv', for any other item.


I don't think there's a simpler way, sorry.
I know what you're thinking ... Don't think that.

Raider


Raider

Ah okay I used that code and it says "i Active inventory is not a member of 'gameCharacter'
was that code that you posted just a sample or what? 

Gilbert

Did you type that in correctly? It should be:

ActiveInventory

with capital A and I but NO space.

If you're not at all sure, just rely on the auto-completion feature of teh script editor.

Raider

No I have copied the code straight from Ashen's post. It does not seem to work and the error keeps coming up. What about using "while" statements?

Gilbert

So, did you check if there's a error in the code? you may also try erasing the "ActiveInventory" part of the code and type in the first few characters (like "activ") to make the editor auto-complete it for you.

Lastly, what version of AGS are you using? The ActiveInventory character property won't work unless you're using V2.7 or later.

Raider

V2.61

okay what about the "GetProperty" statements? And the property box?

Gilbert

If you're using V2.61, try the following instead:
Code: ags

if (character[GetPlayerCharacter()].activeinv == 5) {
Ã,  // Do stuff
}
else if (character[GetPlayerCharacter()].activeinv == 6) {
Ã,  // Do other stuff
}
else unhandled_event(5,3); // 'Use inv on inv', for any other item.

(Substitute, the 5 and 6 in the code with the item numbers of the appropiate items)

Quote from: Rahvin on Tue 02/05/2006 09:06:02
okay what about the "GetProperty" statements? And the property box?

Pardon ???

Raider

Okay thanks heaps.
Ignore what I said, I was wrong.  :P

Raider

I apologise for being annoying...
But how do you go about displaying a message if two items don't work together? ???

Ashen

#11
Code: ags

Display("They don't work together.");

?

How do you mean?
In that manual, look up the game. variables and looks for something like game.inv_activated (I'm fairly certain this was still the same in V2.61, but best to be sure).

Then do something like:
Code: ags

Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);


Or if you meant something else, can you be more specific?
I know what you're thinking ... Don't think that.

Raider

What I mean is: do I have to enter in a code for each combination of items being used together.
For example if "use" cork with knife, I want it to display "that doesn't work"
Do I have to type in:

Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);\

Then if i "use" the bread with the flag do I have to put that code in again but with different variables?
It's hard to explain  :-\

Khris

Add this in the global script:
Code: ags
function unhandled_event (int what, int type) {
Ã,  if (what==5) {Ã,  Ã,  // inventory interaction
Ã,  Ã,  if (type==3) {Ã,  Ã, // used inv
Ã,  Ã,  Ã,  Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);
Ã,  Ã,  }
Ã,  }
}


Explanation:
After the player uses item A on item B, AGS does the following:

-character[GetPlayerCharacter()].activeinv is already A
-game.inv_activated is set to B
-if it exists, B's use inv on inv-interaction is called, else unhandled_event(5,3) is called

Raider

yes that works to some degree but if I use say an item that has no commands in the interaction window, like a "book" with the cork which does have commands in the interaction window (cork with bottle) then it doesn't count as an unhandled event. When I test my game and i use book on mast it displays nothing but if i use the mast on the book, it displays the message I want.
Is there any way I can display the message "that doesn't work" for every combination of items I have without doing writing a code for each one?

Ashen

Quote from: Ashen on Mon 01/05/2006 11:58:04
IIRC, unhandled_event won't be called for an interaction that has any conditions - so if there's script for using item 2 on an item, using item 3 doesn't count as 'unhandled'. The (slightly longwinded) solution is to manually tell the script to run unhandled_event when needed, e.g.:

(code removed)

I don't think there's a simpler way, sorry.

Does this not work? You don't have to specify the actual interaction (Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);) for each item, but if there's ANY code in the 'Use inventory on' interaction then yes, you do have to write a code for each - but it's just a case of copy-pasting else unhandled_event(5,3); at the bottom.
I know what you're thinking ... Don't think that.

Raider

No that code that was given did not work.
Neither does (Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);)

Unless I am putting them in the wrong place? Im putting them in the unhandled event section of the global script.

SSH

You will also need to put the code in the ELSE clause of each of your object interactions:

if (used cork with bottle) {
Ã,  // Do something meaningful
} else {
Ã,  Display ("I can't use %s with %s.", character[GetPlayerCharacter()].activeinv, game.inv_activated);
}
12

Ashen

#18
Sorry, you're right, the code exactly as given won't work. character[GetPlayerCharacter()].activeinv and game.inv_activated are ints not strings, the number of the items used, not their names. Not sure how I missed that one - but it should've given you an error message, rather than just not working. You'll need to look up the usage for GetInvName (I don't have a copy of the 2.61 manual, so I'll have to guess), then try:
Code: ags

string UsedInv, UsedOn;
GetInvName (character[GetPlayerCharacter()].activeinv, UsedInv); // Check the usage before trying this
GetInvName (game.inv_activated, UsedOn); // Or whatever the correct usage is
Display ("I can't use %s with %s.", UsedInv, UsedOn);


Now, if that was the problem you should be sorted - I've used the code more or less as KhrisMUC posted it in the past and it works fine. If not, can you be more specific about what it is/isn't doing that's wrong?

(And you shouldn't really need to put it in the interaction for every item, provided the else unhandled_event (5,3); line is there.)
I know what you're thinking ... Don't think that.

Raider

No that didn't work either.
What is happening is if I "use" cork on map. It doesn't my character display anything, he doesn't say what I have written in the script. It just goes back to normal playing as if nothing happend.
In all adventure games if you use two items that don't work together the character will say "That doesn't work" (or somthing along those lines)
Now I have put in the codes you suggested and when I use two items together that don't work my character doesn't say anything, nothing happens in the game.
Is that explained well enough?  :-\

SMF spam blocked by CleanTalk