run a script after / when activate a gui

Started by kantor_98, Wed 13/04/2011 21:43:41

Previous topic - Next topic

kantor_98

I still work on my "Wheel of fortune" game and I am in the following situation: I activate a GUI with consonants. Each consonant is a button. But I want that the consonants that was already used to be not active. So I will use something like a a string in which I store the fact that a latter was used or not and based on that, I will enable or not the button.
Example:
in the string consoane_folosite I store the following information: position B is corresponding to B, position 1 to C, etc. If B was used, then consoane_folosite[0] became a '*', so that in the gui I will use the sequence:

if (consoane_folosite.Chars[0]=='*') {
btn_B.Enabled = false; }

Until now I was able to use successfully the sequence in the script allocatted to the button. But that means that I HAVE TO PRESS FIRST the button, and after that it became "disabled".
I wish to run the sequence automatically, when GUI is activated, so that the corresponding buttons are already deactivated, if the case. In my example, if B was used already, I want the button B  (btn_B) to be disabled before clicking on it.

How can I run my sequence automatically when activating the GUI ?

Thank you !

Khris

Just disable the buttons in the same place in which you activate the GUI, right before making the GUI visible.

Actually, why not simply disable a consonant button after it was clicked and be done with it?
Buttons remain disabled independent of whether the GUI is visible or not.
Then you don't even have to store whether a consonant was already clicked or not; it's impossible to click a button twice using that method.

Still, if you prefer to do it your way, why not use the ascii values and a boolean array?
'B' = 66, 'Z' = 90.

Code: ags
bool used[26];  // A = 0, Z = 25

// inside the function where the GUI is turned visible

  int i = 1;  // start with B
  while (i < 26) {
    char c = i+65;   // turn i into the corresponding letter
    if (c == 'E' || c == 'I' || c == 'O' || c == 'U') {}  // do nothing
    else {
      if (used[i]) gLetters.Controls[i].Enabled = false;
      else gLetters.Controls[i].Enabled = true;
    }
    i++;
  }


Using this method, the B button must have ID 1, the C button ID 2, etc.

I'd also use a single OnClick function for all buttons, and in there call
Code: ags
  used[control.ID] = true;


Basically what I'm saying is that it's perfectly possible to avoid having 21 incarnations of the same if line or function.

kantor_98

Thank you very much for your quick reply and your suggestions !
I was not aware about the fact that I can handle buttons of a gui even when it is not visible !
It is not easy to use the ascii because in my language there are also some diacritics (see also the post
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=43094.0)

But I think I will have success following your sugestions.
Thank you again - I promiss to keep you informed about my work !

SMF spam blocked by CleanTalk