help with scripting Nested Functions not supported (you may be missing a closing

Started by Ibrahim9, Sun 04/11/2007 04:45:49

Previous topic - Next topic

Ibrahim9

Well I am very new to scrpiting, plz forgive me if this is something ez but i am trying to make the locked door and key usage kind of situation and i got a private message on how to do it, but everytime i try to test it, it says Error line 19  Nested Functions not supported (you may be missing a closing bracket) i will demonstarte.


could you find the problem plz?

// room script file
#sectionstart hotspot10_b  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot10_b() {
  // script for Hotspot 10 (Door): Look at hotspot
if (door_locked == 1) {
  player.Say("The door is locked, I need a key!");
}
else {
  player.Say("It's the door to the next room.");
}

 
{
#sectionend hotspot10_b  // DO NOT EDIT OR REMOVE THIS LINE

}
#sectionstart hotspot10_a  // DO NOT EDIT OR REMOVE THIS LINE
{
function hotspot10_a() {
  // script for Hotspot 10 (Door): Use inventory on hotspot
if (player.ActiveInventory == iKey) {
  if (door_locked == 1) }
    door_locked = 0;
    player.LoseInventory(iKey);
    player.Say("I unlocked the door");
    }
  else {
    player.Say("It is already unlocked.");
}
 
}
#sectionend hotspot10_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot10_c  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot10_c() {
  // script for Hotspot 10 (Door): Interact hotspot
if (door_locked == 1) {
  player.Say("I can't, it is locked!");
  }
else {
  player.ChangeRoom(2, 43, 174);
}
 
}
#sectionend hotspot10_c  // DO NOT EDIT OR REMOVE THIS LINE

Gilbert

This usually means you did something wrong with the braces (missing a }, too many }, etc.), try using the "match braces" feature of the script editor to check if all of they are written correctly.
I don't have time to read your acript  but at least I can find one mistake:


// room script file
#sectionstart hotspot10_b  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot10_b() {
  // script for Hotspot 10 (Door): Look at hotspot
if (door_locked == 1) {
  player.Say("The door is locked, I need a key!");
}
else {
  player.Say("It's the door to the next room.");
}

 
}  <-- wrong brace, should be a closing one
#sectionend hotspot10_b  // DO NOT EDIT OR REMOVE THIS LINE

} <-- should not be any
#sectionstart hotspot10_a  // DO NOT EDIT OR REMOVE THIS LINE
{
function hotspot10_a() {
  // script for Hotspot 10 (Door): Use inventory on hotspot
if (player.ActiveInventory == iKey) {
  if (door_locked == 1) }
    door_locked = 0;
    player.LoseInventory(iKey);
    player.Say("I unlocked the door");
    }
  else {
    player.Say("It is already unlocked.");
}
 
}
#sectionend hotspot10_a  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart hotspot10_c  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot10_c() {
  // script for Hotspot 10 (Door): Interact hotspot
if (door_locked == 1) {
  player.Say("I can't, it is locked!");
  }
else {
  player.ChangeRoom(2, 43, 174);
}
 
}
#sectionend hotspot10_c  // DO NOT EDIT OR REMOVE THIS LINE


Dualnames

I know , the rest of you might be getting annoyed by ibrahim but he's just anxious to make his game , but I 'm providing the solution. Ibrahim instead of posting here in the forums PM me , ok? Send me as many PM's as you want.
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)

Ghost

If I read the code correctly the trouble is that you copied code (that I provided) into already existing brackets.

Each function is defined the same way:

function NameOfFunction( ) {
}

Between these brackets you put your code, and if you insert conditions (like an IF statement) you also use brackets to create "blocks of code".

So it should look like this:

function DoSomething( ) {
  command;
  command;
}

and with an IF

function DoSomething( ) {
  command;
  if (something) {
    command;
    command;
  }
}

As I type this I realise that it's (apparently) almost to simple to post, but well, maybe someone else stumbles upon this and finds it useful.

And to second Jim, Ibrahim really is very eager to learn a lot, and he's holding up well. He swallowed a great deal of basic commands and seems determined to get it all right. You can only respect that.

Ghost out.

bicilotti

And if I may add a note:

a simple and nice feature of the AGS script editor is the "match brace". Place the text curson on '{' and click Ctrl + B to see highlighted the code of the function the brackets are referring to.

If the highlighted text is too long or includes something that doesn't fit with the aim of the function you'll probably have a misplaced bracket problem.

SMF spam blocked by CleanTalk