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?
Because your function is not inside braces. It goes like this:
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.
if (hSkilt_Look == 0 ) {
Display ("blablabla");
}
if (hSkilt_Look == 1) {
player.Say ("Hello?");
}
is better.
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 :(
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...
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.
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?");
}
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!