Random GUI's

Started by MrNashington, Wed 31/07/2013 22:26:13

Previous topic - Next topic

MrNashington

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

Khris

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.

MrNashington

But each GUI has its own decisions/choices that you make in-game which use different buttons each time.

monkey0506

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
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.

Crimson Wizard

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.

MrNashington

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. :)

monkey0506

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
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.

MrNashington

Thanks monkey :) I have it all working now.
Will credit you when the game is released.


SMF spam blocked by CleanTalk