Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Inglov on Sun 10/09/2017 13:34:58

Title: SOLVED Error: expected '(' please help :)
Post by: Inglov on Sun 10/09/2017 13:34:58
Hi! I am new here, and I have a problem with my script.
I am testing out "if", and I have no idea what I am doing wrong here.

When I try this:

function hSkilt_Look()
    if (hSkilt_Look == 0 ) Display ("blablabla"); (This is line 21)
    if (hSkilt_Look == 1) player.Say ("Hello?");

I get the error message: Error (line 21): Expected '('

Can someone please help me with this?
Title: Re: Error: expected '(' please help :)
Post by: Kara Jo Kalinowski on Sun 10/09/2017 13:44:21
Because your function is not inside braces. It goes like this:

Code (ags) Select
function hSkilt_Look() {
    if (hSkilt_Look == 0 ) Display ("blablabla"); (This is line 21)
    if (hSkilt_Look == 1) player.Say ("Hello?");
}


The braces tell the compiler what is part of the function.

Likewise your if statements are not technically wrong, but including them in braces makes your code more maintainable in case you want to add more statements as part of the if statement later.

Code (ags) Select
if (hSkilt_Look == 0 ) {
    Display ("blablabla");
}
if (hSkilt_Look == 1) {
    player.Say ("Hello?");
}


is better.

Title: Re: Error: expected '(' please help :)
Post by: Inglov on Sun 10/09/2017 16:32:52
Oops, I forgot to put the braces here, but they are in my script. Any other reason this error comes up?
My script looks exactly like you wrote now, but I still get the error :(
Title: Re: Error: expected '(' please help :)
Post by: Cassiebsg on Sun 10/09/2017 17:18:46
Uhm...

hSkilt_Look is a function and you checking it for 0 and 1? ???

Where exactly are you giving it these values? I'm guessing that AGS is expecting this line if (hSkilt_Look == 0 ) to look like if (hSkilt_Look() == 0 ) ...

But I don't understand where/how exactly you expect it to give you 0 and 1... but I'm no experience coder, so...
Title: Re: Error: expected '(' please help :)
Post by: Crimson Wizard on Sun 10/09/2017 18:00:09
Definitely, as Cassiebsg noted, you are comparing function name hSkilt_Look to a number. That COULD make sense if that function had any meaningful return value, but it does not in this case (besides calling hSkilt_Look from hSkilt_Look will cause infinite recoursion).

In other words, your code does not make actual sense. You need to explain what you are trying to find out with these "if" checks.
Title: Re: Error: expected '(' please help :)
Post by: Khris on Sun 10/09/2017 20:32:56
He isn't even comparing the result of a call, he's using the function's name, without ().

It seems like the goal here is to show a new message on the second click. This requires a counter variable, like this:

int skilt_looked = 0; // initial value

function hSkilt_Look() {
  if (skilt_looked == 0) {
    Display ("blablabla");
    skilt_looked++;
  }
  else if (skilt_looked == 1) player.Say ("Hello?");
}
Title: Re: SOLVED Error: expected '(' please help :)
Post by: Inglov on Mon 11/09/2017 10:11:06
Ah, okay! I totally misunderstood the manual. I did not make the "int" as I thought the hotspot would be the int and would automatically be counted if I wrote == 0 == 1 and so on.

Thank you!