Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: mathwiz425 on Wed 30/07/2008 18:07:16

Title: dialog_request help
Post by: mathwiz425 on Wed 30/07/2008 18:07:16
How can I have more than one dialog request?
When I tried to put two "function dialog_request(int)" the following comes up:"Variable dialog_request already exists."
Title: Re: dialog_request help
Post by: Khris on Wed 30/07/2008 19:40:31
You don't need more than one, you're supposed to use the parameter to distinguish which code to run:

Example:
// dialog script A
run-script 1         // will call dialog_request(1);

// dialog script B
run-script 2         // will call dialog_request(2);

// global script

function dialog_request(int p) {

  if (p==1) Display("I got called from dialog script A!");

  if (p==2) Display("Dialog B caused me to happen!");
}
Title: Re: dialog_request help
Post by: mathwiz425 on Thu 31/07/2008 14:30:47
Thanks! Now when I only want it to run p==2, it runs p==1 and p==2. What can I do to stop this from happening?
Title: Re: dialog_request help
Post by: Matti on Thu 31/07/2008 15:45:50
That's strange. Are you sure, you didn't put both run-script commands in the same dialog so that they both run at the same time?
Title: Re: dialog_request help
Post by: mathwiz425 on Thu 31/07/2008 15:51:41
I'm completely sure. One dialog has run-script 1 and the other has run-script 2.  P==2 never runs!  All my dialogue requests run p==1. :'(
Title: Re: dialog_request help
Post by: SSH on Thu 31/07/2008 15:51:57
You must remember to put a return or stop between options if you don't want them to run in to each other...
Title: Re: dialog_request help
Post by: mathwiz425 on Thu 31/07/2008 16:01:03
The two run-scripts are in different dialog scripts. 
Title: Re: dialog_request help
Post by: Gilbert on Thu 31/07/2008 16:25:52
There is only ONE dialog_request(). :P

Please post the content of your function for us to look at. I have some ideas but rather look at it to find what you have done wrong first.
Title: Re: dialog_request help
Post by: Khris on Thu 31/07/2008 17:37:14
Mind the name of the parameter.

You can use
function dialog_request(int kumquats) {

  if (kumquats == 1) ...
  if (kumquats == 2) ...
  ...
}

or whatever variable name you want, but make sure you're testing what's going to be the parameter.
Title: Re: dialog_request help
Post by: mathwiz425 on Thu 31/07/2008 18:13:15
Thanks! Can I put more than command after the if (p==1)?  Like...
dialog_request(int p) {
if (p==1) Display("Hi"); Display(Bye!");
if (p==2) player.ChangeRoom(5); Display("You entered room 5");

Title: Re: dialog_request help
Post by: monkey0506 on Thu 31/07/2008 18:23:19
Yes you can, but it will execute any command after the first every time the function is called. :P

This looks like a job for braces!

function dialog_request(int p) {
  if (p == 1) {
    Display("Hi");
    Display("Bye");
  }
  else if (p == 2) {
    player.ChangeRoom(5);
    Display("You entered room 5");
  }
}
Title: Re: dialog_request help
Post by: Khris on Thu 31/07/2008 20:39:07
And like a job for RTFM-Man...

Where's a superhero when you need him? ;)