Expected (

Started by FamousAdventurer77, Mon 30/05/2011 20:46:51

Previous topic - Next topic

FamousAdventurer77

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.

Code: ags

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.");
  }
}
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

Atelier

#1
Code: ags
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:

Code: ags
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

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


into this

Code: ags
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.

FamousAdventurer77

Ah, that's what I was missing....I had a feeling it was more than just a misplaced (. Thanks!
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

FamousAdventurer77

Er, problem...using this

Code: ags

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.
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

Khris

No it doesn't.
The problem lies somewhere else.

FamousAdventurer77

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...?  ???

Code: ags
if (oFruit.Visible = true) Display("There is no need to climb the tree.");
  I got a parse error when I tried this line.
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

ddq

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:

Code: ags
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.

Calin Leafshade

This isnt even nearly finished but it might help:

http://svn.thethoughtradar.com/AGSScript101/

Khris

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.

Atelier

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:

Code: ags
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 ???

Khris

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.

FamousAdventurer77

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.
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

McMonsterBrothers

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...?  ???

Code: ags
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:
Code: ags
if (oFruit.Visible == true); {
 Display ("There is no need to climb the tree.");

}

Gilbert

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.");
}

McMonsterBrothers

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

SMF spam blocked by CleanTalk