"If GUI button is pressed while label is visible" error.

Started by Global Lint, Fri 28/03/2008 01:47:58

Previous topic - Next topic

Global Lint

Since this forum is for simple scripting questions...

The best way I can explain my Bible GUI is to compare it with the one in Captain Bible, if any of you have ever played it.  As you can see, though, it's not quite finished...

(I'll give you a little visual of how I'd like the game to function during the script below, since that might clear up some how's and to-what-end's:  When the player clicks on cD1 (char Demon 1), the demon says "Shall we...?"  The demon tells you a lie, and a GUI Bible pops up.  From one side of the Bible there is a list of buttons labeled "2 Corinthians 6:14-17", "Romans 7:18", and so forth.  On the right side are a bunch of labels, initially invisible, which become visible when a topic is chosen from the left side.  These labels are the actual verse, written out, such as "2 Corinthians 6:14-17: For what do righteousness and wickedness have in common..." When you think you have the right verse, button1, which says "Use", should be clicked, and then that should, for now, display whether you chose the right verse or not to counterattack the demon's lie.)

So IF button one is pressed WHILE label one is visible, the game should display "right answer, should be working".  But, well, when it comes to scripting, I'm a dunce.  The error message is "parse error in expr near 'int'." That would be the line that starts with 'if'.

Here's my flawed scripting.  My thanks to anyone who can tell me what I'm doing wrong:

function cD1_AnyClick()
{
cD1.Say("Shall we match wits, human?");
gBible.Visible = true;
if (function Button1_OnClick(GUIControl *control, MouseButton button) while Label1.Visible = true) {
Display("right answer, should be working.");
}
else {
  Display("wrong answer");
}
Spaz ate the dopefish.

Khris

Umm, interesting game...

Code: ags
function cD1_AnyClick() {
  cD1.Say("Shall we match wits, human?");
  // *
  gBible.Visible = true;
}

function Button1_OnClick(GUIControl *control, MouseButton button) {
  if (Label1.Visible) Display("right answer, should be working.");
  else Display("Wrong answer.");
}


* You'll need code here to initialize the GUI. (Code that turns all labels back to invisible, in this case.)
Plus, you have to somehow disable the Use button until the player has chosen one of the books. Either turn it visible only after a click on one of the book buttons or set a variable and check for that in Button1_OnClick.

Global Lint

The labels are initially invisible already: I set them to begin as invisible in the global script.

I don't want the Use button to be unavailable if the label is the wrong answer, I want it to be available, but if it is pressed while the wrong label is on screen, it should display "wrong answer". 

I'll experiment a bit more with the code you gave me.

EDIT-  Okay, here is the code I've edited.  It's not giving me any error messages, but nothing is happening when I press the 'use' button while label 1 is visible.

Code: ags
function cD1_AnyClick()
{
  cD1.Say("Shall we match wits, human?");
  // * Code that turns all labels back to invisible:
  Label1.Visible = false;
Label2.Visible = false;
Label3.Visible = false;
Label4.Visible = false;
Label5.Visible = false;
Label6.Visible = false;
Label7.Visible = false;
Label8.Visible = false;
Label9.Visible = false;
Label10.Visible = false;
  
  gBible.Visible = true;
}

function Button1_OnClick(GUIControl *control, MouseButton button) {
  if (Label1.Visible) {
  gBible.Visible = false;
  Display("right answer, should be working.");
}
  else { Display("Wrong answer.");
}} 


And here's my rough GUI (I'm more concerned about making it work for now than making it pretty):

Spaz ate the dopefish.

Pumaman

Is your Button1 script hooked up correctly? ie. did you add it by double-clicking the control in the GUI editor, or did you manually paste it into your script?

If you paste it in manually that won't actually hook it up to the button -- select the button in the GUI editor and check its Events tab to make sure.

Global Lint



EDIT:

All right, everything was going pretty well until I tried to make the second demon in another room.  I used the same code, only I used it on demon2; but it gave me this:

GlobalScript.asc(270): Error (line 270): Variable 'Button1_OnClick' is already defined

Which I suppose means that it doesn't like the fact that 'Button1_Onclick' was used earlier in the global script.

Spaz ate the dopefish.

Global Lint

I know double posting isn't a good idea.  I'm sorry.  But I'm trying to get some questions answered so I can move forward with this project.
Spaz ate the dopefish.

Khris

You can't use the same function twice, how is AGS supposed to know which one to call?
Instead, do a check for the game situation inside the function.
Usually, this is done using variables; in your case, you can use player.Room to determine the room the player is in.
Code: ags
function Button1_Click(...) {

  if (player.Room == 1) {
    ...
  }
  else if (player.Room == 2) {
    ...
  }
  ...
}

SMF spam blocked by CleanTalk