Help with "Parser Error in the ActiveInventory"

Started by ZacksQuest, Wed 15/06/2011 22:24:49

Previous topic - Next topic

ZacksQuest

Okay, I'm doing a graphical remake of Zork I (not enough to talk about on the in production forums, only one screen and such...), but I'm stuck in a problem zone. I'm a beginner, and when I tried to make it so you could put a leaflet back in a mailbox, I realised I didn't know the least bit about making inventory items interact with characters. So, I've checked the Help index, and furthermore have been blatantly confused. So, I have two questions.

1: Can someone spot the "parser error" in this piece of code?

function hHotspot1_UseInv()
{
  if (cEgo.ActiveInventory = iLeaflet
cEgo.Walk(123, 121, eBlock, eWalkableAreas);
cEgo.LoseInventory(iLeaflet);
Display("You put back the leaflet and shut the door.");)
}

2: Can I make it so multiple inventory items can be used on a character using ONE function, or do I have to copy and paste "function hHotspot1_UseInv() {}" over and over again?
Current projects:

ZORK I: THE VGA GRAPHICAL REMAKE (Now with EVEN MORE puzzles, MORE story and character development, and SO MUCH CHEESE!)
Here is the site... yay for advertising!-> http://thegreatundergroundempirevga.webs.com/index.htm

Matti

#1
Quote from: ZacksQuest on Wed 15/06/2011 22:24:49
1: Can someone spot the "parser error" in this piece of code?

function hHotspot1_UseInv()
{
 if (cEgo.ActiveInventory == iLeaflet)     // this caused the error
 {

   cEgo.Walk(123, 121, eBlock, eWalkableAreas);
   cEgo.LoseInventory(iLeaflet);
   Display("You put back the leaflet and shut the door.")
 }
}

EDIT:

Quote from: ZacksQuest on Wed 15/06/2011 22:24:49
2: Can I make it so multiple inventory items can be used on a character using ONE function, or do I have to copy and paste "function hHotspot1_UseInv() {}" over and over again?

Of course you can (copying the function wouldn't work anyway):

Code: ags

function hHotspot1_UseInv()
{
  if (cEgo.ActiveInventory == iLeaflet)
  {
  // stuff happens
  }
  if (cEgo.ActiveInventory == iWhatever)
  {
  // stuff happens
  }
  // etc.
}


Hernald

#2
function hHotspot1_UseInv() {
  if (cEgo.ActiveInventory == iLeaflet ) {
    cEgo.Walk(123, 121, eBlock, eWalkableAreas);
    cEgo.LoseInventory(iLeaflet);
    Display("You put back the leaflet and shut the door.")
    }
  }

Note the closed bracket and the opened curly bracket.

To use the same function for open inventory items use else if ()

ZacksQuest

Current projects:

ZORK I: THE VGA GRAPHICAL REMAKE (Now with EVEN MORE puzzles, MORE story and character development, and SO MUCH CHEESE!)
Here is the site... yay for advertising!-> http://thegreatundergroundempirevga.webs.com/index.htm

monkey0506

#4
Some things to keep in mind:

= is the assignment operator:

Code: ags
int i = 0; // create a variable 'i' and set its value to 0
i = 5; // set variable 'i' to value 5


== is the logical equals operator (does left side have the same value as right side):

Code: ags
if (i == 5) { /* do something... */ }


Any time you have an opening parenthesis '(', curly brace '{', or bracket '[', you must have a matching closing symbol:

Code: ags
if (i == 5) // open and close parenthesis
{ // opening brace
  if (player.InventoryQuantity[4] == 3) // opening parenthesis, opening brace, closing brace, closing parenthesis
  { // opening brace
    // some code
  } // closing brace
} // closing brace


If you forget the closing symbol to match the opening one, you'll get an error like this.

One final thing is that any time you have a condition or loop, the curly braces are optional. If you don't include them, then only the very first statement after the condition or loop is used:

Code: ags
if (i == 5) i = 12; // if 'i' is 5, change it to 12
i++; // 'i' will ALWAYS be increased by 1 here


If you include the braces, then you can run multiple statements as part of the condition or loop:

Code: ags
if (i == 12)
{
  i = 0; // this is run if 'i' is 12
  player.Say("Goosnargh."); // this is ALSO run if 'i' is 12, but not otherwise
}


This is really a matter of basic programming principles, so you should check out the scripting tutorial in the manual. ;)

Welcome to the forums though!

SMF spam blocked by CleanTalk