status bar and global messages for unrecognized actions [Both solved] Thanks!

Started by gummicommander, Sun 04/09/2005 16:22:17

Previous topic - Next topic

gummicommander

I have two questions (well, two sections of questions i guess) and I was hoping somebody could help me out :)

(Question 1 [how to make an (action) (hotspot) status bar] solved... thanks :D)

The other question is, how do I set it up so that when the player does an unrecognized action a message pops up that actually says what the player was trying to do-- like a global message that says "Why would you want to use a (inventory item) on the (hotspot)? That just doesn't make any sense!" or something like that?

monkey0506

Code: ags
/* repeatedly_execute */
if (mouse.Mode == eModeWalkto) lblActionLabel.SetText("Walk to @OVERHOTSPOT@");
else if (mouse.Mode == eModeLookat) lblActionLabel.SetText("Look at @OVERHOTSPOT@");
else if (mouse.Mode == eModeTalkto) lblActionLabel.SetText(Talk to @OVERHOTSPOT@");
/* etc. */


Something along this lines should be able to update the label text appropriately...and as for the error message, maybe something like:

Code: ags
function unhandled_event(int what, int type) {
  if (what == 1) {
    if (type == 3) {
      Hotspot* spot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      Display("Why would you want to use a %s on a %s?  That just doesn't make any sense!", player.ActiveInventory.Name, spot.Name);
      }
    }
  }


[EDIT:]

Just FYI, the Name properties of the player.ActiveInventory and Hotspot* spot are only available to AGS v. 2.71 beta 4+, so if you are using 2.71 beta 3 or previous then you would have to replace Name with GetName().

gummicommander

Is there any specific place these things should go in the global file? I stuck it right before function show_inventory_window, and called the function show_action_label. Anyways, I tried copy-pasting the first bit of code in there, and it tells me that token lblActionLabel is undefined, so I tried setting it as a string in the very beginning of the script and then right after "sectionend repeatedly_execute", but it apparently it wasn't expecting my StrCopy command in either case.Ã, 

??? Is "lbl" supposed to be part of a string name, or something to let the system know I'm talking about a label in a GUI, or... something else? ???

Ashen

'lblActionName' is, I'm guessing, the script-o-name for the label you want the text to be displayed on - you'll need to change it to whatever your label is actually called. (Assuming you're using 2.7+.) The code needs to go in the repeatedly_execute (or rep_ex_always) function of the global script. (And is obviously missing a few lines for the other modes.)

The second part (unhandled_event) can go anywhere in the global script, provided it's outside all other functions. Look it up in the manual for a fuller description (e.g. other mouse modes, interacting with characters rather than hotspots, etc).
I know what you're thinking ... Don't think that.

gummicommander

 ;D YAY! Ok, I got the first thing to work :) Thanks a lot to both of you! (And yes, I added another line for the "Use" mode if that's what you meant)


For the second part... 'type' describes the type of message displayed (which would depend on the current mouse mode), right? and 'what' would describe...? A hotspot that isn't supposed have any items used on it, maybe?

Ashen

For the first thing - Yes, that's what I meant about the missing lines.

For the second thing:
Quote from: MeLook it up in the manual for a fuller description

If you look at the manual entry for unhandled_event, you're right that type is to do with the mode used, while what relates to what is being clicked on (hotspot, character, object, etc). The full list of what values mean what is in the manual.
I know what you're thinking ... Don't think that.

gummicommander

Oh, i see it now... :P Sorry, I didn't realize that unhandled_event was a default command. I thought it was a function name made up by monkey.Ã,  :-[

Sorry to be a pest, but I think I'm getting some kind of syntaxy error now. I've barely changed monkey's example (All I changed was .name to .getname, because I'm on 2.70), but it tells me I'm missing a "(" on line 13 , the Display line. I have no idea where to add it :\

function unhandled_event(int what, int type) {
Ã,  if (what == 1) {
Ã,  Ã,  if (type == 3) {
Ã,  Ã,  Ã,  Hotspot* spot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
         Display ("Why would you want to use a %s on a %s? That makes no sense!", player.ActiveInventory.GetName,Ã,  spot.GetName);
Ã,  Ã, }
Ã,  }
}

As you can see, I've gotten pretty far. ::)

(If you're getting frustrated with me, that's OK. I could always comment it out for now and get back to it later, when I know more about this stuff and am less tired)

Gilbert

player.ActiveInventory.Name for v2.71

player.ActiveInventory.GetName(buffer) for v2.7

Note that V2.71 handles string differently from previous versions.
For previous versions, you can't have a string returned directly as a property.
So, you need to do the complicated work like:
function unhandled_event(int what, int type) {
Ã,  string tmpstr1, tmpstr2;
Ã,  if (what == 1) {
Ã,  Ã,  if (type == 3) {
Ã,  Ã,  Ã,  Hotspot* spot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Ã,  Ã,  Ã, player.ActiveInventory.GetName(tmpstr1);
Ã,  Ã,  Ã,  Ã, spot.GetName(tmpstr2);
Ã,  Ã,  Ã,  Ã,  Ã, Display ("Why would you want to use a %s on a %s? That makes no sense!", tmpstr1,Ã,  tmpstr2);
Ã,  Ã, }
Ã,  }
 }

gummicommander

:D:D OK now that's working too! I think I can handle doing the rest of the handlers myself... thanks so much.

monkey0506

Oops.  I forgot the 2.7 functions required buffer parameters... I've been working with the latest betas since beta 3 so I've been using that new String type here lately...

Glad to hear you got it worked out though.  And thanks for helping him decipher my code Ashen. ;)

SMF spam blocked by CleanTalk