Another dialog_request problem

Started by Maslak791, Sat 04/10/2014 12:07:45

Previous topic - Next topic

Maslak791

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

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

Crimson Wizard

#1
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

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

  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

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!

SMF spam blocked by CleanTalk