Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Cordate on Fri 25/09/2020 02:17:10

Title: GUI if/else statement gives a parse error
Post by: Cordate on Fri 25/09/2020 02:17:10
Hey! I tried finding other threads and tried following the help manual, but I'm still having trouble with my script. I'm trying to get the button to change the view of a character when pressed.
What I have so far is:
Code (ags) Select

function Button25_OnClick(GUIControl *control, MouseButton button)
{
  if (QDisplay.NormalView == 21)
    QDisplay.NormalView == 23;
}

Whenever I try running it I get the error "parse error at QDisplay" and nothing that I've tried so far to fix it has worked. Am I doing something wrong? Thanks in advance for the help!
Title: Re: GUI if/else statement gives a parse error
Post by: Slasher on Fri 25/09/2020 02:47:00
Code (ags) Select

function Button25_OnClick(GUIControl *control, MouseButton button)
{
if(QDisplay.View==21){
QDisplay.ChangeView(23);
// you may also need to change speech view and Idle view
QDisplay.SpeechView=speechview number;
QDisplay.SetIdleView(-1,0); // idle view number and delay
  }
}
Title: Re: GUI if/else statement gives a parse error
Post by: Cordate on Fri 25/09/2020 03:00:08
my god it actually worked! Thank you so much!
Title: Re: GUI if/else statement gives a parse error
Post by: Gilbert on Fri 25/09/2020 06:34:22
Just to clarify why the original codes won't work.
In a number of "C-like" programming languages "==" and "=" are completely different. "==" is for comparison and "=" is for assignment, so the second "==" should be the assignment "=".
BUT, as pointed out in the manual, the property NormalView of a character is read-only, so you need to use the ChangeView() function as demonstrated by slasher.