code query on Hotspot name above cursor

Started by Lyana, Mon 31/10/2005 07:11:37

Previous topic - Next topic

Lyana

I was searching for a method to place text above the cusor when it is over
a hotspot, and located this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=21681.0

I entered the text, as directed in the thread, to form the following bit of code:

Code: ags
int Over;string Name;int CharId, dx, dy;
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  
    if (IsOverlayValid(Over)){
      GetLocationName(mouse.x,mouse.y,Name);
      SetTextOverlay(Over,mouse.x-25,mouse.y-18,100,1,15,Name);}

      //mouse.x/mouse.y=position, 100=width, 1=?font?, 15=color
#sectionstart on_event   // DO NOT EDIT OR REMOVE THIS LINE

function on_event (int event,int data) { 
    if (event==ENTER_ROOM) {
      GetLocationName (mouse.x,mouse.y,Name);
      Over=CreateTextOverlay(mouse.x-25,mouse.y-18,100,1,15,Name);}
                       //mouse.x/mouse.y=position, 100=width, 1=?font?, 15=color
    else if (event==LEAVE_ROOM) {   
      RemoveOverlay (Over);}
      //Needs additional script to remove the overlay during the actual interaction.
}


I noted that I had to add the #sectionstart on_event to the global script,
and that when compiled, it gave me the following error:
undefined symbol 'IsOverlayValid'

Help would be much appreciated to find and fix the problem.

Elliott Hird

Whoa far too complicated there! Make a gui with transparent background and border, add a label on it and set its text to @overhotspot@. Then, in repeatedly execute:
Code: ags
gGuiScriptNameHere.SetPosition(mouse.x, mouse.y);

Ashen

Yes, I'd probably use the simpler method myself, but if you want to to it the hard way for some reason:

Are you using one of the newer versions (2.7+)? If so, all the Overlay commands (IsOverlayValid, CreateTextOverlay, RemoveOverlay, etc) have been scrapped in favour of properties (Overlay.Valid, Overlay.CreateTextual, Overlay.Remove, etc). Look them up for the versions you should be using. Or, you could uncheck the 'Enforce object based scripting' option on the General Settings window, to allow the old commands to be used.
I know what you're thinking ... Don't think that.

Gilbert

Also, unless your codes were just partially copied separately from two locations in your script, they're obviously messed up:
1. Whether you need the #sectionstart for on_event() is optional (as opposed to the more important repeatedly_execute(), where the #sectionxxx lines are needed for reference in the editor), but if you have a #sectionstart you MUST have a #sectionend line after the end of each function (currently from the codes you posted there're none for both repeatedly_execute() and on_event().
2. You can't have nested definitions for functions, so you can only define a function's content after a function had ended, unless your codes are partial or HEAVILY messed up with the brackets.
3. Also, as Ashen pointed out, if you're using V2.7+ you need to change the overlay codes.

Suggestion for fixing your codes:
Overlay* Over;
string Name;
int CharId, dx, dy;
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
    if (Over!=null) {
      if (Over.ValidlayValid(Over)){
        GetLocationName(mouse.x,mouse.y,Name);
        Over.SetText(100,1,15,Name);
        Over.X=mouse.x-25;
        Over.Y=mouse.y-18;
      }
   }
      //mouse.x/mouse.y=position, 100=width, 1=?font?, 15=color
}
#sectionend repeatedly_execute


#sectionstart on_event   // DO NOT EDIT OR REMOVE THIS LINE
function on_event (int event,int data) { 
    if (event==ENTER_ROOM) {
      GetLocationName (mouse.x,mouse.y,Name);
      Over=Overlay.CreateTextual(mouse.x-25,mouse.y-18,100,1,15,Name);}
                       //mouse.x/mouse.y=position, 100=width, 1=?font?, 15=color
    else if (event==LEAVE_ROOM) {   
      Over.Remove;}
      //Needs additional script to remove the overlay during the actual interaction.
}


SSH

Someone should just make a module for this and then these regular queries will all be over... Overlays means you could do it all in a module
12

Elliott Hird

But that would be messy.

Okay, Almost got my module working, but how can i work around that "use 320res co-ords" when near edge of screen?

Ashen

What do you mean? So it (the GUI/Overlay) isn't partly off-screen?
I know what you're thinking ... Don't think that.

SSH

320 res coords have nothing to do with screen edges.

If you want to make sure the "tooltip" is always on screen, you have to get it to swap sides when it gets close to an edge that would make it go off-screen.

The sides are given by game.viewport_height and game.viewport_width, which is resolution-independent
12

Elliott Hird

You know what I mean... I can't seem to get it right tho.

SSH

Ummm, no we dont' know what you mean, that's why we said what we did...

Don't be cryptic: tell us the problem and maybe we can help!
12

Elliott Hird

I'm coding a module for the n00bs for overhotspot mouse code, using a gui, and i setpositon mouse.x, mouse.y in module rep_ex. I know you have to work around that Cannot position gui use 320, 200 co-ords when near the edges of the screen, but I can't seem to remember the code.

Ashen

Sure you can. It gets a bit tricky when you try to position it outside the screen, or when it's so near that half the text is missing , but you can do it.

Do you mean something like:
Code: ags

if (mouse.x < 319 - GetTextWidth(Name,1)) Over.X = mouse.x;
else Over.X = 319 - GetTextWidth(Name,1);

Which would stop Over from being displayed off-screen? (Not tested, though, just for example.)
I know what you're thinking ... Don't think that.

Elliott Hird

Yeah. Unfortunately when finishing off the SQ6 template translation I deleted the module :(.

SSH

Something like:

Code: ags

#define OFFSET 10
// in rep_ex
textwidth=GetTextWidth(guiObjLabel.Text, guiObjLabel.Font);
if (mouse.x > (system.viewport_width - textwidth) - OFFSET) {
  gTooltip.x = (mouse.x - textwidth) - OFFSET;
} else {
  gTooltip.x = mouse.x + OFFSET;
}
textheight=10; // assume fixed...
if (mouse.y > (system.viewport_height - textheight) - OFFSET) {
  gTooltip.y = (mouse.y - text.height) - OFFSET;
} else {
  gTooltip.y = mouse.y + OFFSET;
}




12

Gilbert

#14
I think it's easier to make a module using overlays than a GUI, since using a GUI means the user need to create a GUI himself (or import an GUI/template).

Edit: Just made a simple module for it, try it out here.

SMF spam blocked by CleanTalk