Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: MrNashington on Wed 31/07/2013 22:26:13

Title: Random GUI's
Post by: MrNashington on Wed 31/07/2013 22:26:13
Hello!

I have been struggling for a few hours trying to figure out how to make a system where every 5 minutes a random GUI pops up.
I am trying to make a random Letter/Quests mechanic where the different random GUI's will pop up on screen after a certain amount of time.
But how will I make it random for GUI's?

I'm basically aiming for this, but for GUI's not text:

Quote
String _fortune[20];
_fortune[0] = "Tonight you will find new love";
_fortune[1] = "Stay with your wife";
...


And then in the hotspots on_click you can randomly choose one string:

int ran = Random(19);
Display(_fortune[ran]);

Thanks alot, Charlie
Title: Re: Random GUI's
Post by: Khris on Wed 31/07/2013 23:19:56
Just use one GUI, add a label to it, and set the label's text to the randomly chosen string.
You don't need 20 GUIs just to display 20 different texts.
Title: Re: Random GUI's
Post by: MrNashington on Thu 01/08/2013 00:13:22
But each GUI has its own decisions/choices that you make in-game which use different buttons each time.
Title: Re: Random GUI's
Post by: monkey0506 on Thu 01/08/2013 02:22:07
Not saying you should (as I think Khris is probably pointing in the right direction), but if you really wanted to select a random GUI:

Code (ags) Select
GUI *firstRandomGUI = gRandom0; // the first of the randomly displayed GUIs
int randomGUICount = 10; // the number of randomly displayed GUIs
gui[Random(randomGUICount - 1) + firstRandomGUI.ID].Visible = true;


I did "randomGUICount - 1" because Random returns a value between 0 and X inclusive, so if you have 10 total random GUIs, then the range to offset the ID of the first should be 0-9, not 0-10. Oh, and this assumes that all the randomly displayed GUIs are sequentially ordered.
Title: Re: Random GUI's
Post by: Crimson Wizard on Thu 01/08/2013 09:53:36
Quote from: MrNashington on Thu 01/08/2013 00:13:22
But each GUI has its own decisions/choices that you make in-game which use different buttons each time.
Can you elaborate this; do you mean that button texts/images should be different? In such case you may change those texts/graphics accordingly when the gui is about to be displayed.
Title: Re: Random GUI's
Post by: MrNashington on Thu 01/08/2013 12:38:13
Thanks monkey, will give that a go now :)

Crimson: Yeah, each GUI has there own different backgrounds, buttons which lead to outcomes, different sizes, and of course different texts. This is why I thought I should pursue launching random GUI's instead of the same one with different properties. :)
Title: Re: Random GUI's
Post by: monkey0506 on Thu 01/08/2013 21:14:10
If he wants to have more GUIs let him have more GUIs. :P He can have as many as he wants.

As to the code, it's the same basic logic. I just accessed the gui array instead of a custom array of Strings. If you want you could also keep track of which GUI is displayed by changing that last line to:

Code (ags) Select
GUI *randomGUI = gui[Random(randomGUICount - 1) + firstRandomGUI.ID];
randomGUI.Visible = true;


And the "firstRandomGUI" bit isn't strictly necessary, but it could allow you to have different categories of quests and such. Just seed the first GUI for each category and the number of GUIs in that category.
Title: Re: Random GUI's
Post by: MrNashington on Fri 02/08/2013 12:51:48
Thanks monkey :) I have it all working now.
Will credit you when the game is released.