Nested Function

Started by metalmario991, Sun 22/02/2015 00:15:58

Previous topic - Next topic

metalmario991

I keep getting this error when I try to play my game where it says room22.asc(80): Error (line 80): Nested functions not supported (you may have forgotten a closing brace)
but my line looks like this:
function hSlot2_Talk()
What is wrong?!?

metalmario991

function hSlot2_UseInv()
{
if (cEgo.ActiveInventory == iCard);
{
  if (oEvaDoor.Visible = true);
  {
    cEgo.Walk(210, 81, eBlock, eWalkableAreas);
    cEgo.FaceLocation(209, 53, eBlock);
    Wait(10);
    cEgo.FaceLocation(127, 73, eBlock);
    oEvaDoor.Visible = false;
    oKall.Visible = true;
  }
  else
   cEgo.Walk(210, 81, eBlock, eWalkableAreas);
    cEgo.FaceLocation(209, 53, eBlock);
    Wait(10);
    cEgo.FaceLocation(127, 73, eBlock);
    oEvaDoor.Visible = true;
    oKall.Visible = false;
}
else
Display("Wrong!");
}
}

Could this have something to do with it?

Gurok

#2
The error that AGS is reporting is probably due to a function that occurs before hSlot2_UseInv() in your script. There are lots of problems with the function you posted though:

Code: ags
if (cEgo.ActiveInventory == iCard);


If statements shouldn't be followed by a semicolon.

Code: ags
if (oEvaDoor.Visible = true);


The single equals sign is used for assigning to a variable. Use double equals ('==') to compare equality. Again, the if statement shouldn't have a trailing semicolon.

Code: ags
}
}


There's no matching opening brace for the second closing brace at the end of your function. It's not clear right now, but if you indent your code, errors like this become more apparent. Here's a cleaned up version of your function:

Code: ags
function hSlot2_UseInv()
{
	if(cEgo.ActiveInventory == iCard)
	{
		if(oEvaDoor.Visible == true)
		{
			cEgo.Walk(210, 81, eBlock, eWalkableAreas);
			cEgo.FaceLocation(209, 53, eBlock);
			Wait(10);
			cEgo.FaceLocation(127, 73, eBlock);
			oEvaDoor.Visible = false;
			oKall.Visible = true;
		}
		else
			cEgo.Walk(210, 81, eBlock, eWalkableAreas);
		cEgo.FaceLocation(209, 53, eBlock);
		Wait(10);
		cEgo.FaceLocation(127, 73, eBlock);
		oEvaDoor.Visible = true;
		oKall.Visible = false;
	}
	else
		Display("Wrong!");
}


Another tip: Use [code ] and [/code ] (without the spaces) tags around any code you post. It'll format your code as you see above and make it a bit easier to read. Hope this helps.

Edit: You might be able to get more help with the error if you post the function that occurs immediately before hSlot2_UseInv() in your script.
[img]http://7d4iqnx.gif;rWRLUuw.gi

metalmario991

I'm going to try this. This is my entire code for this room.

function hDood_Interact()
{
Display("Unlike many doors aboard the USS Arvaid II this one requires a code card!");
}

function hDood_Look()
{
Display("The ship's EVA suits are stored in these closets.");
}

function hDood_Talk()
{
Display("You won't get in there doing that.");
}

function hDood_UseInv()
{
if (cEgo.ActiveInventory == iCard)
{
Display("It's out of order. Also, you are doing it WRONG.");
}
else
{
  Display("That won't accomplish anything.");
}

function hSign2_Look()
{
Display("This sign indicates that this door is out of order. Too bad.");
}

function hSign2_Interact()
{
Display("No out of order sign is needed in this journey.");
}

function hSign2_Talk()
{
Display("No response will ever be gained from that.");
}

function hSign2_UseInv()
{
Display("Nothing Happens.");
}

function hSlot1_Interact()
{
cEgo.Walk(127, 79, eBlock, eWalkableAreas);
Display("You try fitting your finger into the slot but fail and feel rather sad.");
}

function hSlot1_Look()
{
Display("Code cards go in here to access the EVA suit storage.");
}

function hSlot1_Talk()
{
Display("That won't work.");
}

function hSlot1_UseInv()
{
if (cEgo.ActiveInventory == iCard)
{
  cEgo.Walk(127, 79, eBlock, eWalkableAreas);
  Display("You slip the code card into the slot.");
  Display("You miss however, the fact that the slot, quite clearly, is out of order.");
  cEgo.Say("D'oh!");
}
else
{
  Display("That won't work in the slot.");
}
function hSlot2_Talk()
{
Display("Your witty words won't open the door.");
}

function hSlot2_UseInv()
{
if (cEgo.ActiveInventory == iCard)
{
  if (oEvaDoor.Visible == true)
  {
    cEgo.Walk(210, 81, eBlock, eWalkableAreas);
    cEgo.FaceLocation(209, 53, eBlock);
    Wait(10);
    cEgo.FaceLocation(127, 73, eBlock);
    oEvaDoor.Visible = false;
    oKall.Visible = true;
  }
  else
   cEgo.Walk(210, 81, eBlock, eWalkableAreas);
    cEgo.FaceLocation(209, 53, eBlock);
    Wait(10);
    cEgo.FaceLocation(127, 73, eBlock);
    oEvaDoor.Visible = true;
    oKall.Visible = false;
}
else {
Display("Wrong!");
}

function hSlot2_Interact()
{
Display("Try something smarter.");
}

function hSlot2_Look()
{
function hSlot2_Look()
{
Display("Code cards go in here to access the EVA suit storage.");
}

}

function hCrest_Interact()
{
Display("Don't disgrace that crest, George!");
}

function hCrest_Look()
{
Display("This is a rug in the image of the Cosmo Confederation Crest Design #12. Used from 3239 to 3930.");
}

function hCrest_Talk()
{
Display("Nothing will ever respond.");
}

function hCrest_UseInv()
{
Display("Don't mess with it!");
}

function hKeiBoard_Interact()
{
cEgo.Walk(135, 185, eBlock, eWalkableAreas);
Display("You try to something with the keyboard but you have no idea what any of these buttons do so, you decide to leave them alone.");
}

function hKeiBoard_Look()
{
Display("A keyboard lies on the console.");
}

function hKeiBoard_Talk()
{
Display("STOP TALKING TO INANIMATE OBJECTS!!!");
cEgo.Say("No.");
Display("Ok.");
}

function hKeiBoard_UseInv()
{
Display("Nothing can be used there.");
}

function hConsole2_Interact()
{
cEgo.Walk(97, 155, eBlock, eWalkableAreas);
Display("You bang repeatedly on the console, never notcing the keyboard and button attached to it.");
}

function hConsole2_Look()
{
Display("A console is mounted on the southeren area of the Airlock.");
}

function hConsole2_Talk()
{
Dislay("The console ignores you.");
}

function hConsole2_UseInv()
{
Display("Why would you want to use that there?");
}

function hElen_Interact()
{
cEgo.Walk(55, 108, eBlock, eWalkableAreas);
cEgo.ChangeRoom(6, 900, 900);
}

function hHotspot13_Look()
{
Display("You are standing inside the USS Arvaid II Airlock. The scenery is different (thankfully) from the rest of the ship, though I doubt and airlock would need to look good. Why would it have to? Two doors and a console occupy this room. On the east wall is a door to the shuttle area and your escape!");
}


Do you see anything that could cause this: Failed to save room room22.crm; details below
room22.asc(29): Error (line 29): Nested functions not supported (you may have forgotten a closing brace)

Vincent

this, have no sense.

Code: ags

function hSlot2_Look()
{
function hSlot2_Look()
{
Display("Code cards go in here to access the EVA suit storage.");
}
}

metalmario991

I fixed that but I am still getting the same error.

metalmario991

Okay the error has been fixed. Everything works fine now.

SMF spam blocked by CleanTalk