Variable Trouble within dialogue request

Started by mysticjim, Fri 01/12/2006 21:58:02

Previous topic - Next topic

mysticjim

I've obviously done something daft here, can anyone help?

I've defined an int called gamelevel in the global script, exported it and then imported to all rooms in the script header.

e.g.

// main global script file

int gamelevel = 0;
export gamelevel;

&

// Main header script - this will be included into every script in
// the game (local and global). Do not place functions here; rather,
// place import definitions and #define names here to be used by all
// scripts.

import int gamelevel;

Ok, so far so good, I've managed to use the variable in character interactions and object interactions fine. 

Problem I've had is that I wanted to set gamelevel to a certain number during some dialogue.  When the player asks a certain question I wanted gamelevel to be set to 1, I did this;

within dialogue script...

BIGJON: "Cheers mate, that would be a great help. You could save the day!"
EGO: "Well, I'd better get a move on, catch you soon."
BIGJON: "Laters Dude."
option-off-forever 2
run-script 1 // run the dialogue request to set gamelevel to 1
stop

Then in the dialogue request function ;

#sectionstart dialog_request  // DO NOT EDIT OR REMOVE THIS LINE
function dialog_request(int par) {
  if (par==1) {
  gamelevel = 1; //set gamelevel to 1
}

I saved the game got the following error;

"There was an error compiling your script. The problem was in Global Script

Error line 171 : Nested functions not supported(you may have forgotten a closing brace."

I'm confused by this as line 171 is the next function down from my dialogue request function,

#sectionstart character1_a  // DO NOT EDIT OR REMOVE THIS LINE
function character1_a() {

}

Its blank, I haven't touched it, and at this point in my AGS understanding, I've no idea what it does or how to use it, so why on earth am I getting an error with it???

- Winner of the 10/12/06 Tune Contest

Ashen

Assuming you haven't just left it out when you copied it here then - as the error mesage suggests - it looks like you've missed a closing brace from the dialog_request function:
Code: ags

#sectionstart dialog_request  // DO NOT EDIT OR REMOVE THIS LINE
function dialog_request(int par) {
  if (par==1) {
    gamelevel = 1; //set gamelevel to 1
  } // <-- This brace closes the 'par == 1' condition
} // <-- This one closes the function, and you didn't have it.


It says the error is on that line, because that's where it 'sees' it - that line declares a new function, which because of the missing } is still inside dialog_request ('nested' in the words of the error message, like a condition within a condition). If you a similar error in the future, just look at the function immediately BEFORE the line the error mentions, that's where it'll be.

Not wanting to confuse the issue more, but since you only hae one lone in the par == 1 condition, you don't actually need the braces there at all:
Code: ags

#sectionstart dialog_request  // DO NOT EDIT OR REMOVE THIS LINE
function dialog_request(int par) {
  if (par==1) gamelevel = 1; //set gamelevel to 1
}


However, if you DO use braces, always make sure they match. Ctrl-B can be used to check for matching opening and closing braces.

Oh, and about the function at line 171: It's one of the Character interactions. A function like that will exist for any 'Run script' Character interaction you create. I can't say which mode it relates too, because AGS automatically generates the functions based on the order you add them.
I know what you're thinking ... Don't think that.

SSH

put another "}" at the end of your dialog_request function
12

Ashen

I know what you're thinking ... Don't think that.

mysticjim

Ah nuts! Sorry guys, I didn't realise I needed another closing brace.  It makes sense now, theres an opening one on the function line, then I added another opening one for my command, however, theres a closing one already there at the end of the function, I took it for granted that was all I needed!

Many thanks for sorting that out for me!
- Winner of the 10/12/06 Tune Contest

Da_Elf

i have a little thing i do with my fingers as i count opened braces and closed braces by raising and lowring a finger per brace

Khris

Indent the code (AGS'es editor even does it automatically! :o)

That makes the code easier to read, too.

Personally, I detest this:
Code: ags
}
}
}

SMF spam blocked by CleanTalk