GUI scripting Update for newest AGS version

Started by heirofmaul, Wed 28/03/2007 12:23:47

Previous topic - Next topic

heirofmaul

Alright, I know I'm a bit behind the crowd on this, but what more needs to be updated in this script (for a quit GUI, if you couldn't tell) to get things right...

#sectionstart btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconExit_Click(GUIControl *control, MouseButton button) {
 
   gQuitgui.Visible = true;
 
   if gQuitgui.Visible = true{
      if(Button == 0){
         QuitGame(0);
      }
   if(Button == 1){
      gQuitgui.Visible = false;
      }
   }
   
}

#sectionend btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE

I'm getting an error message when I try to test or save saying: Error (line 143): expected '('.  Line 143 is the first "if" statement, the   " if gQuitgui.Visible = true{ "   bit.  I'd appreciate anyone to fill me in on this in good detail.  Thanks.   ;D

GarageGothic

#1
The problem is the missing parentheses, as AGS itself points out. Try:

Code: ags
if (gQuitgui.Visible == true) {


note that you also need "==" instead of just "=" when writing if statements.
Also, and I'm not sure this is necessary, but you should probably use lowercase "button" to be consistent with the function.

Ashen

#2
GG covered some of this while I was typing, but I'll post it for the rest:

The condition part of if statements need to go inside  ( )'s - like the two if (button == lines. Line 143 is missing them. AGS expects it, it's not there - hence the error.

However, the whole thing is wrong, in a couple of ways.
1) The button parameter in the function declaration has a lower case b. The two ]if... statements use upper case. AGS is case-sensitive, so these need to be consistant.

2) Conditional checks use '=='. A single = is for setting a vaue. So, it'd be:
Code: ags

if (gQuitgui.Visible == true){

NOT (as you've got):
Code: ags

if gQuitgui.Visible = true{


3)Why are the QuitGUI button commands in the btnIconExit_Click function? They should have their own functions.
Even if you've set the Quit/Play buttons to run btnIconExit_Click, the way you've set it up is wrong. button refers to the Mouse Button pressed, NOT the GUIControl Button (e.g. btnIconExit), and 0 isn't a valid value for that - I'm not sure what you're trying to achieve. However this might be close:
Code: ags

#sectionstart btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnIconExit_Click(GUIControl *control, MouseButton button) {
 
   if (control == btnIconExit) {
     gQuitgui.Visible = true;
   }
 
   else if (control == btnQuit) {
     QuitGame(0);
    }
   else if (control == btnPlay) {
     gQuigui.Visible = false;
   }
}
#sectionend btnIconExit_Click  // DO NOT EDIT OR REMOVE THIS LINE

(Assuming btnQuit, btnPlay are the buttons on the Quit GUI, and they're both set to run btnIconExit_Click.)
I know what you're thinking ... Don't think that.

heirofmaul

Thanks Ashen, you exlpained a good bit to me, but everything's not quite ship-shape yet.  See, what I was doing was following the AGS tutorials, getting a feel for everything, and I did the scripting tutorial http://www.adventuregamestudio.co.uk/actutor.htm (which I know now is essentially obsolete) and the "custom Quit GUI" tutorial http://www.adventuregamestudio.co.uk/actutgui1.htm (also out of date, apparently).

I don't know if you are/were familiar with those tutorials, but it isn't explained how to update the scripting to the newest version of AGS.  Even after checking as many functions updates in the help index as I could find, my coding is still (obviously) not fully right.

So, as I was just trying to follow a simple tutorial, I'm kinda in the dark now about how to go about getting this cleared up.  The step (in the tutorial) of simply editing the script of the GUI is now an obsolete function.  So I just did my best to place everything in the global script, which is why things are in odd places.

So Ashen, since you seem to really know your stuff, do you think you could (when you get the chance and if you feel up to it) peruse the GUI tutorial (I followed it exactly) and tell me the CORRECT step-by-step way to do what the tutorial is trying to teach me?  I'd really appreciate.  Thanks.

Ashen

#4
OK, I know there was an up-to-date Quit GUI tutorial somewhere, but I can't seem to find it ... Looking up ANY new GUI tutorial should give you an understanding of how they work now, though.

The basics of making a GUI with working buttons:
- Make your GUI in the editor (set the size and position, add the buttons, select graphics, etc - this bit should be pretty clear).
- Select a button. Notice that the first line of the floating properties window now says 'Script Name'. Double click that, and give the button a script name.
- Now double click the button. If necessary, click 'OK' to confirm the script function name. The default function name will be (Button name)_Click, but you don't HAVE to accept the default Control function name, if you'd find another more meaningfull. This also means you can have several Buttons running the same function - if, for example you had multiple GUIs with Quit buttons on them, you could set them all to Quit_Click rather than repeating the same code for each of them. (Or, if you use the btnIconQuit_Click from my last post, you could call it from the QuitGUI buttons to.)
You should now be in the Script Editor, at the Control function for your button. Add whatever code you want the button to run (see below).
- Exit & save changes. The Button should now work - repeat this for all the buttons on the GUI (note that each button must have a unique name).

What code you want to run depends (understandably) on what you want the button to do. You've got the right code (QuitGame(0); gQuitgui.Visible = false;), you just needed the right place to put it.
I know what you're thinking ... Don't think that.

heirofmaul

Awesome, with a bit of patience and tweaking it worked!

Thanks a lot, Ashen.  You really saved me here and did a great job explaining.  'preciate it!  ;D

SMF spam blocked by CleanTalk