dialog_request help

Started by mathwiz425, Wed 30/07/2008 18:07:16

Previous topic - Next topic

mathwiz425

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."

Khris

You don't need more than one, you're supposed to use the parameter to distinguish which code to run:

Example:
Code: ags
// 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!");
}

mathwiz425

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?

Matti

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?

mathwiz425

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. :'(

SSH

You must remember to put a return or stop between options if you don't want them to run in to each other...
12

mathwiz425

The two run-scripts are in different dialog scripts. 

Gilbert

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.

Khris

Mind the name of the parameter.

You can use
Code: ags
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.

mathwiz425

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");


monkey0506

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!

Code: ags
function dialog_request(int p) {
  if (p == 1) {
    Display("Hi");
    Display("Bye");
  }
  else if (p == 2) {
    player.ChangeRoom(5);
    Display("You entered room 5");
  }
}

Khris

And like a job for RTFM-Man...

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

SMF spam blocked by CleanTalk