possible variable

Started by Flyman, Fri 27/01/2012 11:53:38

Previous topic - Next topic

Flyman

Hi...what's wrong in my script...
I've  to examine a object so: the first time the character examine he added a "key" and speech " I've found"....
If the have just take the key...he speech only "nothing".

note: i can't use setglobal, because I can't use a hotspot in my pictures!

if (UsedAction (A_LOOK_AT)) {
  if (MovePlayer (338, 137)) {
    FaceDirection (GetPlayerCharacter(), DIR_UP);
    Wait (5);
if (character [GetPlayerCharacter ()].activeinv == 11) {  \\can use this for  a condition?? "if the character have added just an object "a key"??
      DisplaySpeech(GetPlayerCharacter(), "Nothing.");
    }
    DisplaySpeech (GetPlayerCharacter (), "I've found");
PlaySound(4);
AddInventory (11);
    }
  }
}

Help!

monkey0506

What version of AGS are you using? This code looks...error prone to say the least.

Does MoveCharacter return a specific result? If the result is undefined (I don't have the manual handy, I'm on my phone) then you should never be using it as a condition.

Anyway, are you ever setting the player's active inventory? If you are we need to see the code please. If you're letting the engine handle inventory clicks then it's not going to set active inventory for a look at/examine command coz that's not what active inventory is for but rather game.inv_activated.

Flyman

I use AGS 2.72
How can resolve to set a condition?

Khris

Flyman,
you're using an old AGS version and possibly an old starter pack and an old tutorial, it seems.

I'd recommend switching to 3.2, a current starter pack and the new tutorial in the MMM forum.

Until then:

Code: ags
  // first, let's move the player and face the object/hotspot
  if (MovePlayer (338, 137)) {
    FaceDirection (player.ID, DIR_UP);
    Wait (5);

    // now let's check at the verb
    if (UsedAction (A_LOOK_AT)) {
      if (player.InventoryQuantity[11] > 0)  player.Say("I didn't find anything else.");
      else {
        player.Say("I found a key!");
        PlaySound(4);
        player.AddInventory(inventory[11]);
      }
    }
  }


player.InventoryQuantity tells you how much of an item the player is carrying. So if it is > 0, the player has already picked up the key. The problem with this method is that if the player is able to lose the key, they can pick it up over and over again.
Newer AGS versions have a handy function called Game.DoOnceOnly for these situations.

(Also, please post in the Beginner's section.)

Flyman

Thanks Chris!!
I post in Beginner's section!!

mmm, if possible that  AGS implemented a command "Game.DoOnceOnly" in future version??

Khris

AGS already has Game.DoOnceOnly, not in version 2.72 though.

Like I said, move to 3.2.

Also, you're using really old code, even for 2.72.

Code: ags
DisplaySpeech(GetPlayerCharacter(), "Nothing.");

is now
Code: ags
player.Say("Nothing.");


Which tutorial are you using?

Flyman

mmm, I don't use a tutorial, I used manual of ags!
I prefer ags 2.72 but i konw that I must upgrade to new version

monkey0506

Yeah, that old-style coding predates AGS 2.7. Since then we've had AGS 2.71, 2.72, 3.0, 3.0.1, 3.0.2, 3.1, 3.1.1, 3.1.2, 3.2, and 3.2.1. Your coding is at least 11 versions behind. :D

I started to edit my post earlier with info about InventoryQuantity but I wasn't even entirely sure what AGS version you were using and like I said, I was on my phone without the manual handy.

IIRC, Game.DoOnceOnly showed up in AGS 3.0. You should really upgrade unless you've already been working on this project for several years.

Flyman

Ok  ;D
In the new version of ags of must modify the code "modify of Chris", with command Game.DoOnceOnly ??


    // first, let's move the player and face the object/hotspot
  if (MovePlayer (338, 137)) {
    FaceDirection (player.ID, DIR_UP);
    Wait (5);

    // now let's check at the verb
    if (UsedAction (A_LOOK_AT)) {
      if (player.InventoryQuantity[11] > 0)  player.Say("I didn't find anything else.");
      else {
        player.Say("I found a key!");
        PlaySound(4);
        player.AddInventory(inventory[11]);
      }
    }
  }


Khris

Quote from: Flyman on Fri 27/01/2012 16:20:00
mmm, I don't use a tutorial, I used manual of ags!

MovePlayer, FaceDirection and UsedAction are custom functions of the MMM starter packs.
You're using those but if you aren't using a tutorial, you're copying them from existing code in the starter pack, right? So then the starter pack is really old.

Game.DoOnceOnly:
Code: ags
      if (Game.DoOnceOnly("find key")) {
        player.Say("I found a key!");
        PlaySound(4);
        player.AddInventory(inventory[11]);
      }
      else {
        player.Say("I didn't find anything else.");
      }

Instead of "find key", you can use whatever text you want, the only important thing is that you use a different text for each time you use Game.DoOnceOnly.

Flyman


SMF spam blocked by CleanTalk