Displaying random text in a quit menu

Started by Wicked, Sun 14/09/2014 04:24:42

Previous topic - Next topic

Wicked

Hi im trying to display the random text in a quit menu,without the text locking me out of choosing a option and disappearing? Thank you

monkey0506

This is a pretty common question, actually. Typically you'd do something like this:

Code: ags
int ran = Random(5);
if (ran == 0) lblQuit.Text = "Are you sure you want to quit?";
else if (ran == 1) lblQuit.Text = "You're giving up already?";
// ...
else if (ran == 4) lblQuit.Text = "Can't take it any more?";

Wicked

sorry, I tried looking around but couldnt find other posts, sorry that didnt work what does 1blquit does beacuse its giving me a error.

Slasher

Hi,

lblQuit is the name that monkey_05_06 gave to the text label that displays the text.

The label name you have can be named anything as long as it reflects the same name in the script.

For now name the label: lblQuit and script as monkey_05_06 has showed and implement it on the button so that when it is clicked the random text will display.

;)

Crimson Wizard

I still do not think that this clearly answers the Horrorfiend's question :).

Idea is to create your own GUI that will have a label and two (or more) buttons, like "Yes" and "No".
Upon making GUI visible you set up its label text the way you wish. Depending on what you mean by "random"... if you mean, it should be taken at random from some list, then use monkey_05_06's suggestion.
Then you should create functions for handling button clicks (same way as you create function for hotspots etc).
In "Yes" function you should probably do just "QuitGame(0)" to quit without asking more questions.
In "No" function you hide the GUI.

I do not really understand what you mean by "without the text locking me out of choosing a option and disappearing"... Please, elaborate.

Gurok

Quote from: Crimson Wizard on Sun 14/09/2014 12:50:28
I do not really understand what you mean by "without the text locking me out of choosing a option and disappearing"... Please, elaborate.

I think he might mean using Display("") which shows the text, but locks you out of interacting with rest of the interface and then disappears. Rather odd way to describe it though.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Wicked

#6
Sorry I should have described it better,I have a bad tenancy of that.  I created my own GUI for the quit menu and created the yes or no, and wanted to add about 10 to 15 of my own quirky lines and they would be randomly chosen out and  put in the box, I wanted each line in the box to  stay while the player chooses instead of locking the player out and disappearing when they click.

Sorry about the confusion im a newb at coding I have learned alot through comming here and reading posts and checking out youtube videos

Slasher

In that case add the label script to the Quit button BEFORE your new Quit Game GUI opens. That way the label will already be changed to the random text and be displayed.

I use this method all the time in various instances.






Wicked

#8
Thanks for the help, sorry took me a while to understand I forgot there was a button to make labels in the gui up top, my brain is slow. thanks again

monkey0506

Quote from: Horrorfiend on Sun 14/09/2014 08:06:11sorry that didnt work what does 1blquit does beacuse its giving me a error.

While this is the beginner's help forum, there are still certain measures which are generally expected of you to take before you post asking for help. I won't reiterate the entire list of rules for this forum, but the three most basic expectations we (those trying to help you) are:

1. That you have read the manual (at least looked for pertinent entries).

It's not always simple to find exactly what you're looking for, but the answer I gave you (which seems to have been what you were looking for) is almost identical to the example the manual gives for the Random function.

2. That you have tried searching the forums.

Searching for "random message" yields 4 pages of results. Some of them are out-of-date, but the basic concept behind the first result in the list is still the same, and the manual redirects you to the appropriate properties/functions for those same commands.

3. That you have a basic concept of how programming works.

Simply put, you're not going to be able to make a game in AGS without doing some programming. Simply reading through the scripting tutorial (in the manual!) should give you some idea that if you see something like "lblQuit", then it's probably referring to some entity in your game. It's not enforced or even provided as the default for new controls, but the prefix "lbl" is conventional (not just in AGS) to indicate that you are referring to a GUI Label control named "Quit". If you can't comprehend programming well enough to make interpretations such as this from variable names, then you need to take a step back and learn some programming basics first. I'm not saying this to be rude, but as I said, programming is an essential requirement for making games in AGS. Understanding concepts like this (especially after a meaningful error message was raised) is one of the most basic and fundamental parts of programming.

I'm not saying this to be rude, but in the sincere hope that you actually take it to heart. I'm not meaning to berate or belittle you, but this thread has gone downhill very, very fast.

Quote from: Horrorfiend on Sun 14/09/2014 17:07:53Thanks for the help, sorry took me a while to understand I forgot there was a button to make labels in the gui up top, my brain is slow. thanks again

From this I'm not sure you've understood slasher's meaning. He wasn't talking about adding controls to your GUI in the editor at design-time. He was telling you to call the code earlier on at run-time. This is another misunderstanding predicated by your lack of understanding for basic programming concepts. Essentially, it should look something like this:

Code: ags
function btnQuit_OnClick(GUIControl *control, MouseButton button)
{
  int ran = Random(5);
  if (ran == 0) lblQuit.Text = "Are you sure you want to quit?";
  else if (ran == 1) lblQuit.Text = "You're giving up already?";
  // ...
  else if (ran == 4) lblQuit.Text = "Can't take it any more?";
  gQuit.Visible = true;
}


Obviously this will not work out-of-the-box, especially not if you just cut and paste it. You have to understand what it's doing first. This is an event handler for when the GUI Button btnQuit is clicked on by the player. btnQuit would probably be a button on your Menu GUI. The event handler has to be linked in the Events pane of the button's properties (select the button in the editor, and click the lightning bolt icon in the Properties pane -- you can then click the ellipses ("...") button for the event to automatically create an empty event handler for it) or it will not be called. I've also reused the same code I gave you previously to illustrate the point of how it is meant to be used. lblQuit is not some built-in function, but represents your GUI Label control on your Quit GUI. Similarly, gQuit doesn't exist either, but represents your Quit GUI. What this code does, when properly implemented, is set the label text to one of a set of messages at random, and then displays the Quit GUI, showing the message on a GUI Label and containing GUI Buttons for the player's Yes or No response.

This cannot be made more clear, so if this doesn't make immediate sense, please take the time to understand it before moving on.

SMF spam blocked by CleanTalk