Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dan_N on Wed 02/08/2006 17:03:35

Title: @OVERHOTSPOT@, next to the cursor. (SOLVED)
Post by: Dan_N on Wed 02/08/2006 17:03:35
Hello.

I'm fairly new at this so first of all I ask you, please please don't post directly scripts without explaining then what you meant.

Ok, here's my problem: I've seen it done many times, then name of the hotspot/object/character appearing next to cursor. But not in a text window, so the player has to click for the window to dissapear. To further understand what I mean look at 7 Days a Skeptic and Beneath a Steel Sky.

Is this a too complicated problem to post in the Beginner's Technical Questions?
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: limeTree on Wed 02/08/2006 17:08:57
Go to the resource page,i think it is a module,you just upload it and there you go.
Name the objects and otspots when you create them,that name will be shown)
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Dan_N on Wed 02/08/2006 17:18:24
Thanks. I looked it up and found something.
But I don't think I'll implement it any time soon 'cause it looks pretty complicated... ??? and I want to experiment with it...
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: SSH on Wed 02/08/2006 17:32:02
It's my Description module, and if you just import it, I think it does what you want.
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Khris on Wed 02/08/2006 19:01:00
Quote from: Dan_N_GameZ on Wed 02/08/2006 17:03:35I'm fairly new at this so first of all I ask you, please please don't post directly scripts without explaining then what you meant.
So my guess is you want to learn how to do this rather than a ready-made solution, correct?

One way to do this is using a GUI with a single label.
You'll need mouse.x, mouse.y, GUI.SetPosition and Label.Text.
Look up these commands, if necessary, and try to get it working.
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Dan_N on Wed 02/08/2006 23:03:27
Ok, I think I got an ideea on how to make this happen:

I go to interaction window of a hotspot and at the condition "When mouse over hotspot" I put in an action "Run Script". There at the "mouse.x,mouse.y" coordinates I set the position of a GUI label and write in the label the name of the hotspot. But there something here I'm not getting... Won't the label be refreshed every cycle the mouse is over hotspot? Even if it's not moving?
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Khris on Thu 03/08/2006 04:50:22
Yes, it will. But you won't notice.

Having to put the same code in every hotspot's "when mouse over"-interaction would be horrible.
That's what the repeatedly_execute function in the global script is for (among other things).

The code inside the rep_ex() should basically look something like this:
Ã,  lblHotspotname.Text=Game.GetLocationName(mouse.x, mouse.y);Ã,  // set label text
Ã,  gHotspotname.SetPosition(mouse.x+2, mouse.y+13);Ã,  // move GUI


Alternatively, you could set the label's text to "@OVERHOTSPOT@".
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: monkey0506 on Thu 03/08/2006 08:42:16
Quote from: KhrisMUC on Thu 03/08/2006 04:50:22  gHotspotname.SetPosition(mouse.x+2, mouse.y+13);  // move GUI

You'll probably want some sort of bounds-checking on this as well.

  int x = mouse.x, y;
  int width = GetTextWidth(lblHotspotname.Text, lblHotspotname.Font);
  if (mouse.x - (width / 2) < 0) x = 0;
  else if (mouse.x + (width / 2) >= System.ViewportWidth) x = System.ViewportWidth - width;
  /**** THIS WILL ONLY WORK IN AGS 2.72 AND LATER ****/
  mouse.y + (Game.SpriteHeight[mouse.GetModeGraphic(mouse.Mode)] / 2) + 2;
  if (y > System.ViewportHeight) y = mouse.y - GetTextHeight(lblHotspotname.Text, lblHotspotname.Font, width) - (Game.SpriteHeight[mouse.GetModeGraphic(mouse.Mode)] / 2) - 2;
  /******** USE THIS FOR PREVIOUS VERSIONS *********/
  y = mouse.y + 8 + 2;
  if (y > System.ViewportHeight) y = mouse.y - GetTextHeight(lblHotspotname.Text, lblHotspotname.Font, width) - 8 - 2;
  /**********************************************/
  gHotspotname.SetPosition(x, y);


This will ensure that you don't try to display the label outside of the screen (that way you can always see all of the text it contains.

In pre-2.72 versions you will have to either a) code a get mouse-mode graphic function yourself (which will be completely customized toward your game settings), or b) use an arbitrary number to represent 1/2 the height of the mouse (in the above code I used 8 which is half the size of the default cursors).
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Dan_N on Thu 03/08/2006 09:06:16
Hello all, just finihed my omlet... ;) (it was gooood)

Anyway, thought i'd tell you all: i'm using AGS 2.71, and i don't think i'll be upgrading anytime soon, 'cause i got two projects in this AGS already...

And i really don't see why i would want to make a checking to be sure the text isn't displayed outside of the hotspot. if i write in label.text @OVERHOTSPOT@, wouldn't that do the job for me automatically? i think i'm gonna go with krismuc's ideea, 'cause it sounds great and simple and i'm an adept of KISS (keep it simple, stupid! ;)). But thanks for the input and if anybody has anymore ideeas, i'll be glad to hear them!
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Ashen on Thu 03/08/2006 10:38:00
QuoteAnd i really don't see why i would want to make a checking to be sure the text isn't displayed outside of the hotspot.

No, you misunderstood. monkey_05_06's code isn't to stop it being displayed off the HOTSPOT, it's to stop it being displayed off the SCREEN. There's two reasons for this the first being the obvious one of, it's a bit pointless having the hotspot name displayed if half of it isn't actully visible. The other is, if the hotspot is very near the edge of the screen, mouse.x+2 or mouse.y+13 might be outside the screen boundaries - which would cause a crash.
Neither of these might be issues for you, depending on how you set your rooms up - but surely it's simpler to do this than have to fuss with the placement of hotspots in the room (and if you also want it to work on Characters that might be moving about, this'd become even harder).

EDIT: Oops. Fixed attribution, sorry about that, monkey. Somehow managed to read the author of the quote, instead of the post it was in.
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: monkey0506 on Thu 03/08/2006 21:14:14
Quote from: Ashen on Thu 03/08/2006 10:38:00KhrisMUC's code isn't to stop it being displayed off the HOTSPOT, it's to stop it being displayed off the SCREEN.

Erm...monkey_05_06's code you mean? ;)

Anyway, you don't have to use the bounds-checking. I just figured it could save you some trouble if you want to be able to have hotspots near the edge of the screen...because like Ashen said, it will cause problems if you're not careful with where you try to position the GUI.

[EDIT:]

Ashen, it's okay. :=
Title: Re: @OVERHOTSPOT@, next to the cursor.
Post by: Dan_N on Thu 03/08/2006 21:30:13
Yeah, well, I like to keep my rooms small, in the center, with lots of black arround and some space to the end of the screen. Also, the GUIs i like to make for displaying of scoring, buttons whatever are always visible and near the end of the screen, so I don't know what good the bounds checking will do. But again, input is good and I thank you for that.