Getting hotspots/objects mouseover to show text(SOLVED)

Started by proskiier, Sat 10/11/2007 16:51:18

Previous topic - Next topic

proskiier

My question is basically in the topic but I saw in the "how to cure a cold game" that when you had the mouse over lets say paintings (text would show up on the bottom left side of the screen saying what object/hotspot you had the mouse over.

I was just wondering how you do this.  Thanks alot for reading and/or helping me out.

Radiant

Make a GUI, put a label on that GUI, and have the text include the word @OVERHOTSPOT@

gypsysnail

Hi Radient thats a good one, I am now at this stage of learning how to do this particular feature and I would like if someone could please expand on this a bit? This gui if it is going to be made in the gui pane, how does it get directed to the particular hotspot and in that particular room? Is any further scripting by the game author needed to be done?
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Radiant


Khris

GUIs are room independent, so you don't need to worry about moving it to rooms.
As long as the GUI's visibility is set to normal, it will be visible at all times.

I'll call the GUI "gOverhot".

To move it about on the screen, you need to call the GUI's SetPosition function (or change its coords directly).
This has to be done constantly, so you'd put the code in the repeatedly_execute function of the global script:
Code: ags
  //inside rep_ex
  int c=System.ViewportWidth-gOverhot.Width;
  int x=mouse.x+XOFFSET; if (x<0) x=0; if (x>c) x=c;
  c=System.ViewportHeight-gOverhot.Height;
  int y=mouse.y+YOFFSET; if (y<0) y=0; if (y>c) y=c;

  gOverhot.SetPosition(x, y);

Replace X/YOFFSET with small numbers to set the GUI apart from the mouse cursor a little.
The checks are there to make sure the GUI is always displayed fully on screen.

gypsysnail

Thanks KrisMUC
I kind of still don't fully get it, I know its silly that I cant, but I havent done this for a long time, and only just came back to working on my game. I'm not exactly sure where to start with this gui... starting point to ending point though I think the ending point is putting the code in the global script. Where do I start....? Sorry I'm not an experienced programmer, I'm learning but have never studied it professionally.
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

No worries, here's the step by step:

Create the GUI, resize it to a suitable width and height (e.g. 100x14) and call it "gOverhot". Notice the small properties window? That's where you enter the Scriptname and dimensions and set the visibility to "Normal". Now set the background and border color to 0 to make the GUI invisible.
(Actually, the GUI's contents will still be visible, just not the GUI itself.)

Add a label to it. Using the yellow dots at the corners, resize it so it's roughly as big as the GUI.
In the properties window, set its text to "@OVERHOTSPOT@". You should see that text appear on the label.
(You can enter some other text first to properly place the label.)

The only thing left to do is add the code to the rep_ex function. Just select if from the menu (Script -> repeatedly_execute) and put the text inside the curly brackets.

If you want to deactivate the GUI (e.g. in an options screen or the like), set it's .Visible property to false.
Code: ags
  gOverhot.Visible=false;

Upon leaving the options screen, just set it back to "true".

The only downside is the fixed width of the GUI. Thus even with a very short hotspot text, the GUI won't move all the way to the right of the screen.
There's a way to overcome this, but we'll stick to the current method for now.

SSH

12

gypsysnail

Thank you KrisMUC and SSH!! ;) I am going to try both, always keen to try everything. My head is full of cobwebs, I remember last I spoke of those modules, and I will give that one a go. Many thanks again
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

gypsysnail

#9
Ok I did all you told me to do (but bit confused by the offset x/y instructions, not sure what you mean.. there are a lot of x and ys in the script, which ones should I change to numbers?) and I went to test game but it came back with an error message:

"problem was in: Internal character defines
error line: 81 (in my script thats where I placed, within the rep exe). Variable gOverhot is already defined"

And then.... it interestingly came up with a 2nd error message rite away saying "this error occured in an internal AGS script. This should never happen; try reinstalling the latest AGS"  ummm???? Is there a recently upgraded ags program I'm not aware of? I know I've not been here so regularly of late, but havent visited the main ags website to see it so maybe I've missed it. Do you know anything about the 1st error message?

EDIT: Ok I went back and had a look, I put the name Overhot in the script little box, and now I have deleted that bit, yes u didnt mention that so I think I went wrong there lol ;). Anyway that went and the 1st error message didnt pop up, it proceeded to save the game and then a new error message came up - this time
"Problem in: Global script (obviously! lol)
Error line 64 Expected Integer value after "="
(copied and pasted line 64 here for you: int c=System.ViewportWidth-gOverhot.Width;
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

I tested my code and instructions and everything went smoothly.
(Except that the GUI's name is supposed to be "OVERHOT" and goes into the text box at the top, but you seem to have corrected that by yourself.)

There are a lot of x and ys in the script but only one "XOFFSET" and one "YOFFSET". Those would be rejected by the compiler if you left them in.

The error you got (about "int c=...") suggests that you pasted the code outside a function.

gypsysnail

#11
Ok... not sure what out of function area means... I am thinking I should have typed function at the start of the code...? I am not sure what you mean by the offset bit sorry. Where do I replace the x y with small numbers? For example would 3 for x and 3 for y be ok?
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

No, not at the start.
A piece of code like this always goes into a so-called function. Either a custom one or one of AGS's predefined ones, as in this case:
Quote from: KhrisMUC on Mon 12/11/2007 11:01:52The only thing left to do is add the code to the rep_ex function. Just select if from the menu (Script -> repeatedly_execute) and put the text inside the curly brackets.
After selecting the menu item, the script editor window should appear with the cursor sitting at a line where it says "function repeatedly_execute()"
After that there are two curly brackets { and }, the code goes in between them.
Like this:
Code: ags
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  int c=System.ViewportWidth-gOverhot.Width;
  int x=mouse.x+XOFFSET; if (x<0) x=0; if (x>c) x=c;
  c=System.ViewportHeight-gOverhot.Height;
  int y=mouse.y+YOFFSET; if (y<0) y=0; if (y>c) y=c;

  gOverhot.SetPosition(x, y);
}


Now look at that code and notice the two all-caps words: XOFFSET & YOFFSET
Replace those with numbers like 3, yes.
Now the x line would say " int x=mouse.x+3;  if (..."

Putting a 3 in there makes AGS place the top left corner of the GUI 3 pixels to the right of the mouse.
Putting a 5 in there instead of YOFFSET makes AGS place it 5 pixels below the current mouse position.
This is done to avoid the cursor overlapping the hotspot text.

Alternatively, don't add those offsets and in the GUI editor, move the label a bit to the right and down.

gypsysnail

Thanks for the that. Ok I tried it and I got the error message variable already defined and it took me to the global script where I had pasted the code. I still dont fully understand the function stuff. I have copied and pasted below the current code sequence of the things i have already in the rep_exe for other functions, before the code you gave me goes in. I have tried but still doesnt recognise.

Code: ags
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  lblTime.Text = String.Format("%02d:%02d, Day %d", GameTime.Hour(),
GameTime.Minute(), GameTime.Day());
  // Start of special Following Code
  if (cEgo.Moving == false) { // Player has stopped moving (obviously)
    if (Follow == 1) { // If Jonah is still flying
      // Change state (the 'Follow' variable), and have him fly to Ego
      cJonah.FollowCharacter(null);
      Follow = 2;
      cJonah.Walk(cEgo.x,  cEgo.y, eNoBlock);
    }
    else if (Follow == 2) { // If Jonah is on his way to Ego's shoulder
      if (cEgo.Loop == 1 || cEgo.Loop == 0) cJonah.Baseline = cEgo.y -
1; // Or '==2' for the other shoulder
      else cJonah.Baseline = cEgo.y + 1;
      if (cJonah.Moving == false) { // Jonah is at Ego's location
        // Make sure their Loops are always the same
        cJonah.Loop = cEgo.Loop;
      }
    }
  }
  else { // If Ego is Moving
    if (Follow == 2) { // If Jonah is 'at rest'
      // Change state (the 'Follow' variable), and have him start flying free
      cJonah.FollowCharacter(cEgo,0,0);  
      Follow = 1;
    }
  }
  // End of special Following Code
}

function show_inventory_window () {
  // This demonstrates both types of inventory window - the first part is how to
  // show the built-in inventory window, the second part uses the custom one.
  // Un-comment one section or the other below.
  
  // ** DEFAULT INVENTORY WINDOW
//  InventoryScreen();

  // ** CUSTOM INVENTORY WINDOW
  gInventory.Visible = true;
  // switch to the Use cursor (to select items with)
  mouse.Mode = eModeInteract;
  // But, override the appearance to look like the arrow
  mouse.UseModeGraphic(eModePointer);

}

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


EDIT:
Hey! can someone please reply????? I am sorry that I have to double post but I don't want to be waiting this long for a reply! PLEASE HELP! Or I will have to post my question into a new topic SORRY! I think its cos this topic is labelled SOLVED at the end thats why but I am not happy no one has answered my question above come on!

EDIT by Ashen: To remove double post. Have patience, and read the rules.

Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

Calm down already.

First of all, the show_inventory_function somehow ended up inside the repeatedly_execute's #sectionstart / #sectionend lines.

The code is properly indented so in the snippet you showed there are only two lines that contain a single } at the very beginning of the line.
Those }s close the respective function opened with "function NAME() {"

Everything between the { and } is considered inside the function and the code I posted earlier still isn't.

Please do the following and do it exactly the way I describe it:

Select all the following code and copy it to the clipboard:
Code: ags
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here

  //*****OverHot code start
  int c=System.ViewportWidth-gOverhot.Width;
  int x=mouse.x+XOFFSET; if (x<0) x=0; if (x>c) x=c;
  c=System.ViewportHeight-gOverhot.Height;
  int y=mouse.y+YOFFSET; if (y<0) y=0; if (y>c) y=c;
  gOverhot.SetPosition(x, y);
  //*****end

  lblTime.Text = String.Format("%02d:%02d, Day %d", GameTime.Hour(),
GameTime.Minute(), GameTime.Day());
  // Start of special Following Code
  if (cEgo.Moving == false) { // Player has stopped moving (obviously)
    if (Follow == 1) { // If Jonah is still flying
      // Change state (the 'Follow' variable), and have him fly to Ego
      cJonah.FollowCharacter(null);
      Follow = 2;
      cJonah.Walk(cEgo.x,  cEgo.y, eNoBlock);
    }
    else if (Follow == 2) { // If Jonah is on his way to Ego's shoulder
      if (cEgo.Loop == 1 || cEgo.Loop == 0) cJonah.Baseline = cEgo.y -
1; // Or '==2' for the other shoulder
      else cJonah.Baseline = cEgo.y + 1;
      if (cJonah.Moving == false) { // Jonah is at Ego's location
        // Make sure their Loops are always the same
        cJonah.Loop = cEgo.Loop;
      }
    }
  }
  else { // If Ego is Moving
    if (Follow == 2) { // If Jonah is 'at rest'
      // Change state (the 'Follow' variable), and have him start flying free
      cJonah.FollowCharacter(cEgo,0,0);  
      Follow = 1;
    }
  }
  // End of special Following Code
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

function show_inventory_window () {
  // This demonstrates both types of inventory window - the first part is how to
  // show the built-in inventory window, the second part uses the custom one.
  // Un-comment one section or the other below.
  
  // ** DEFAULT INVENTORY WINDOW
//  InventoryScreen();

  // ** CUSTOM INVENTORY WINDOW
  gInventory.Visible = true;
  // switch to the Use cursor (to select items with)
  mouse.Mode = eModeInteract;
  // But, override the appearance to look like the arrow
  mouse.UseModeGraphic(eModePointer);

}


In AGS, open the global script and select exactly the same lengthy block you've pasted in your second to last post.
Press Ctrl-V to overwrite it.

This should fix things.

gypsysnail

Thank you thank you KrisMUC :) thats one step further for me in learning the programming. I havent forgotten what Ashen taught me dont worry ;). Ok I am going to try code now. Once its established and clear... the next step is how will I "tag" each item in each room with the active code?

And lol yes sorry KrisMUC I realise you would have been in bed, the time difference!! ;) just thought maybe others might help too that was what I was thinking.
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

Glad to be of help :)

Quote from: gypsysnail on Tue 13/11/2007 06:11:13Once its established and clear... the next step is how will I "tag" each item in each room with the active code?

That's not necessary; the text @OVERHOTSPOT@ is recognised by AGS and automatically and continually replaced by the name of the thing under the mouse.
(Unless you meant something else.)

So once everything regarding the global script is sorted out, it should work as intended immediately, provided you have entered names for all the objects, hotspots, etc.

gypsysnail

Oh ok.... what was it meant for? Umm I actually wanted text to show up next to the mouse pointer on anything that I name..... how would this be done? And what is overhotspot actually for? I cant believe I dont know what this means... :O it shows I dont know the term meanings fully yet OMG
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

Khris

Quote from: gypsysnail on Tue 13/11/2007 07:41:59Umm I actually wanted text to show up next to the mouse pointer on anything that I name.....
Did you fix the global script yet? If yes, mission accomplished.

gypsysnail

Yep fixed global script and tested game but when I point over things they dont show text - and I knew that would happen because I havent... actually written any texts for particular stuff.. like.... for example if I point my mouse pointer over a car and it says "your car".... where would I do this?
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

SMF spam blocked by CleanTalk