Text boxes with pictures?

Started by essaywrite7, Sun 18/07/2021 01:30:43

Previous topic - Next topic

essaywrite7

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

Crimson Wizard

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: ags

void DisplayDescription(int sprite, String text)
{
    // Following assumes that you have a GUI gDescription with a button btnDescPicture and a label lblDescLabel;
    // you may give your own names to these of course
    btnDescPicture.NormalGraphic = sprite;
    lblDescLabel.Text = text;
    gDescription.Visible = true;
    while (WaitMouseKey(1) == 0); // loop wait until player presses something
    gDescription.Visible = false;
}


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.

essaywrite7

Quote from: Crimson Wizard on Sun 18/07/2021 08:51:52
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: ags

void DisplayDescription(int sprite, String text)
{
    // Following assumes that you have a GUI gDescription with a button btnDescPicture and a label lblDescLabel;
    // you may give your own names to these of course
    btnDescPicture.NormalGraphic = sprite;
    lblDescLabel.Text = text;
    gDescription.Visible = true;
    while (WaitMouseKey(1) == 0); // loop wait until player presses something
    gDescription.Visible = false;
}


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

Crimson Wizard

#3
Quote from: essaywrite7 on Sun 18/07/2021 16:14:59
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: ags

import void DisplayDescription(int sprite, String text);


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


Quote from: essaywrite7 on Sun 18/07/2021 16:14:59I 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.

Khris

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: ags
function hPainting_LookAt() {  // this needs to be linked in the hotspot's event pane
  DisplayDescription(123, "It's a painting.");
}


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.

essaywrite7

Okay thank you very much for your help with this

SMF spam blocked by CleanTalk