Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Wayne Adams on Sun 01/03/2009 03:47:28

Title: Checking inventory and removing it in dialog script (SOLVED)
Post by: Wayne Adams on Sun 01/03/2009 03:47:28
Ok, so i may have missed it somewhere but i want to do inventory work in dialog scripts..

add-inv works just fine..

however if i try to check for inventory:
if (player.HasInventory(1)){
option-on 6
}
it gives me errors..

I've also searched for examples on the "run-script" command to remove inventory from player inside of a dialog, and I haven't found anything of use..

Also I'll note that I've just upgraded to 3.1.2 sp1, and all ran fine with the project.. until i started trying to be fancy that is :)

Thanks in advance guys.
Title: Re: Checking inventory and removing it in dialog script (Searched manual)
Post by: Trent R on Sun 01/03/2009 10:07:40
The obvious thing to ask if whether or not you've indented the normal script lines.

Also what kind of errors does it give you? And have you checked out the new Dialog functions in the manual? I'm not the best with dialogue, but I believe all of those will replace things like add-inv, option-on, etc. But the old ones still work due to backwards compatibility.


~Trent
Title: Re: Checking inventory and removing it in dialog script (Searched manual)
Post by: Khris on Sun 01/03/2009 12:51:13
First of all, .HasInventory requires an InvItem as parameter, not the ID.

This should do it:
if (player.HasInventory(inventory[1])) dDialog.SetOptionState(6, eOptionOn);

I'd think you can't mix dialog and non-dialog script like that, so use .SetOptionState.
Replace dDialog with the scriptname of your dialog; and for readability, replace inventory[1] with the scriptname of the inv item.
Title: Re: Checking inventory and removing it in dialog script (Searched manual)
Post by: Wayne Adams on Mon 02/03/2009 00:57:13
EDIT: This is working now, Thanks for the assist, Khris..
I think I understand the formatting and usage of the dislog script versus normal scripting a little better.


So, I tried running the dialog with the command in the format you gave Khris.. however. AGS still reports an undefined command..
Also.. in 3.1.2 sp1 the error reporter gives lines, but in the dialog script doesn't list the code with lines.. is there a way to toggle line numbers in dialog script?


EDIT: Sorry. here is the new line:

if (player.HasInventory(iInventory1)) dThornOldWatch.SetOptionState(6, eOptionOn);


Where iInventory1 is item in question, and dThornOldWatch is the dialog plant should be used in.



Title: Re: Checking inventory and removing it in dialog script (SOLVED)
Post by: Trent R on Mon 02/03/2009 07:37:01
But notice how Khris put a space in front of his line? If you wanted to, you could indent it 10 spaces. It just needs at least one to know to run it as a normal script line rather than dialogue.

[Edit]: Also, is your item actually called iInventory1? That seems like a hassle... much more readable script to called it iKey or iShoe or whatever. Khris used the inventory[] array which can be useful for things like while loops and when you don't know a specific item. But either one works really.

About the numbered lines in the dialog editor, I believe someone requested that in the Wishlist thread. I don't think it would hurt to go quote that post and add your support to it.



~Trent