Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Konador on Tue 13/07/2004 14:56:40

Title: unhandled_event - Completely Clueless
Post by: Konador on Tue 13/07/2004 14:56:40
Hi. I have read the help files for unhandled event, but I am really new to this and I still don't understand how to script. I even tried copying the unhandled_event code from the demo game but it comes up with errors when I try to test game. I changed the character name from EGO to my character but still get an error. The code is completely meaningless to me, and I have no clue how to customise it. Is there a plugin which will let me do it in a similar way to programming in dialogues? Or is there someone out there who can explain it to me step by step? I'd like to have a rotation of 3 or 4 "I can't do that" type things, so that I don't have to program every single hotspot and item combination.

Thanks for any help you can give,
-Ben
Title: Re: unhandled_event - Completely Clueless
Post by: TerranRich on Tue 13/07/2004 15:58:14
Quoteunhandled_event (int what, int type)
Called when an interaction is run, but no events are listed in the interaction window. This could be used to display a default "I can't do that" type of message. The values of WHAT and TYPE tell you what the player did.
The possible values are listed below:

WHAT TYPE Description
    1       1    Look at hotspot
    1       2    Interact with hotspot
    1       3    Use inventory on hotspot
    1       4    Talk to hotspot
    1       7    Pick up hotspot
    1       8    Cursor Mode 8 on hotspot
    1       9    Cursor Mode 9 on hotspot
    2       0    Look at object
    2       1    Interact with object
    2       2    Talk to object
    2       3    Use inventory on object
    2       5    Pick up object
    2       6    Cursor Mode 8 on object
    2       7    Cursor Mode 9 on object
    3       0    Look at character
    3       1    Interact with character
    3       2    Speak to character
    3       3    Use inventory on character
    3       5    Pick up character
    3       6    Cursor Mode 8 on character
    3       7    Cursor Mode 9 on character
    4       1    Look at nothing (ie. no hotspot)
    4       2    Interact with nothing
    4       3    Use inventory with nothing
    4       4    Talk to nothing
    5       0    Look at inventory
    5       1    Interact with inventory (currently not possible)
    5       2    Speak to inventory
    5       3    Use an inventory item on another
    5       4    Other click on inventory

What's the problem with that above manual quote? Just use an if statement to check EVENT and DATA and display a message accordingly. You can use the Random() command to display a random message. Look up the BFAQ for information on creating your own functions. Keep in mind that you do NOT have to import ths function, as it is already checked by AGS to see if it exists.

If you're unable to figure it out on your own, I'll be willing to give you an example function.
Title: Re: unhandled_event - Completely Clueless
Post by: Konador on Wed 14/07/2004 07:53:54
Hi, Thanks for the reply. I've read all the material on this but I still don't know what to do. Is it something like:

#sectionstart unhandled_event

unhandled_event (1,7) "I'm not picking that up!"
unhandled_event (2,5) "Why would I want to pick that up?"

#sectionend unhandled_event
Title: Re: unhandled_event - Completely Clueless
Post by: Ashen on Wed 14/07/2004 14:42:02
No, more like this:

#sectionstart unhandled_event
function unhandled_event (int what, int type) {
  if (what == 1) { //if Hotspot
    if (type == 4) { // if Talk To Hotspot
      Display ("I could, but it won't answer.");
    }
    if (type == 7) { // if Pick Up Hotspot
      Display ("I'm not picking that up!");
    }
  }
  if (what == 2) { //if Object
    if (type == 2) { // if Talk To Object
      Display ("Aren't you a pretty thing?");
      Wait (20);
      Display ("It's ignoring me. How rude.");
    }
    if (type == 5) { // if Pick Up Object
      Display ("Why would I want to pick that up?");
    }
  }
}
#sectionend unhandled_event

I added a second 'type', to give you more of an idea how to do different ones.

To make a random response for Pick up object, for example, change:

    if (type == 5) { // if Pick Up Object
      Display ("Why would I want to pick that up?");
    }

to:

    if (type == 5) { // if Pick Up Object
      int ran=Random(2);
      if (ran==0) Display ("Why would I want to pick that up?");
      else if (ran==1) Display ("I'm not picking that up");
      else Display ( "It'll never fit in my pocket.");
   }


Hope this is some use.
Title: Re: unhandled_event - Completely Clueless
Post by: Konador on Wed 14/07/2004 22:10:52
Thanks :)

I tried editing it and adding a section for inventry combinations,

Quote#sectionstart unhandled_event
function unhandled_event (int what, int type) {
Ã,  if (what == 1) { //if Hotspot
Ã,  Ã,  if (type == 4) { // if Talk To Hotspot
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 2) { // if Pick Up Hotspot
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  Ã,  Ã,  Ã,  if (type == 3) { // if Use inventry with Hotspot
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
Ã,  }
Ã,  if (what == 2) { //if Object
Ã,  Ã,  if (type == 2) { // if Talk To Object
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 5) { // if Pick Up Object
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  }
Ã,  Ã,  Ã,  if (type == 3) { // if use inventry with Object
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
}
Ã,  if (what == 5) { //if Inventry item
Ã,  Ã,  if (type == 3) { //if inventry item on another
Ã,  Ã,  Ã,  Display ("Those two things wouldn't work together.");
}

#sectionend unhandled_event

When I click test it says "unexpected if on line 148", which is this line:

if (what == 5) { //if Inventry item

Whats the problem with it?
Title: Re: unhandled_event - Completely Clueless
Post by: Mr Flibble on Wed 14/07/2004 22:50:17
I can only conjecture with my pure coding knowledge, but methinks it needs an extra closing brace on the line above/ different spacing of existing braces.
Title: Re: unhandled_event - Completely Clueless
Post by: Konador on Wed 14/07/2004 23:14:17
If I put in an extra one in it says:

Unexpected "}"

I've tried loads of different combinations or braces and stuff, but none of them seem to work :(
Title: Re: unhandled_event - Completely Clueless
Post by: Wolfgang Abenteuer on Thu 15/07/2004 01:31:42
Your braces don't match up is why.

function unhandled_event (int what, int type) {
Ã,  if (what == 1) { //if Hotspot
Ã,  Ã,  if (type == 4) { // if Talk To Hotspot
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 2) { // if Pick Up Hotspot
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  Ã,  Ã,  Ã,  if (type == 3) { // if Use inventry with Hotspot
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
Ã,  }
Ã,  if (what == 2) { //if Object
Ã,  Ã,  if (type == 2) { // if Talk To Object
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 5) { // if Pick Up Object
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  }
Ã,  Ã,  Ã,  if (type == 3) { // if use inventry with Object
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
}
Ã,  if (what == 5) { //if Inventry item
Ã,  Ã,  if (type == 3) { //if inventry item on another
Ã,  Ã,  Ã,  Display ("Those two things wouldn't work together.");
}

The function unhandled_event function terminates with the closing brace I've bolded.Ã,  Everything after that is outside the the function (and essentially in "limbo") so the game can't understand why there's an "if" statement in the middle of nowhere.Ã,  Put another closing brace at the end, like Mr Flibble suggested, and delete the one that I've bolded.Ã,  Also, you might want to move one of the three brackets at the end of the if (what == 1) statement and put it above the if (type == 3) { // if Use inventry with Hotspot line, because those two conditionals aren't properly closed and will cause problems when they go to be executed.

Edit:Ã,  Essentially, make it look like this:
function unhandled_event (int what, int type) {
Ã,  if (what == 1) { //if Hotspot
Ã,  Ã,  if (type == 4) { // if Talk To Hotspot
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 2) { // if Pick Up Hotspot
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  }
Ã,  Ã,  if (type == 3) { // if Use inventry with Hotspot
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
Ã,  if (what == 2) { //if Object
Ã,  Ã,  if (type == 2) { // if Talk To Object
Ã,  Ã,  Ã,  Display ("That can't speak, duh.");
Ã,  Ã,  }
Ã,  Ã,  if (type == 5) { // if Pick Up Object
Ã,  Ã,  Ã,  Display ("I can't pick that up!");
Ã,  Ã,  }
Ã,  Ã,  if (type == 3) { // if use inventry with Object
Ã,  Ã,  Ã,  Display ("That wouldn't do anything useful.");
Ã,  Ã,  }
Ã,  }
Ã,  if (what == 5) { //if Inventry item
Ã,  Ã,  if (type == 3) { //if inventry item on another
Ã,  Ã,  Ã,  Display ("Those two things wouldn't work together.");
Ã,  Ã,  }
Ã,  }
}


~Wolfgang
Title: Re: unhandled_event - Completely Clueless
Post by: Mr Flibble on Thu 15/07/2004 18:32:28
Wow, I was right, first time that happened.
I'd just like to say that this thread has helped me too. Unhandled events weren't something I'd really thought about, but now I shall spend an hour (maybe less) coding all manner of random responses.
Title: Re: unhandled_event - Completely Clueless
Post by: TerranRich on Fri 16/07/2004 17:09:38
I would suggest...to everybody...please find a tutorial somewhere on programming in general. Parameters, return values, and "if" statements are integral parts of any programming language and should be learned if you plan on using the scripting in AGS.