Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FamousAdventurer77 on Mon 30/05/2011 20:46:51

Title: Expected (
Post by: FamousAdventurer77 on Mon 30/05/2011 20:46:51
Nitpicky detail I'm missing, where would the parentheses go in here? I can't save the room because I keep getting Expected '(' for the oFruit.Visible line.


function hFruitTree_Interact()
{
 if oFruit.Visible = true; {
 Display("There is no need to climb the tree."); }
 else {
 Display("There is no need to climb the tree. Besides, there isn't any more ripe fruit to pick anyway.");
 }
}
Title: Re: Expected (
Post by: Atelier on Mon 30/05/2011 21:00:12
function hFruitTree_Interact()
{

  if (oFruit.Visible == true) Display("There is no need to climb the tree.");

  else {
  Display("There is no need to climb the tree. Besides, there isn't any more ripe fruit to pick anyway.");
  }
}


Try this. Also, make sure you use the right amount of equal signs:

= sets, == checks

For example:

if (oFruit.Visible == true) Display("I'm checking whether Fruit is visible with two equal signs");


//player enter room, or whatever

oFruit.Visible = false; //Here I'm setting a variable because it's just one equal sign.


Notice also in my top code, you can shorten this

if oFruit.Visible = true; {
  Display("There is no need to climb the tree."); }


into this

if (oFruit.Visible = true) Display("There is no need to climb the tree.");

Because you don't need the extra { } if there's only one expression after the if statement.
Title: Re: Expected (
Post by: FamousAdventurer77 on Mon 30/05/2011 21:22:13
Ah, that's what I was missing....I had a feeling it was more than just a misplaced (. Thanks!
Title: Re: Expected (
Post by: FamousAdventurer77 on Mon 30/05/2011 21:39:56
Er, problem...using this


function hFruitTree_Interact() {
if (oFruit.Visible == true) Display ("There is no need to climb the tree.");
else {
Display("There is no need to climb the tree. Besides, there isn't any more ripe fruit to pick anyway."); }
}


turns the object invisible even though I set it to visible initially.
Title: Re: Expected (
Post by: Khris on Mon 30/05/2011 22:54:31
No it doesn't.
The problem lies somewhere else.
Title: Re: Expected (
Post by: FamousAdventurer77 on Tue 31/05/2011 02:05:48
I'm getting really confused now: I deleted that bit of code and replaced it with the old one (not the one I first posted, just a simple one-line Display message) and made sure that oFruit was initially visible in the Room's objects panel.

It still isn't when I run the test game. What went wrong...?  ???

if (oFruit.Visible = true) Display("There is no need to climb the tree.");  I got a parse error when I tried this line.
Title: Re: Expected (
Post by: ddq on Tue 31/05/2011 02:24:58
Quote from: Atelier on Mon 30/05/2011 21:00:12
Try this. Also, make sure you use the right amount of equal signs:

= sets, == checks

For example:

if (oFruit.Visible == true) Display("I'm checking whether Fruit is visible with two equal signs");

You should probably read up on some tutorials for AGS or for C-like programming languages in general.
Title: Re: Expected (
Post by: Calin Leafshade on Tue 31/05/2011 02:27:04
This isnt even nearly finished but it might help:

http://svn.thethoughtradar.com/AGSScript101/
Title: Re: Expected (
Post by: Khris on Tue 31/05/2011 02:56:09
If the object isn't visible, make sure you aren't turning it off somewhere else in the script.
It might also be off-screen or hidden behind a walkbehind.
Title: Re: Expected (
Post by: Atelier on Tue 31/05/2011 18:26:16
Quote from: ddq on Tue 31/05/2011 02:24:58
Quote from: Atelier on Mon 30/05/2011 21:00:12
Try this. Also, make sure you use the right amount of equal signs:

= sets, == checks

For example:

if (oFruit.Visible == true) Display("I'm checking whether Fruit is visible with two equal signs");

You should probably read up on some tutorials for AGS or for C-like programming languages in general.

Me or OP ???
Title: Re: Expected (
Post by: Khris on Tue 31/05/2011 18:54:45
The OP of course, ddq was quoting you to show that you already corrected the mistake.
Seems like you edited your "==" to "=" though which is wrong.

Again, = sets the variable to the left to whatever the result of the right side is.
== is used to compare two values or Strings.
Title: Re: Expected (
Post by: FamousAdventurer77 on Wed 01/06/2011 01:28:04
The culprit was a walk-behind, code works after I fixed it and plugged it back in.

Yep I could use a scripting lesson or two since I haven't done it in years, the video tutorials are pretty much the best I got right now since I tend to learn the best from being shown the basics by an actual person then figuring out the rest on my own (opposed to strictly out of a book.)

Calin- great link! Looks like the perfect thing for me to read up on.
Title: Re: Expected (
Post by: McMonsterBrothers on Wed 01/06/2011 07:15:55
Quote from: FamousAdventurer77 on Tue 31/05/2011 02:05:48
I'm getting really confused now: I deleted that bit of code and replaced it with the old one (not the one I first posted, just a simple one-line Display message) and made sure that oFruit was initially visible in the Room's objects panel.

It still isn't when I run the test game. What went wrong...?  ???

if (oFruit.Visible = true) Display("There is no need to climb the tree.");  I got a parse error when I tried this line.

i dont know if this helps but i think that you must put the {}'s in there like this:
if (oFruit.Visible == true); {
Display ("There is no need to climb the tree.");

}
Title: Re: Expected (
Post by: Gilbert on Wed 01/06/2011 07:24:20
No, if there is a single line of code you don't need the braces (though adding them there wouldn't hurt).

Also, your line shouldn't work either, as you've added a semi-colon that shouldn't be there:

if (oFruit.Visible == true); {
  Display ("There is no need to climb the tree.");
}
Title: Re: Expected (
Post by: McMonsterBrothers on Wed 01/06/2011 07:26:19
Quote from: Iceboty V7000a on Wed 01/06/2011 07:24:20
No, if there is a single line of code you don't need the braces (though adding them there wouldn't hurt).

Also, your line shouldn't work either, as you've added a semi-colon that shouldn't be there:

if (oFruit.Visible == true); {
  Display ("There is no need to climb the tree.");
}


oops my bad lol thanks dude  ;D