Unhadled_event - what's wrong with this code? (SOLVED)

Started by Rui 'Trovatore' Pires, Wed 12/01/2005 13:22:29

Previous topic - Next topic

Rui 'Trovatore' Pires

Code: ags

function unhandled_event(int what, int type) {
Ã,  Ã, string unhandledsame;
Ã,  Ã, string not;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã, intÃ,  Ã,  randnot;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 

Ã,  Ã, // Display a message for using an inventory item on another inventory item
Ã,  Ã, if (what==5) {
Ã,  Ã,  Ã, inventory[player.ActiveInventory].GetName(unhandledsame);
Ã,  Ã,  Ã, StrToLowerCase(unhandledsame);
Ã,  Ã,  Ã, GetLocationName(mouse.x, mouse.y, temploc);
Ã,  Ã,  Ã, StrToLowerCase(temploc);
Ã,  Ã,  Ã, if (StrComp(temploc,unhandledsame)==0) Display("Why would you want to use the %s on itself?", unhandledsame);
Ã,  Ã,  Ã, else {
Ã,  Ã,  Ã,  GetLocationName(mouse.x, mouse.y, temploc);
Ã,  Ã,  Ã,  StrToLowerCase(temploc);
Ã,  Ã,  Ã,  randnot=Random(2);
Ã,  Ã,  Ã,  if (randnot==0) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "There's no real reason to use the %s on the %s.", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (randnot==1) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "Use the %s on the %s? You must be desperate!", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (randnot==2) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "I don't think using the %s on the %s would achieve anything.", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Display(not);
Ã,  Ã,  Ã,  type=0;
Ã,  Ã, }
Ã,  Ã,  Ã,  Ã, 

Ã,  Ã, 
Ã,  Ã, }

Ã,  Ã, // Display a random message for using an inventory item on something 
Ã,  Ã,  Ã, if (type==3 && what!=5) {
Ã,  Ã,  Ã,  inventory[player.ActiveInventory].GetName(unhandledsame);
Ã,  Ã,  Ã,  StrToLowerCase(unhandledsame);
Ã,  Ã,  Ã,  GetLocationName(mouse.x, mouse.y, temploc);
Ã,  Ã,  Ã,  StrToLowerCase(temploc);
Ã,  Ã,  Ã,  randnot=Random(2);
Ã,  Ã,  Ã,  if (randnot==0) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "There's no real reason to use the %s on the %s.", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (randnot==1) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "Use the %s on the %s? You must be desperate!", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (randnot==2) {
Ã,  Ã,  Ã,  Ã,  Ã, StrFormat(not, "I don't think using the %s on the %s would achieve anything.", unhandledsame, temploc);

Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Display(not);
Ã,  Ã, }Ã,  
}


With the above code, and with the following in my Key (inv item #1) in Use INventory with This interaction

Code: ags

if (player.ActiveInventory==1) Display("Why use the key on itself?");
else if (player.ActiveInventory==2) Display("You consider wrapping the key on the poster... but what the heck. You're lazy, and so am I.");
Ã,  
//else unhandled_event(5,0);


I NEVER get the message "Display("Why use the key on itself?");" when I use the key with itself. I'm sure I'm doing something wrong, and I'ms ure it's blindingly obvious... but I can't spot it...

BTW, I know some things looks redundant and could be simplified, but while I tried to fix this I tried different ways of coding. That's why.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scorpiorus

Try putting Display("ActiveInventory = %d", player.ActiveInventory); just before if (player.ActiveInventory==1) Display("Why use the key on itself?");

See what inventory item number it actually displays.

Rui 'Trovatore' Pires

As I feared would happen when I read your post, nothing happens. The thing simply isn't called at all. Putting a Display("ActiveInventory = %d", player.ActiveInventory); on the very beginning made NO DIFFERENCE AT ALL, because for some reason the thing isn't called.

What's ODD is that I DO get the 3 random "unhandled_event" error messages! The LATTER 3, too, the ones after the "type==3" check - this I have made sure of by using Displays (I love the "display" command, it's a beauty for debugging).
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

strazer

I copied your code into a test game using AGS v2.7 Beta 11.
Apart from having to declare the "temploc" variable, it worked right away.

I do get "Why use the key on itself?" and the unhandled_event messages...

Scorpiorus

#4
Yeah, the code itself seems ok. But the fact you get unhandled_event called while you don't manually invoke it means that AGS doesn't see the 'Use inventory item with this' interaction defined and thus calls unhandled_event by itself. Try re-adding the interaction and see if it helps.

Rui 'Trovatore' Pires

If you mean deleting the interaction and then re-adding it, it's tried. Didn't help at all, though, I'm afraid.

I'd post some more code, but I don't know how it'd help. My mouse_on_click code, for instance... thing is, there is NO PLACE in the script I call "unhandled_event" as a function, except AFTER the inventory item processing (and I commented THOSE out), and that's about the only reason it would override it.

...anyway, I guess it won't hurt. Here's the "Left click" section of my mouse code.

Code: ags

   else if (button==eMouseLeft) {
     gMenu.Visible=0;
     gFile.Visible=0;
     gGame.Visible=0;
      gGuibackiii.Visible=0;
     gGuibackiv.Visible=0;
     if (player.ActiveInventory!=-1 && GetLocationType(mouse.x,mouse.y)==eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
     else if (player.ActiveInventory!=-1 && gInv.Visible && GetInvAtLocation(mouse.x, mouse.y)==null) {}
     else if (player.ActiveInventory!=-1) ProcessClick(mouse.x, mouse.y, eModeUseinv);
     else {
     if (gInv.Visible==0) {
       ProcessClick(mouse.x, mouse.y, eModeWalkto); 
       gAction.Visible=0; 
       gGuibackii.Visible=0;
     }
     else {gAction.Visible=0; gGuibackii.Visible=0;}
   }
   }
   else if (button==eMouseLeftInv) {
     if (player.ActiveInventory!=-1) ProcessClick(mouse.x, mouse.y, eModeUseinv); 
     else {
     player.ActiveInventory=game.inv_activated;
     mouse.Mode=eModeUseinv;
     highlit=1;
     mouse.ChangeModeGraphic(eModeUseinv, inventory[player.ActiveInventory].Graphic+10000);
     gAction.Visible=0; 
     gGuibackii.Visible=0;
}
   }
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Rui 'Trovatore' Pires

#6
Nevermind, I might have found out. SOMEONE (who I already PMd) has, while commenting and revising my code, REMOVED defines like #sectionstart onouseclick, or whatever they are. This is probably the matter. I am transferring the whole shebangs to a new game, so that AGS may link stuff properly...

[vents] THIS is the LAST TIME I let ANYone touch MY code in ANY circunstances! [/u][/vents]
Ah, that felt good...

EDIT - No, that wasn't it. I completely transfered the thing to a new game... and still the problem occurs. Which means the problem is definitely my code.

I also tried commenting out everything related to unhandled_evet, and guess what? Nothing happens. AT ALL. When I use INV items on one another, nothing happens.

Is someone up for checking the thing? I can upload the whole mess.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scorpiorus

Think I see what's wrong. You ticked "handle inventory clicks in script" and then try using ProcessClick to run the "use inv on this item" interaction. But this function only works with background so it "clicks" behind the inventory GUI. Use RunInventoryIteraction instead, thus with the new OO approach:

...
else if (button==eMouseLeftInv) {
Ã,  Ã,  Ã, if (player.ActiveInventory!=-1) inventory[game.inv_activated].RunInteraction(eModeUseinv);
...

Rui 'Trovatore' Pires

<slaps head and goes in the corner with a big DUNCE cap on it>

Thank you very much, oh god of scripting. ;D
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk