overlay next to mouse displaying hotspot's name works fine UNTIL room change

Started by Khris, Fri 10/09/2004 03:16:44

Previous topic - Next topic

Khris

Hello, I'm really stuck here.

My situation is the following:
When the mouse is over a hotspot (or obj or char), I made the cursor change to the appropriate MODE.
Additionally, I wanted to display the name of the hotspot next to the cursor.
I figured I could use a transparent GUI with one label and change the GUI's pos and label's text in the repeatedly_execute().
My first attempt though was to achieve this by using a TextOverlay which seems to be a more elegant way (at least in my opinion).

First I tried to store the Overlay's ID in an int I declared in line 2 of the global script (outside any function).
In game_start() I had
Ã,  id=CreateTextOverlay(0, 0, 100, 2, 1, "");
and in the global repeatedly_execute() I had
Ã,  SetTextOverlay(id, x+5, y+5, 100, 2, 1, line); (with x and y holding the mouse coords)

Then I tried another approach:
In game_start() I had
Ã,  int id;
Ã,  id=CreateTextOverlay(0, 0, 100, 2, 1, "");
Ã,  SetGlobalInt(9, id);
and in the global repeatedly_execute() I had
Ã,  int id;
Ã,  id=GetGlobalInt(9);
Ã,  SetTextOverlay(id, x+5, y+5, 100, 2, 1, line);

Both methods work fine as long as EGO stays in the first room.
But as soon as a new room is loaded, the game crashes with the following error message:
(room 4, script line 66) RemoveOverlay: Invalid Overlay ID passed
(line 66 of the global script holds the SetTextOverlay command)

(Perhaps I should add that I don't use the global repeatedly_execute(); I wrote my own called rep_ex() and call it in every room's repeatedly_execute() to disable the cursor's auto-change in rooms where I don't want it. But I believe it doesn't matter. And the global repeatedly_execute() is empty of course.)

I know this post is awfully long, but I wanted to be exact. Sorry :)

Please help, any hint is appreciated.

Gilbert

Because overlays will be destroyed when you enters a new room. You need to create another in a new room.

To remedy this, you can create the overlay in the on_event() function instead of game_start().

In the global script, create a function on_event() likie below (if it's already created, jut add the if (.....} part contents into it):
function on_event (int event, int data) {Ã,  Ã,  
Ã,  Ã, if (event == ENTER_ROOM) {
Ã,  Ã,  Ã, id=CreateTextOverlay(0, 0, 100, 2, 1, "");
     SetGlobalInt(9, id);
Ã,  Ã, }
 }

(Just comment out the create overlay and setglobalint line form game_start)

You can read more about on_event() from the manual section:
Reference --> Text script event reference

Also, if all the related codes are in the global script you don't need to use GlobalInts (unless you want to use it in a room script).
You can just move the "int id;" line on top of the global script, out of functions, then every functions in the global script can refer to this id variable directly (and use GlobalInts if you want its value in a room script).

Khris

Great, works perfectly,
thank you very much for the quick response!

Phemar


I use this one:
int over;string hot;
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
    if (IsOverlayValid(over)) {
      GetLocationName(mouse.x,mouse.y,hot);
      SetTextOverlay (over,mouse.x+10,mouse.y-10,5,1,15,hot);}}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_event   // DO NOT EDIT OR REMOVE THIS LINE
function on_event (int event,int data) {
  if (event==ENTER_SCREEN) {
    GetLocationName (mouse.x,mouse.y,hot);
    over=CreateTextOverlay(mouse.x+10,mouse.y-10,5,1,15,hot);}
  else if (event==LEAVE_SCREEN) {
    RemoveOverlay (over);}}
#sectionend on_event  // DO NOT EDIT OR REMOVE THIS LINE

SMF spam blocked by CleanTalk