Im new with ags and I just start of with scripting and I have a problem
I want to run script in a conversation by using 'run-script x" the totorial says use "function dialog_request"
(int parameter) but I don't understand why I should use INT and wathever I try it says error "nested functions not supported" I allready read all the helpfiles but I cant get it to work
could anyone help me out.
Well, the int parameter is necessary to distinguish between different tasks - when, for example, you run the script from different topics(options) AGS still calls the same dialog_request function. The integer value is used to choose the related portion of script.
//dialog script:
//topic 1
@1
ego: "blah blah"
man: "blah"
run-script 1
return
//topic 2
@3
man: "blah"
ego: "blah"
man: "blah"
run-script 2
return
//main global script
//outside all functions:
function dialog_request(int parameter) {
if (parameter == 1) {
Display("We are running a topic number 1");
}
if (parameter == 2) {
Display("We are running a topic number 2");
}
}
How it turned out?
I now understand more about how it works but when I do that it still doesn't work it still says nested functions not supported.do I have to change the word parameter in something random?It still doesn't work.
The problem with braces I think, could you post your main global script?
}
function dialog_request(int parameter) {
if (parameter == 1) {
Display("blablabla");
}
}
here it is but what are braces?
Quotewhat are braces?
I mean
{, }. I think you forgot to close a function. Where do you place dialog_request()? I need to look at the whole global script.
nope that can't be it it says error at line 106 and thats at: function dialog_request(int parameter) {
so it can't be anything else
// main global script file
function game_start() {
// called when the game starts, before the first room is loaded
}
function repeatedly_execute() {
// put anything you want to happen every game cycle here
}
function show_inventory_window () {
// This demonstrates both types of inventory window - the first part is how to
// show the built-in inventory window, the second part uses the custom one.
// Un-comment one section or the other below.
// ** DEFAULT INVENTORY WINDOW
InventoryScreen();
/*
// ** CUSTOM INVENTORY WINDOW
GUIOn (INVENTORY);
// switch to the Use cursor (to select items with)
SetCursorMode (MODE_USE);
// But, override the appearance to look like the arrow
SetMouseCursor (6);
*/
}
function on_key_press(int keycode) {
// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused() == 1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363) SaveGameDialog(); // F5
if (keycode==365) RestoreGameDialog(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.bmp"); // F12
if (keycode==9) show_inventory_window(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
}
function on_mouse_click(int button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button==LEFT) {
ProcessClick(mouse.x, mouse.y, GetCursorMode() );
}
else { // right-click, so cycle cursor
SetNextCursorMode();
}
}
function interface_click(int interface, int button) {
if (interface == ICONBAR) {
if (button == 4) { // show inventory
show_inventory_window();
}
else if (button == 5) { // use selected inventory
if (character[ GetPlayerCharacter() ].activeinv >= 0)
SetCursorMode(4);
}
else if (button == 6) // save game
SaveGameDialog();
else if (button == 7) // load game
RestoreGameDialog();
else if (button == 8) // quit
QuitGame(1);
else if (button == 9) // about
Display("Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2003 Chris Jones");
} // end if interface ICONBAR
if (interface == INVENTORY) {
// They clicked a button on the Inventory GUI
if (button == 1) {
// They pressed SELECT, so switch to the Get cursor
SetCursorMode (MODE_USE);
// But, override the appearance to look like the arrow
SetMouseCursor (6);
}
if (button == 2) {
// They pressed LOOK, so switch to that mode
SetActiveInventory(-1);
SetCursorMode(MODE_LOOK);
}
if (button == 3) {
// They pressed the OK button, close the GUI
GUIOff (INVENTORY);
SetDefaultCursor();
}
if ((button == 4) && (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)) {
// scroll down
game.top_inv_item = game.top_inv_item + game.items_per_line;
}
if ((button == 5) && (game.top_inv_item > 0)){
// scroll up
game.top_inv_item = game.top_inv_item - game.items_per_line;
}
function dialog_request (int parameter) {
if (parameter == 1) {
Display("blablabla");
}
}
Aha, you see, the dialog_request is just like any other function which you have to declare outside any function's body, so remove these 4 lines:
function dialog_request (int parameter) {
if (parameter == 1) {
Display("blablabla");
}
and place them outside, like:
// main global script file
function game_start() {
........
}
function repeatedly_execute() {
........
}
function show_inventory_window () {
........
}
function on_key_press(int keycode) {
........
}
function on_mouse_click(int button) {
........
}
function interface_click(int interface, int button) {
........
}
//just like any other function:
function dialog_request (int parameter) {
if (parameter == 1) {
Display("blablabla");
}
}
~Cheers
wow I can hardly believe it just worked :D
I just tough I had to leave 1or 2 braces but specially there I had to leave 3 because it whas an if in an if ect
thanks for your help and a happy new year :)
You are welcome, glad it is sorted out.
happy new year ! :)
~Cheers