using inventory items on hotspots

Started by Gribbler, Sun 12/02/2012 12:24:46

Previous topic - Next topic

Gribbler

Hi!

Here's what I intend to do: character1 (player) wants to interact with an object on screen. When he does other character2 tells him not to. Character1 uses inventory object on character2. Then he is able to interact with object.

How do I do this? Variables?

I figured out how to do something similiar when character1 clicks on object / inv item:

function iNOTEBOOK_Look()
{
if (Notebook_Variable == 0)  {
  player.Say("It must be that kid's notebook.");
  }
if (Notebook_Variable == 1)  {
  player.Say("There are nice pictures of dragons and knights in it.");
  }
if (Notebook_Variable == 2) {
  player.Say("He must have been crazy about fantasy.");
  player.Say("There are fantasy drawings on almost every page.");
  player.SpeechView = 7;
  Wait(10);
  player.Say("Hey! What's this?");
  Wait(15);
  player.SpeechView = 4;
  player.Say("It's some kind of collectible card.");
  player.AddInventory(iCARD);
  }

But how do I do those "conditionals" when using inventory items?

Thanks in advance for any suggestions

Khris

The code you posted doesn't change the variable.

Here's example code for the object:
Code: ags
function oCrate_Interact() {

  if (character2_dealtwith) {
    ...
  }
  else {
    character2.Say("Hey, leave that alone!");
  }
}


Code: ags
function character2_Useinv () {
  
  if (player.ActiveInventory == iBluntobject) {
  
    if (character2_dealtwith) player.Say("Again? I don't think so.");
    else {
      ...
      character2_dealtwith = true;
      Display("Character 2 won't keep me from doing stuff now.");
    }
  }
  else player.Say("That doesn't make sense.");
}


character2_dealtwith is supposed to be a Global variable of type bool, initial value false.

Gribbler

I'm still struggling with this...
Here's what I want to do in more details: Player wants to pick up TOOLBOX. When player interacts with it PLUMBER says "Leave that alone". Player must use BUCKET on HOLE_STREET (plumber character is in a hole) to be able to pick up TOOLBOX. PLUMBER is an invisible character placed around HOLE.

My code for TOOLBOX is:
Code: ags

function oToolbox_Interact()
{
if (Plumber_Unconscious) {
  player.AddInventory(iTOOLBOX);
}
else {
  cPLUMBER.Say("Leave that alone!");
}
}


Code for hotspot HOLE_STREET:

Code: ags

function hHOLE_STREET_UseInv()
{
if (player.ActiveInventory == iBUCKET) {
  
    if (Plumber_Unconscious) player.Say("Again? I don't think so.");
}
    else {
      Plumber_Unconscious = true;
      player.Say("Now it's safe to take it.");
    }
  }
  else player.Say("He won't let me take it.");
}



Plumber_Unconscious is a Global variable of type bool, initial value false.

I keep getting "unexpected else" at the end of hotspot HOLE STREET code.

Khris

A fine example of why I keep stressing how important proper indentation is.

You had an extra closing brace in your code.

Code: ags
function hHOLE_STREET_UseInv()
{
  if (player.ActiveInventory == iBUCKET) {
    if (Plumber_Unconscious) player.Say("Again? I don't think so.");
    else {
      Plumber_Unconscious = true;
      player.Say("Now it's safe to take it.");
    }
  }
  else player.Say("Why should I drop that into the hole?");
}


I have also changed the last message (it is displayed if the player uses something else with the hole).

Also, if the player uses the bucket with the hole without having tried to take the toolbox first, they'll wonder what "it" is referring to.

Gribbler


SMF spam blocked by CleanTalk