Unhandled event not working

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

Previous topic - Next topic

Ashen

It's explained OK, but it still doesn't make sense - the code should work, it's worked in the past, and it's strange that it doesn't work for you. Does it work if yu do what SSH suggested, and have the 'You can't use X on Y' message in the item script?

Can you post your code (unhandled_event and an item or two should do)?
I know what you're thinking ... Don't think that.

Raider

Okay this is my unhandled_event code
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);
    }
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);
unhandled_event(5,3); // 'Use inv on inv', for any other item.
  }
}



What did you mean about posting the items? Did you mean to post the interactions or just list them or what?

SSH

Unhandled event only runs when there is no interaction, Rahvin. If there is an interaction, you must put an ELSE clause in your if statements to display"That doesn't work" for cases where the wrong object is used. This needs to be done in EVERY inventory item interaction that you have already set up. You don't need to create new interactiosn, though.
12

Raider

Okay I think I'm beginning to understand now, sorry i've been a bit slow.
Just to make it clear, what do I write exactly and where? Could you just tell me the coding for it and tell me where I put the coding?
Thanks, a lot for your patience guys.

Ashen

The unhandled_event can probably stay where it is, but needs to look like:
Code: ags
function unhandled_event (int what, int type) {
  if (what==5) {    // inventory interaction
    if (type==3) {   // used inv
      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);
    }
  }
}

(Note: It'll need to be BEFORE the inventory item functions in the Global Script, for the next bit to work.)

Then, at the end of the interaction scripts for items which have can be used with other items add:
Code: ags

else unhandled_event(5,3);

So, if the bottle is item 4 and the cork is item 6, you'd have something like:
Code: ags

  // script for Inventory item 4 (Bottle): Use inventory on this item
if (character[GetPlayerCharacter()].activeinv == 6) { // Use cork on bottle
  // Do stuff
}
else unhandled_event(5,3); // Use anything else on bottle



You can, as SSH says, replace the unhandled_event(5,3); in the item scripts with a Display() command (and the GetInvName commands, if needed). This wouldn't actually be much more work, if you just copy-pasted the same default mesage, and would allow you to tailor some responses to the item clicked on (e.g. Display ("I could use %s, but I don't want to break the bottle", UsedInv) rather than a generic "That doesn't work").
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk