Jibble

A redesign of the AGS site is now ready to be implemented! Please help us with art and content.

Author Topic: Text boxes with pictures?  (Read 234 times)

Text boxes with pictures?
« on: 18 Jul 2021, 01:30 »
I’ve been looking for a way to make a text box pop up with a picture, for when the character looks at a hotspot object. You can see a description of the object, plus a picture to go with it. I did some searching, but I can’t find anything that will combine both text and picture

Thank you for your help

Re: Text boxes with pictures?
« Reply #1 on: 18 Jul 2021, 08:51 »
Make GUI with a button for picture and a label for a text. And anything else more you might need.

Then write a function that displays that GUI, waits for player's input and hides GUI.

Code: Adventure Game Studio
  1. void DisplayDescription(int sprite, String text)
  2. {
  3.     // Following assumes that you have a GUI gDescription with a button btnDescPicture and a label lblDescLabel;
  4.     // you may give your own names to these of course
  5.     btnDescPicture.NormalGraphic = sprite;
  6.     lblDescLabel.Text = text;
  7.     gDescription.Visible = true;
  8.     while (WaitMouseKey(1) == 0); // loop wait until player presses something
  9.     gDescription.Visible = false;
  10. }
  11.  

Amend the above code to your needs, like add coordinates as parameters, or calculate position to center on screen, or around the mouse cursor, and so on.

Re: Text boxes with pictures?
« Reply #2 on: 18 Jul 2021, 16:14 »
Make GUI with a button for picture and a label for a text. And anything else more you might need.

Then write a function that displays that GUI, waits for player's input and hides GUI.

Code: Adventure Game Studio
  1. void DisplayDescription(int sprite, String text)
  2. {
  3.     // Following assumes that you have a GUI gDescription with a button btnDescPicture and a label lblDescLabel;
  4.     // you may give your own names to these of course
  5.     btnDescPicture.NormalGraphic = sprite;
  6.     lblDescLabel.Text = text;
  7.     gDescription.Visible = true;
  8.     while (WaitMouseKey(1) == 0); // loop wait until player presses something
  9.     gDescription.Visible = false;
  10. }
  11.  

Amend the above code to your needs, like add coordinates as parameters, or calculate position to center on screen, or around the mouse cursor, and so on.

Thank you for this. When I try to implement it. It won't allow me to include it when the character goes to look at an object, because it says it cannot have a nested function. I tried having it outside the look object function, but then it has the GUI launch and stay up on the screen from the moment the game starts.

Please let me know your thoughts.
Thank you

Re: Text boxes with pictures?
« Reply #3 on: 18 Jul 2021, 17:07 »
Thank you for this. When I try to implement it. It won't allow me to include it when the character goes to look at an object, because it says it cannot have a nested function.

Yes of course, all functions should be separate, not inside each other.
It's best to have this function in the GlobalScript script, declare it in the header as:
Code: Adventure Game Studio
  1. import void DisplayDescription(int sprite, String text);
  2.  

Then you can call it from anywhere else like any other standard function.


I tried having it outside the look object function, but then it has the GUI launch and stay up on the screen from the moment the game starts.

GUI should have Visible set to false in the editor to start hidden.
« Last Edit: 18 Jul 2021, 17:09 by Crimson Wizard »

Re: Text boxes with pictures?
« Reply #4 on: 19 Jul 2021, 08:42 »
To be very clear: the function goes into the main Global script, not the header.
Then you add that import line to the Global script's header; that way you can use the function inside room scripts.
You call it like this:

Code: Adventure Game Studio
  1. function hPainting_LookAt() {  // this needs to be linked in the hotspot's event pane
  2.   DisplayDescription(123, "It's a painting.");
  3. }

This one line is all you need to use the function. That is the point of a function: to not have duplicate code all over the place.

Re: Text boxes with pictures?
« Reply #5 on: 19 Jul 2021, 17:46 »
Okay thank you very much for your help with this