Check that I have another inventory item before actions taken with an inv item

Started by barefoot, Thu 17/12/2009 15:50:44

Previous topic - Next topic

barefoot

Hi,

I have the following code which works fine. What I need to do is have it check that i have another inventory item (lamp) before it proceeds... else displays the message 'I think you need to get aomething before you enter'...

How would I add this to following code I already have...



function hHotspot2_Interact()
{
cRedpants.Say("It's locked");
}

function hHotspot2_UseInv()
{
if (player.ActiveInventory ==pin1) {
 
   Display("You use the metal catch to unpick the door");
  object[9].Visible = true;

  cRedpants.Say("Yes, its open, come on guys!");
   cRedpants.Walk(342, 329, eBlock);
   player.ChangeRoom(58, 597, 411);

}
   else cRedpants.Say("That won't work");
 
}

any help would be appreciated

Thanks

barefoot
I May Not Be Perfect but I Have A Big Heart ..

Calin Leafshade

player.HasInventory.. or something like that.. check the manual

EDIT: also i would avoid "you need something else" type things.. they are arbitrary and stupid.. despite the fact i use one in McCarthy..

Khris

if (player.HasInventory(iLamp)) ...

Please RTFM and use the search function.

barefoot

hi

thanks

C...  Not always stupid, but you said it...   thanks anyhow...

K... WDYPO ..  thanks

barefoot



I May Not Be Perfect but I Have A Big Heart ..

Calin Leafshade

Yes, always stupid.

"I think you need to get something else before you enter"
Who thinks that? and why?
The door is unlocked but they cant go because some omnipresence says so?
Bullshit.

Secondly, Khris raises a perfectly good point. This is a basic function mentioned in the manual.
WDYPO is just rude.

barefoot

Calin

All points are taken... and i do appreciate any help i can get.. including the manual etc etc...which I am doing and have only been involved with 3.1.2 for 2 weeks......

It does get annoying when people have to say the last word.. in a negative
way... we are all here to help or receive help... in a positive way... stupid as it may be at times...Im only human..lol

The Manual does show both functions but NOT when used together... ie ActiveInventory and Hasinventory (which is why I asked)

OK, why then? :

There is a door. You have a pick in the inventory to open it..

At the moment.. the Room you then enter is dark, a few words are said "why dont you use the lamp?   the room then changes to another dupicate Room where it uses the Flashlight  plugin...

But of course you need to collect the lamp before you enter to make it authentic..... at the moment the Room changes even though I have not collected the Lamp.

That is why I wanted to add the point of checking if inv has another item before you can enter the Room after you have picked the lock...


In any game its all about fantasy and imagination...

thanks Calin

I May Not Be Perfect but I Have A Big Heart ..

Crimson Wizard

Quote from: barefoot on Thu 17/12/2009 16:59:52
In any game its all about fantasy and imagination...

as well as when reading manual sometimes ;)
Khris can be rude, but... seriously, use some imagination! How I would seek a solution in this case? I already know that character has parameter such as ActiveInventory and function such as AddInventory. So, I open Help Index and type in "character" and see "Character functions and properties" topic. Open that. There's a list of all functions and properties. I scan it down reading each line...
Blast! there's "HasInventory" function! I already guess what it does, but just in case I click on the link and make sure it is what I want.
That's how I was studying AGS... and everything else, by the way.
Just small advice, to save your own time (seriosly, using this method DOES save time) :)

barefoot

Thanks Crimson

at least an intelligent, nice way of putting things reply... thanks

I guess certain persons dont have much patience, but im not holding it against them and im sure they have much knowledge...

I am not one to give up at any cost... I have learnt to use quite a few of the functions, but sometimes the obvious is not always obvious at the time, if you catch my drift.. but i am steadily learning...

if the manual were not so many pages i would print it out because being almost blind i have a job to read it on screen and printing it would make it easier....anyhow..

thank you again

barefoot





I May Not Be Perfect but I Have A Big Heart ..

Helme

Argh... I thought the only way to do this is if (player.InventoryQuantity[iLamp.ID]==true)...

monkey0506

Checking "if (player.InventoryQuantity[iLamp.ID] == true)" is technically comparable to checking "if (player.InventoryQuantity[iLamp.ID] == 1)" which is why I would highly recommend you don't do that. The Character.HasInventory(InventoryItem*) function is fairly new but simplifies the process, such as, "if (player.HasInventory(iLamp))". However if you're going to work with Character.InventoryQuantity, you should always use integer values. For example if you have "show multiple inventory items multiple times" (I forget what this is actually called) turned off and are using the character's inventory to store money and you check "if (player.InventoryQuantity[iMoney.ID] == true)" the condition will only pass if the player has exactly one of the iMoney item. If the player has $250 then this condition would return false.

And barefoot I don't think you should take this too personally but just an observation: You have been posting a lot of threads with what could generally be considered easily answered questions. Obviously you already know about the manual, but you may also want to look at the Beginner's FAQ. If you can't find what you're looking for there both the wiki search and the forum search are useful tools as well. And you may not know this, but there are 3 different ways to navigate the CHM help file (the manual). You have the "Contents" tab which has everything in an organized, structured tree view; the "Index" tab which lists every property, function, and page in the manual in alphabetical order; and the "Search". With regard to this thread specifically, I think it would be logical to search for something such as "player has inventory" to check whether the player has an inventory item. I put that into the manual's search tab and the very first page is "Character functions and properties". As I scroll down each of the words I entered is highlighted, and when I come across the entry for "Character.HasInventory" there's 8 different words highlighted in that section, definitely enough to catch your eye and make you look whether that can help point you in the right direction. And what do you know! It's the exact function you were trying to find.

Asking for help is not bad. You're trying to find an answer to your questions so you can make your game. You're trying to understand. But the reason you're getting some of the responses you are (RTFM and the like) is because it seems that you're not utilizing the tools you have at your disposal before you just come here and post these questions. I'm not anybody particularly special around here, I'm just a regular member. But from one member to another, use your tools. It will help. If you still can't find an answer, tell us what you did to try and find the answer. Tell us what you put in on the manual and forum search functions. Tell us what came up. Are you confused as to what you found? Didn't see anything that seemed relevant? Still not entirely clear? This type of information will help us understand what you've done, and make sure that we have the full picture. Because the way it seems now it comes across that you're not taking full advantage of the resources available to you.

So maybe next time just look a little harder before you post. Trust me, once you get in the habit of doing that, you'll find that you have to post for help less and less often, and you'll find that you might even be able to start assisting others yourself! :D

barefoot

Hi Monkey

cheers mate.. nice reply....

I am begining to put things together, and its quite a rewarding experience. I am understanding the Manual more and trying each function out if I come across a situation where it sounds a good idea...(using my imagination)..  Apart from that I can try different things out and see how it goes..

EG:  I have used the 'manual scaling' function to makes characters get smaller a bit at a time... 
       Incorporated the Flashlight and Snow/Rain Plugins.. 
       Choice of more than 1 inventory item to use on object/character..

I do appreciate your answer and will NOT POST again unless absolutely stumped or have an idea not covered..

Maybe one day I'll be here to offer help and advice...

My first full length game has reach room 64 and Im hoping to have it completed by just after xmas, proberbly just into the new year...    Entitled Redpants: The Princess and the Beanstalk...   

Thanks again Monkey

barefoot


I May Not Be Perfect but I Have A Big Heart ..

Khris

Quote from: monkey_05_06 on Fri 18/12/2009 15:01:57
Checking "if (player.InventoryQuantity[iLamp.ID] == true)" is technically comparable to checking "if (player.InventoryQuantity[iLamp.ID] == 1)" which is why I would highly recommend you don't do that. The Character.HasInventory(InventoryItem*) function is fairly new but simplifies the process, such as, "if (player.HasInventory(iLamp))". However if you're going to work with Character.InventoryQuantity, you should always use integer values. For example if you have "show multiple inventory items multiple times" (I forget what this is actually called) turned off and are using the character's inventory to store money and you check "if (player.InventoryQuantity[iMoney.ID] == true)" the condition will only pass if the player has exactly one of the iMoney item. If the player has $250 then this condition would return false.

The arguably best method here is to use if (player.InventoryQuantity[iLamp.ID]) ...; this will return true for everything except 0.

I've seen lots of people use if (stuff == true) instead of if (stuff) and it seems to be not only ugly and superfluous but also error prone.

Crimson Wizard

Quote from: monkey_05_06 on Fri 18/12/2009 15:01:57
Checking "if (player.InventoryQuantity[iLamp.ID] == true)" is technically comparable to checking "if (player.InventoryQuantity[iLamp.ID] == 1)"
Oh no, that's not what I expected to hear from guy who wrote a number of modules for AGS  :P

monkey0506

The arguably best method in newer versions of AGS is to just simply use "if (player.HasInventory(iLamp))" coz it's shorter. :P However the "if (player.InventoryQuantity[iLamp.ID])" method is more compatible with older versions, so if you were writing for example a script module that specifically deals with inventory management or some such you might consider using the InventoryQuantity for that purpose. When I said specifically to "always use integer values" when working with InventoryQuantity, I was of course referring to checking the actual quantity. Logically all of the following do the exact same thing though:

Code: ags
if (player.HasInventory(iLamp)) {}
if (player.InventoryQuantity[iLamp.ID]) {}
if (player.InventoryQuantity[iLamp.ID] > 0) {}
if (player.InventoryQuantity[iLamp.ID] >= 1) {}


If any one of those was considered true they would all evaluate as true. But comparing the InventoryQuantity to the literal value of true would, as I said, only pass as true if the InventoryQuantity was exactly one. :D

And barefoot, I wasn't trying to completely defer you from posting EVER, but I was just suggesting that if you put forward a little more effort on your own part that you'll be a lot less likely to 1) have to post as much and 2) get told to read the manual/use the forum search/search the wiki, etc. Of course you're welcome to post when you need assistance, but there are other tools available that will often yield results faster than waiting around for somebody to post a response. Telling you to use your resources isn't just to prevent posts like these that have simple answers, it's also (and perhaps even primarily) to help you (although it may not always seem like it). Don't be discouraged if you don't find an answer right away just think of where else you might be able to look that you haven't yet, and if you still need help then feel free to post. That's what the forums are here for! :=

barefoot

Hi Monkey..

yes, i understand.. cheers... just need to rectify an outstanding issue..


UPDATE.. 'I have decided to use Regions true/false for the time being'....

END OF UPDATE...


When my player goes onto a region he needs to have the sword (not isword but sword).

Going by whats been said and the manual I have tried the HasInventory function when the player goes onto a region that goes to another Room..

The code I have put:


}
function region2_WalksOnto()
 
 if (player.HasInventory(sword))

player.ChangeRoom(23, 55, 371);
}
 else
 cRedpants.Say("Can't go just yet, I need something important);
{

I get:

Failed to save room room22.crm; details below
room22.asc(44): Error (line 44): Expected '{'


I have tried putting { on line 44 but to no avail..

Barefoot


I May Not Be Perfect but I Have A Big Heart ..

monkey0506

Quote}
function region2_WalksOnto()
 
  if (player.HasInventory(sword))

player.ChangeRoom(23, 55, 371);
}
  else
  cRedpants.Say("Can't go just yet, I need something important);
{

I'm sorry but WTF is going on here?? Honestly if you typed this you seriously need to take a look at the scripting tutorial before you continue any further. From what's written here the code should look more like this:
// removed closing brace (where was this even coming from??)
function region2_WalksOnto() { // added opening brace
  if (player.HasInventory(sword)) { // added opening brace
    player.ChangeRoom(23, 55, 371);
  }
  else cRedpants.Say("Can't go just yet, I need something important"); // added closing quotation mark
} // removed opening brace (??) and added closing brace
I honestly don't mean to sound rude but the functions you posted before made sense. Then suddenly it's as if your script threw up everywhere. :-\

P.S. You can use [code] and [/code] to encapsulate code like this:

Code: ags
function region2_WalksOnto() {
  if (player.HasInventory(sword)) {
    player.ChangeRoom(23, 55, 371);
  }
  else cRedpants.Say("Can't go just yet, I need something important");
}

barefoot

Hi

Yes Monkey, I made a bloomer big time....  could'nt quite see... but i've seen the light as they say...

I'm understanding the functions a lot better and how they work..  and yes, not only reading but actually understanding the manual is essential and has helped me move on, thanks... though it took me a while (must be because  im an 'oldie')...

Thanks again Monkey and all who helped me (Khris, Calin, Crimson etc etc)

I have actually completed my first Fantasy Adventure Game entitled Redpants: The Princess and the Beanstalk... I dont suppose you big gamers need worry, just yet...

Thanks again

barefoot







I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk