Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: on Tue 05/08/2003 19:41:07

Title: GUI problems
Post by: on Tue 05/08/2003 19:41:07
Hello there. I have a problem with the GUIs. I want to make a new GUI with two buttons:
 if (interface == 3)
   if (button == 0)
     GUIOn (4);
   else if (button == 1)
     GUIOff (3);
   )
 )
when i write this, save it and test the game nothing seems to happen. several times i even received some errors.
I'd appreshiate it if someone helps.
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Tue 05/08/2003 20:25:47
Be sure that you go to the GUI settings and 1) make the GUI clickable and 2) be sure that each button is set up to "Run Script", otherwise it won't do anything when they're clicked on.

BTW if you're making a GUI turn on another GUI, you my want to have it first turn off the current GUI and pass a Wait(); command, otherwise the new GUI will overlay the old one and it may look kind of messy.  That's just an asethetic suggestion, though.

~Wolfgang
Title: Re:GUI problems
Post by: MachineElf on Tue 05/08/2003 20:48:19
As Wolfgang said, make sure their clickable and set to "run script".

What seems wrong in your code, however, is probably the brackets.
This is what your code is supposed to look like (of course make sure all this is in the interface_click function...):

   if (interface == 3)
   {
           if (button == 0)
                 GUIOn (4);
           else if (button == 1)
                 GUIOff (3);
   }


About what Wolfgang said about turning off GUIs: The Wait() command is not necessary. All you need to do is:
GUIOff (3);
GUIOn (4);
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Tue 05/08/2003 22:07:44
Actually, in my experience, if I don't put a Wait(1); between the GUIOff() and GUIOn() lines, it'll "turn off" the first GUI, but won't actually clear it from the screen before it turns on the second GUI.  Functionally, it's fine, but aesthetically it's kind of bad.  I guess the script runs faster than the screen refresh rate for me.  *shrugs*

~Wolfgang
Title: Re:GUI problems
Post by: MachineElf on Tue 05/08/2003 23:19:29
I'm not quite sure what you mean...
If you don't have the wait command the GUIOff and On will be run practically at the same time, leaving nothing of the old gui shown when the new is turned on. If this is what you meant I can't really see what is more aesthetical about having a short, probably unnoticable, pause between the commands than just having the GUIs switch places at the same time. Or am I misunderstanding you?
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Tue 05/08/2003 23:50:43
Ah, I see what you mean.  The reason I had to add the Wait(1); was because the two different GUIs were either different sizes or I had them popup at different locations, so the new one would overlap the old one without covering it completely and you'd be able to see the uncovered part of the old GUI under the new one.  The Wait(1); command I put in there allowed enough time for the screen to clear the old GUI before putting the new one up.  Obviously, if the new GUI completely covers the old one then the Wait(); is not necessary.

Sorry about the confusion! ;D

~Wolfgang
Title: Re:GUI problems
Post by: on Wed 06/08/2003 05:42:46
Thank you, but nothing happens. Now the script is correct, but the gui is not interactable. Should I write something after the "GUIOff (3)" part, to make the game return to the main screen? Or is it something about the properties menu?
It looks something like this:
GUI 3 Object 0 (Button)
Image   (None)
Mouseover image   (None)
Pushed image (None)
(...)
Text   Enter
(...)
Left Click   Run Script
New mode number   N/A
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Wed 06/08/2003 07:25:39
Hmm, that should work.  Like MachineElf said, make sure these are all in the interface_click function.


function interface_click(int interface, int button);
if (interface == 3) {
 if (button == 0) {
   GUIOn(4);
 }
 if (button == 1) {
   GUIOff(3);
 }
}


And make sure both the buttons are set to "Run Script" as left-click (like you do for button 0), and make sure the GUI itself is set to clickable (there's a tickbox on the top of the GUI options tab for each GUI).  Aside from that, it should work.  I have something similar to that in mine and it works just fine.  *shrugs*

Edit:  And, no, you shouldn't have to write anything after the GUIOff(3); to go back to the main screen.  I'm curious, though...why do you have a couple of things as (...) there?  Those are the width/height, and font/text colour for the button.  Maybe you need to specify a width and height for the button (or did you just not include the values in your post)?

~Wolfgang
Title: Re:GUI problems
Post by: MachineElf on Wed 06/08/2003 10:58:39
So you actually mean that the GUI you turn off is still on screen when you turn on the new one? When is it then turned off? This sounds very strange, actually, as I've never encountered something quite like this.
In a script that goes:
GUIOff (1);
GUIOn (2);
GUI 1 should be turned off before GUI 2 is turned on and leave no traces on screen no matter if it's bigger or not.
Are you absolutely sure this is the case? If so, something else must be wrong...
Title: Re:GUI problems
Post by: Ishmael on Wed 06/08/2003 11:00:02
I had to use the Wait(1); so the GUIs didn't stay on the screen when new ones were turned on...
Title: Re:GUI problems
Post by: MachineElf on Wed 06/08/2003 11:24:03
Hm, ok. Still think it's strange. Although I'm not going to 'solve' this, just out of curiousity, when do they turn off?
Title: Re:GUI problems
Post by: on Wed 06/08/2003 18:54:51
So, thanks for your help! I've found and fixed the problem. It actually turned out not to be that huge. The monitor resolution I'm working in is 1280x1024p so there is no big difference between "(" and "{". For some reasons I changed the resolution to 640x480p and saw my mistake. Sorry for bothering you... and my terrible english.
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Wed 06/08/2003 19:19:59
It turns off the next time you interact with the "new" GUI, either by pressing a button or turning it off also (basically, anytime something happens that forces the screen to refresh itself).  I'm guessing that when the new GUI turns on immediately after the old one is turned off, since there's no pause inbetween, the screen does not redraw in that amount of time.  Note that the old GUI isn't interactive at all, so any buttons on it that may still be visible are no longer clickable, etc. which means that the game code has turned off the GUI, but it just shows the graphic so the monitor still thinks it's there (at least, in part). Putting the Wait(1); in there allows the screen time enough to redraw itself (without the old GUI on it) before putting up the new GUI.  That's just a guess, though.

~Wolfgang
Title: Re:GUI problems
Post by: Pumaman on Wed 06/08/2003 19:43:43
Hmm, odd - so are you saying that if you turn off one popup modal GUI, but simultaneously turn on another one, the old one doesn't get erased?
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Wed 06/08/2003 20:02:33
Correct.  A code as such:

GUIOff(3);
GUIOn(4);

will turn on GUI 4, make it interactive, and overlay it on top of the graphic for GUI 3, and make GUI 3 un-interactive.  The graphic for GUI 3 won't clear from the screen until something else happens, that makes the screen refresh (again, just a guess at that part).  In fact, it may be possible by making a handful of GUIs whose only purpose is turning on other GUIs, and seeing if you can "stack" GUI graphics as such.  Like have a button on GUI 3:

GUIOff(3);
GUIOn(4);

then make one on GUI 4:

GUIOff(4);
GUIOn(5);

etc. and have each consecutive GUI be either a smaller size or popup in a different location than the preceding one.  I don't know if that would work as I've never tried it, but it would illustrate the point if it does.

~Wolfgang
Title: Re:GUI problems
Post by: Gankkizz on Wed 06/08/2003 21:01:40
I did a small script:

if (interface == 4) {
 if (button == 0) {
   GUIOff(4);
   GUIOff(3);
 }
}

And it worked out just fine. GUI 4 didn't leave on the screen

---EDIT---
Maybe something like an animation causes it leave on the screen in your game.
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Wed 06/08/2003 22:52:05
if (interface == 4) {
if (button == 0) {
GUIOff(4);
GUIOff(3);

}
}

That's because that code turns off both GUIs.  The problem only arises when one is turned off and another one is turned on immediately thereafter.  IIRC it works if you turn off a GUI and display a message at the same time as well.  Like:

GUIOff(3);
Display("Hello there.");

I think I did something like that once and it had the same problem, but don't quote me on that.

~Wolfgang
Title: Re:GUI problems
Post by: MachineElf on Thu 07/08/2003 01:04:01
Hm, that is odd, Wolfgang. I haven't at all encountered that, but that may be because I usually out something more in the scripts than just those two lines.
What happens if you put just _anything_ between or after the GUI commands? Like this, which basically does nothing:

int test;
GUIOff (1);
GUIOn (2);
test = test;

or put it between the two.

Also, what happens if you turn on a GUI with a lower id, and therefor, if both were to be turned on, would overlap the other? Does the old still overlap the new although it remains non-interactive?
Title: Re:GUI problems
Post by: Wolfgang Abenteuer on Thu 07/08/2003 04:09:43
...Alright...now it's not doing it.  Urgh...I'm absolutely positive it used to do it to me, but for some reason it's not doing it now!  Well, time for the men in white coats to take me away, I guess! :p  Sorry about the hassle, guys!

~Wolfgang
Title: Re:GUI problems
Post by: Gankkizz on Thu 07/08/2003 21:10:25
Sorry about that... I wrote it wrong only in my reply. The code was GUIOff(4); GUIOn(3); and it worked fine with me
Title: Re:GUI problems
Post by: Pumaman on Fri 08/08/2003 16:45:43
I haven't been able to replicate this either. If it happens to you again though, do let me know.