Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Melee Island Resident on Sat 23/04/2011 15:49:39

Title: Scripting Trouble
Post by: Melee Island Resident on Sat 23/04/2011 15:49:39
okay i've got this code here, could someone please explain to me what's wrong with it?


function cGhost_UseInv()
{

  if (player.ActiveInventory == iFlowerPot) {
    dFlowers.Start();
    player.AddInventory(iCode);
    Display ("The Code is now in your inventory");
  }

}

when i use the flower pot on the character it does nothing
Title: Re: Scripting Trouble
Post by: Khris on Sat 23/04/2011 15:54:43
Is the function properly linked?

Try this:

function cGhost_UseInv()
{
  Display("test");
  if (player.ActiveInventory == iFlowerPot) {
    dFlowers.Start();
    player.AddInventory(iCode);
    Display ("The Code is now in your inventory");
  }
}


Does it say "test"?

Also note that dFlowers.Start(); ends up in the queue and the dialog is only started after the function has finished, i.e. the player will get iCode, then the message, then see the dialog.
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sat 23/04/2011 20:58:29
test doesn't show
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sat 23/04/2011 21:12:25
okay by making this change i've gotten it to show the dialogue

function cGhost_UseInv()
{
  if (player.ActiveInventory == iFlowerPot) {
    dFlowers.Start();
    }
}

but the player still needs to get iCode
Title: Re: Scripting Trouble
Post by: Khris on Sat 23/04/2011 21:17:29
Wait, so now the function is called? So you got it to be linked properly but chose not to mention that, correct? Just trying to get us on the same page here, because other people might look at this thread when they're having a similar problem and wonder why removing commands makes functions get called that previously weren't.

Anyway, you can put standard script commands into dialog scripts, you just need to out a space at the start of the line.

Please read the manual and especially the complete tutorial though first.
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sat 23/04/2011 23:19:42
// Dialog script file
@S  // Dialog startup entry point
Ghost: Oh my god, you stole Dracule's prized Flower Pot.
Ghost: You Truly are evil
return
@1
Ghost: Of course it does
Ghost: Here it is

player.AddInventory(iCode);
    Display ("The Code is now in your inventory");
  }
stop

i tried it but it gave me an error

am i on the right track at least?
Title: Re: Scripting Trouble
Post by: Khris on Sat 23/04/2011 23:30:07
Like I said, put a space before player.AddInventory(iCode);
Also remove the }, what is it doing there?

And I'd appreciate it if you addressed what I wrote previously and also if SPELL OUT THE ERROR MESSAGE YOU GET in the future.
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sat 23/04/2011 23:41:27
k done that

Dialog 1(10): Unknown command: player .addinventory(icode). The command may require parameters which you have not supplied.

im sure im doing something really stupid
Title: Re: Scripting Trouble
Post by: Khris on Sun 24/04/2011 00:18:55
Shouldn't it be:

   player.AddInventory(iCode);

Capitalization is important, and there can't be a space before or after the dot.
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sun 24/04/2011 01:09:17
in the script it's capitalized

and there's no space inbetween the dot

and im still getting the same error
Title: Re: Scripting Trouble
Post by: Sephiroth on Sun 24/04/2011 01:23:01
Quote
andI'm still getting the same error

You seem to have an obvious problem with spelling, even when you're writing a post, you're not using capitals and you forget to put spaces sometimes.

There's nothing wrong with your code, every script command needs a space before, when it's inside the dialog, and the command should be written carefully, when you start to write "player.add" it should pop up a quick window to auto complete your code, it will take care of the spelling for you.


// Dialog script file
@S  // Dialog startup entry point
Ghost: Oh my god, you stole Dracule's prized Flower Pot.
Ghost: You Truly are evil
return
@1
Ghost: Of course it does
Ghost: Here it is

player.AddInventory(iCode);
Display("The Code is now in your inventory");

stop
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Sun 24/04/2011 02:34:59
cheers mate ;D
Title: Re: Scripting Trouble
Post by: Melee Island Resident on Mon 25/04/2011 14:24:07
okay i have advanced further and have gotten stuck at a similar problem
// Dialog script file
@S  // Dialog startup entry point
Troll: You can't go in there without the code.
return
@1
Troll: Well what is it then?
    if (player.ActiveInventory == iCode) {
    dTroll2.Start();
   
    else player.Say("I don't know.");
return

Dialog 2(10): Error (line 10): PE04: parse error at 'else'

what exactly am i doing wrong?

Title: Re: Scripting Trouble
Post by: Matti on Mon 25/04/2011 14:44:49
This part:


  if (player.ActiveInventory == iCode) {
    dTroll2.Start();
   
    else player.Say("I don't know.");


should look like this:


  if (player.ActiveInventory == iCode) dTroll2.Start();
  else player.Say("I don't know.");
Title: Re: Scripting Trouble
Post by: Dualnames on Mon 25/04/2011 14:45:34

// Dialog script file
@S  // Dialog startup entry point
Troll: You can't go in there without the code.
return
@1
Troll: Well what is it then?
   if (player.ActiveInventory == iCode)    dTroll2.Start();
   else player.Say("I don't know.");
return


EDIT: Beat by Matti (WTF!)