Scripting, Code & Interaction: Difference between revisions
Jump to navigation
Jump to search
→Running regular code outside dialog
Line 55: | Line 55: | ||
==Running regular code outside dialog== | ==Running regular code outside dialog== | ||
''I need to run some code in my dialog script that isn't in the form of a dialog command! I suppose I need to run regular AGS script from within the dialog script. What do I do?'' | |||
Well, there's this little thing called '''run-script X'''. First off, create (or edit, if it's there already) a function within the global script called '''dialog_request (int X)'''. You can name '''X''' whatever you'd like, as it really doesn't matter. Next, inside that function, you will check to see what value '''X''' is. When you run the '''run-script X''' command, whatever is in place of the variable '''X''' will be passed along to the '''dialog_request''' function. So, you must then check the value of the integer variable within the '''dialog_request''' function, so that the right script will be called. Let's say that "'''run-script 4'''" was called. Within the dialog_request function, there will be a set of '''if...else if...else if...''' commands. When it comes around to cheecking to see if the variable passed was '''4''', then whatever is put down afterward until the next "'''else if'''" command will run. | |||
Here is an example to get you started. If, in the dialog script, you had the command '''run-script 5''', you would need the following in your Global Script... | |||
function dialog_request(int blorg) { | |||
if (blorg==1) { | |||
// Put whatever goes here if "run-script 1" is run | |||
} else if (blorg==2) { | |||
// Put whatever goes here if "run-script 2" is run | |||
} else if (blorg==3) { | |||
// Put whatever goes here if "run-script 3" is run | |||
} else if (blorg==4) { | |||
// Put whatever goes here if "run-script 4" is run | |||
} else if (blorg==5) { | |||
// BINGO! This code will be run when "run-script 5" is called | |||
} | |||
} | |||
Do you see now? When the function '''dialog_request()''' is run, with "'''5'''" being passed as the only parameter, only the right code will run, because you added an "'''if/else if'''" check within the function. This way, only that code will run if "'''5'''" was passed as the parameter. | |||
Get it? Got it? Good! :) | |||
==Placing your code: more basics== | ==Placing your code: more basics== | ||
==Fatal error when running "function DoSomething(1,2,3);"== | ==Fatal error when running "function DoSomething(1,2,3);"== |