Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - delacey89

#1
Hello everyone. I'm new here, and to coding in general, though I've been toying with the idea of making a game in AGS since about 2007 or so. Forgive me if my question seems obvious.

Okay, in my scenario the character (cDummy) is supposed to pick up a bit of bamboo and an empty Jetpack. Nearby he finds a Crater with radioactive waste inside. The puzzle involves combining the inventory item iBamboo with iJetpackEmpty to make the new combined item iBambooJetpack, which can then be used on the Crater to siphon the waste to use as jetpack fuel. Once this is done the inventory item iBambooJetpack will be replaced with iJetpackFull.
The catch is that I don't want the player to be able to combine any of the items until after they have tried to use either the bamboo (iBamboo) or the empty Jetpack (iJetpackEmpty) on the Crater (hCarter1).

At the moment, I have this in my global script:

Code: ags
  // Declare global variables

bool iBambooOrJetpackUsedOnCrater = false;

  //Rest of Script
function iBamboo_UseInv()
{
  if (cDummy.ActiveInventory == iJetpackEmpty)
  {
    if (iBambooOrJetpackUsedOnCrater)
    {
      cDummy.Say("Now You're thinking with your noodle!");
      cDummy.LoseInventory(iBamboo);
      cDummy.LoseInventory(iJetpackEmpty);
      cDummy.AddInventory(iBambooJetpack);
      cDummy.Say("The bamboo will make the perfect siphon.");
    }
  }
  else
  {
    cDummy.Say("Why would I want to do that?");
  }
}

function iJetpackEmpty_UseInv()
{
  if (cDummy.ActiveInventory == iBamboo)
  {
    if (iBambooOrJetpackUsedOnCrater)
    {
      cDummy.Say("Now You're thinking with your noodle!");
      cDummy.LoseInventory(iBamboo);
      cDummy.LoseInventory(iJetpackEmpty);
      cDummy.AddInventory(iBambooJetpack);
      cDummy.Say("The bamboo will make the perfect siphon.");
    }
    else
    {
      cDummy.Say("Why would I want to do that?");
    }
  }
}

And this in my room script:

Code: ags
  // Declare global variables

bool iStonesUsedOnCrater = false;

bool iBambooOrJetpackUsedOnCrater = false;


function hCrater1_UseInv()
{
  if (cDummy.ActiveInventory == iStones)
  {
    if (Game.DoOnceOnly("StonesInCrater") == true)
    {
      cDummy.Walk(hCrater1.WalkToX, hCrater1.WalkToY, eBlock, eWalkableAreas);
      iStonesUsedOnCrater = true;
      cDummy.LoseInventory(iStones);
      cDummy.Say("There goes my back.");
      cDummy.Say("Whoa! Some kind of fluorescent green liquid splashed up at me!");
      GiveScore(10);
    }
  }
  else if (cDummy.ActiveInventory == iBamboo)
  {
    iBambooOrJetpackUsedOnCrater = true;
    cDummy.Say("It's glowing! It's probably radioactive.");
    cDummy.Say("If you want me to suck that up into my mouth you'd better have a damn good reason.");
  }
  else if (cDummy.ActiveInventory == iJetpackEmpty)
  {
    iBambooOrJetpackUsedOnCrater = true;
    cDummy.Say("Not a bad idea. Whatever that green liquid is, it sure looks radioactive; there's a good chance it'll work as fuel.");
    cDummy.Say("...but it's too far to reach. I'll need to fetch it with something else.");
  }
}

The game launches and everything works up to a point. The inventory items can be used on the crater and cDummy will say what he is supposed to, but if I try to combine the bamboo with the Jetpack AFTER using the items on the crater, I simply get the response "Why would I want to do that?". My assumption is the problem has something to do with "iBambooOrJetpackUsedOnCrater" and the fact it's written in both the global and the room script, but that's just my gut feeling. I really don't know. I thought maybe if I put all the code surrounding the crater in the global script?

Any help is greatly appreciated.



EDIT---
Sorry everyone. Figured it out as soon as I posted.
I got it working by removing "bool iBambooOrJetpackUsedOnCrater == false;" from room script, before putting this into the global script:

Code: ags
bool iBambooOrJetpackUsedOnCrater;
export iBambooOrJetpackUsedOnCrater;

...and finally I put this in the Global HeaderScript:

Code: ags
import bool iBambooOrJetpackUsedOnCrater;

Now it works flawlessly.


PS I've never really used a forum before and don't know the proper etiquette. Guess I'll leave this here for others with a similar problem to see?
SMF spam blocked by CleanTalk