Hi there.
Short version: How do I set a variable properly in a dialog script and have it carry over to when the user interacts with an object through a condition of if it is set or not?
I'm actually doing a "Simulation" as opposed to a game for a university project where the 'user' is an IT Technician whom has to solve computer-based problems. I'm a novice AGS user and have been using it for several months and only recently have I needed to do proper scripting rather than creating rooms and objects. Onto my problem:
The first scenario I'm creating requires the player to talk to an NPC to find out the nature of the issue (Setting up Out Of Office Assistant in Outlook :D) and only then can they go through the 'solve' process when they interact with the PC. So I have the following dialog with a set-globalint variable as mentioned in the AGS Helpfile:
Quote// dialog script file
@S // dialog startup entry point
Bruce: Lisa...
Lisa: Yes?
return
@1 // option 1
Lisa: I'm fine, thank you.
return
@2 // option 2
Lisa: I'm going on holiday for a week and I will be expecting a lot of emails.
Lisa: So I'd like those people to get mailed automatically when they mail me.
Lisa: Can you make it do that?
Bruce: I think I know what you mean.
Bruce: I'll have a look now.
set-globalint 1lisatlk 1
return
@3 // option 3
Lisa: Ok.
stop
Then on the 'room' for Lisa's desktop, the Player Character uses her Outlook:
(http://content.imagesocket.com/thumbs/TechsProb01ee4.JPG) (http://imagesocket.com/view/TechsProb01ee4.JPG)
And the variable settings:
(http://content.imagesocket.com/thumbs/TechsProb01_B471.JPG) (http://imagesocket.com/view/TechsProb01_B471.JPG)
So if the user hasn't spoken to Lisa about the problem, they get a message saying they don't have enough information, while if they have spoken to her then dialog2 (The dialog where the user has to select the correct solution) runs.
However, whenever I run the game it acts as if the variable isn't actually set. What am I doing wrong?
Change that to
set-globalint 101 1
Then do
if (GetGlobalInt(101)) {
...
}
Or use any other GlobalInt, of course, but they are only referenced by numbers, not names (yet).
GlobalInts <-> Graphical Variables
The interaction editor can only access Graphical Variables ("=Conditional - If variable is set to a certain value"), these can be referred to by name.
GlobalInts can only be accessed by script (="Run script") and are referred to by numbers.
From within dialog script, only GlobalInts can be set directly with the set-globalint command.
For setting Graphical Variables from within dialog script, you have to run custom script with the run-script command.
So you can either:
1.) Use only GlobalInts
Do as KhrisMUC says and change the command to
set-globalint 101 1
then change all
Interact object
-> Conditional...
...etc. to
Interact object
-> Run script
if (GetGlobalInt(101) == 1) {
RunDialog(2); // fixed
}
else if (GetGlobalInt(101) == 0) {
DisplayMessage(5);
}
2.) Set the Graphical Variable from the dialog script
...
Bruce: I'll have a look now.
run-script 7 // runs the function below and passes 7
return
...
// global script
function dialog_request(int runscript) { // if it doesn't exist already
if (runscript == 7) { // if "run-script 7" used
SetGraphicalVariable("1lisatlk", 1);
}
//else if (runscript == 4) { // if "run-script 4" used
// do stuff
//}
//...etc.
}
Edit:
Yep, sorry about that.
Thanks very muich for the responses, and apologies for not posting this in the Beginner's area originally.
Ok, that makes sense about the two types of variables. I've removed the Conditionals and I'm trying to use GlobalInts in a script now as that's going to be easier for me, like so:
(http://content.imagesocket.com/thumbs/Techsprob01_D91d.JPG) (http://imagesocket.com/view/Techsprob01_D91d.JPG)
However, I'm now getting the following error:
Error (line 8 ): '.RunDialog' is not a public member of 'Game'. Are you sure you spelt it correctly (remember capital letters are important)?
Here's the actual script which I'm sure is the same as Stratzer gave me:
Quote// script for Object 5: Interact object
// If Bruce has run dialog option 2 with Lisa, he can access the Solve button, otherwise he can't.
if (GetGlobalInt(101) == 1) {
Game.RunDialog(2);
}
else if (GetGlobalInt(101) == 0) {
DisplayMessage(5);
}
And just in case here's the whole room script:
Quote// room script file
#sectionstart object5_a // DO NOT EDIT OR REMOVE THIS LINE
function object5_a() {
// script for Object 5: Interact object
// If Bruce has run dialog option 2 with Lisa, he can access the Solve button, otherwise he can't.
if (GetGlobalInt(101) == 1) {
Game.RunDialog(2);
}
else if (GetGlobalInt(101) == 0) {
DisplayMessage(5);
}
}
#sectionend object5_a // DO NOT EDIT OR REMOVE THIS LINE
I've also tried Game.RunDialog(d1Solution) as d1Solution is the dialog Script Name, but I'm getting the same error.
Please post error messages as text not images. It makes it easier for people with the same problems to search for an answer.
Not that there's likely to be many people getting this message... The problem is that strazer gave you the wrong code (first time for everything ;)). If you check the manual (as you should've done), you'll see that Game.RunDialog doesn't exist. What you want to use is Dialog.Start (http://www.adventuregamestudio.co.uk/manual/Dialog.Start.htm) (in this case d1Solution.Start();, if 'd1Solution' is the correct script name).
The OLD command was RunDialog, but that's obsolete as of V2.72 - if you're usng an earlier version that that, use RunDialog.
That works. Excellent - thank you very much! :)
Quote from: Ashen on Mon 26/02/2007 12:13:45
Please post error messages as text not images. It makes it easier for people with the same problems to search for an answer.
Bah, I've got a month left to implement five more IT-based scenario's and finish my 10,000 word report so nuts to writing up error messages when a print screen works as well! ;)
(Seriously, I'll try to from now on though)
Although it doesn't say it on all error messages (it does on some, though), you can use Ctrl-C to copy the text of the message and paste it into your reply - even quicker than saving, cropping and uploading a screenshot, and less likely to annoy the mods.
And "nuts to it", indeed. In my day I finished a 10,000 word dissertation in 3 days, never mind your 'month'. (Just, don't ask about my grades...)