Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Maslak791 on Sat 04/10/2014 12:07:45

Title: Another dialog_request problem
Post by: Maslak791 on Sat 04/10/2014 12:07:45
Hello,

I was trying to run this script, but I keep getting this error no matter what I do or change.

GlobalScript.asc(616): Error (line 616): Variable 'dialog_request' is already defined


and the script:

Code (ags) Select

function dialog_request(int parameter)
  if
  (parameter==1)
  (player.HasInventory(iPapierosy))
  (player.LoseInventory(iPapierosy))
  {
  cEgo.Say("Something something");
  cBabcia.Say("yes.");
 
  }
  else
  {
  cEgo.Say("Bye");
}
Title: Re: Another dialog_request problem
Post by: Crimson Wizard on Sat 04/10/2014 12:23:10
This message means that there might be another function with same name somewhere in your script.
Press Ctrl+F to bring Search Text window and look for "dialog_request" in whole GlobalScript.asc.

On other hand, your script has several mistakes. First, you are missing a number of brackets:
Code (ags) Select

function dialog_request(int parameter)
{ <================= here
  if
  (parameter==1)
  (player.HasInventory(iPapierosy))
  (player.LoseInventory(iPapierosy))
  {
    cEgo.Say("Something something");
    cBabcia.Say("yes.");
  }
  else
  {
    cEgo.Say("Bye");
  } <=== moved it a bit to the right to make better indentation
} <============ here


Secondly, you have a mistake in the condition. The multiple conditions must be joined with either '&&' ("AND") or  || ("OR) operator. All the group of conditions should be surrounded with outer pair of round brackets --   "if ( all conditions )"
I don't know your logic, so I'll just give an example:
Code (ags) Select

  if (
  (parameter==1) &&
  (player.HasInventory(iPapierosy)) &&
  (player.LoseInventory(iPapierosy)))


Finally, you should not use "LoseInventory" in condition, because it is does not have a meaningful return value.
The problem of AGS if that the functions declared as "function NNN" are automatically assigned a return value of "int" type. This is a serious problem because it allows users to do things like:
Code (ags) Select

int a = player.LoseInventory(iPapierosy);

However, the actual return value here will have undefined, random or meaningless value.
Do not use function's return value unless documentation explicitly states that it returns one!