Expected (

Started by metalmario991, Sun 25/01/2015 03:25:11

Previous topic - Next topic

metalmario991

I'm getting an error in a specific function as you can see above but I can't figure out the exact location it wants me to put the (. Can anyone solve this problem?

function oCdoor_Interact()
{
if (Game.DoOnceOnly(oCdoor_Interact))
{cEgo.Walk(192, 55, eBlock, eWalkableAreas);
Display("As you move to open the door it suddenly springs open!"
Display(" 'STAY BACK!' ");
Display(" 'George! Oh thank go!' ");
Display("It's your best friend Ken!");
Display(" 'When I heard the ship was being invaded I fled down the hall and hid in the closet. I was afraid to come out but I'm glad to see you. We got outta here!' ");
cEgo.AddInventory(iKen);
}
else
{Display("TEST");
}
}
:confused:

monkey0506

Code: ags
function oCdoor_Interact()
{
  if (Game.DoOnceOnly(oCdoor_Interact)) // oCdoor_Interact is not a String variable!
  {
    cEgo.Walk(192, 55, eBlock, eWalkableAreas);
    Display("As you move to open the door it suddenly springs open!" // MISSING closing parenthesis and semicolon!
    Display(" 'STAY BACK!' ");
    Display(" 'George! Oh thank go!' ");
    Display("It's your best friend Ken!");
    Display(" 'When I heard the ship was being invaded I fled down the hall and hid in the closet. I was afraid to come out but I'm glad to see you. We got outta here!' ");
    cEgo.AddInventory(iKen);
  }
  else
  {
    Display("TEST");
  }
}


It is telling you that an opening parenthesis was expected because oCdoor_Interact is the name of a function. In AGS there's no such thing as a function-pointer, or anything like it, so when the script parser sees a function name it expects the very next character to be the opening parenthesis.

The Game.DoOnceOnly function takes a String parameter, not a function name as a callback. You could still use the name of the function if you want, but you'll have to enclose it in double quotes ("oCdoor_Interact").

You are also missing a closing parenthesis and semicolon on the fifth line of your code snippet, as I commented on above.

Here is the amended code:

Code: ags
function oCdoor_Interact()
{
  if (Game.DoOnceOnly("oCdoor_Interact"))
  {
    cEgo.Walk(192, 55, eBlock, eWalkableAreas);
    Display("As you move to open the door it suddenly springs open!");
    Display(" 'STAY BACK!' ");
    Display(" 'George! Oh thank go!' ");
    Display("It's your best friend Ken!");
    Display(" 'When I heard the ship was being invaded I fled down the hall and hid in the closet. I was afraid to come out but I'm glad to see you. We got outta here!' ");
    cEgo.AddInventory(iKen);
  }
  else
  {
    Display("TEST");
  }
}


P.S. You can format your code for forum posts by putting it between [code] and [/code] tags.

Dualnames

Also if you want to put " instead of ' you can.

I think it's
Code: AGS

Display(" \"STAY BACK!\" ");//will display "STAY BACK"
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk