Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: frission on Thu 11/10/2007 03:17:30

Title: Text-based inventory? [SOLVED]
Post by: frission on Thu 11/10/2007 03:17:30
My game is not mouse driven and I would rather have an AGI-style text inventory (you hit tab and a little display box comes up enumerating all of the stuff you have). I plan to just cycle through the inventory, grab the names, and put them in a big string. (If they type in "look at [inv item]" then I'll display the sprite and a little description or something like that.)

Now it seemed natural to me that there would be some way to see what inventory a player had, but for all of my searching through the manual and on the forums I don't see an easy way to do it. The non-easy way would be to cycle through all possible inventory objects (and I imagine I'd have to hard-code a maximum array size to cycle through) and then use InventoryQuantity to see if the player had it. Surely there's a better way!?
Title: Re: Text-based inventory?
Post by: Khris on Thu 11/10/2007 04:02:16
readonly InventoryItem* InvWindow.ItemAtIndex[]
readonly int InvWindow.ItemCount

(readonly static int Game.InventoryItemCount)
Title: Re: Text-based inventory?
Post by: frission on Thu 11/10/2007 04:42:50
Quote from: KhrisMUC on Thu 11/10/2007 04:02:16
readonly InventoryItem* InvWindow.ItemAtIndex[]
readonly int InvWindow.ItemCount

(readonly static int Game.InventoryItemCount)

Great! Thanks!

I don't have an inventory window anymore, so those particular ones don't help, but Game.InventoryItemCount simplifies the process of figuring out whether they have an item, and keeps me from having to hard-code the value.

Here's my quicky text-only inventory display script:


function show_inventory_window () {
String inventoryListing = "You are carrying:";
int i = 0;
int inventoryCount = 0;
while(i<Game.InventoryItemCount) {
i++;
if(player.InventoryQuantity[i]>0) {
inventoryListing = inventoryListing.Append(String.Format("[ - %s",inventory[i].Name));
inventoryCount++;
}
}
if(inventoryCount>0) {
  Display(inventoryListing);
} else {
Display("You're not carrying anything.");
}
}


Of course, there's more to a text-only inventory than displaying it (I've just about finished writing a long function which processes any "look at X" where X is an inventory item and handles it separately than other things that are looked at, in this case it loads it up into a custom GUI that displays the image and a description), but it's coming along nicely.
Title: Re: Text-based inventory?
Post by: Khris on Thu 11/10/2007 07:53:22
Quote from: frission on Thu 11/10/2007 04:42:50I don't have an inventory window anymore, so those particular ones don't help
The GUI/InvWindow doesn't have to be visible. The functions will work nonetheless.
Title: Re: Text-based inventory?
Post by: Radiant on Thu 11/10/2007 12:09:27
This template (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27206.0) may be useful...
Title: Re: Text-based inventory? [SOLVED]
Post by: Blu Aardvark on Tue 16/09/2008 06:30:41
I'm designing a text-based (non-graphical) game, and found the above "quicky" script quite helpful (with a few modifications, of course).

My problem: I've discovered that I'm currently limited to displaying only 16 lines at a time, meaning only 15 inventory items would be visible, unless I changed the font or otherwise did something undesirable.

Is there a relatively simple way to space the list into two separate columns?

Here's what I'm looking at:

function show_inventory () {
String inventoryListing = "You are carrying:";
int i = 0;
int inventoryCount = 0;
while(i<Game.InventoryItemCount) {
i++;
if(player.InventoryQuantity[i]>0) {
inventoryListing = inventoryListing.Append(String.Format("[ - %s",inventory[i].Name));
inventoryCount++;
}
}
if(inventoryCount>0) {
  roomText.Text = inventoryListing;
} else {
roomText.Text = Game.GlobalMessages[996];
}
}
Title: Re: Text-based inventory? [SOLVED]
Post by: Khris on Tue 16/09/2008 11:35:46
function show_inventory () {
String inventoryListing = "You are carrying:";
int i = 0;
int inventoryCount = 0;

int rightColumn = 0;
String tmp;
int lc;

while(i<Game.InventoryItemCount) {
i++;
if(player.InventoryQuantity[i]>0) {
tmp = inventory[i].Name;
if (!rightColumn) {            // left column
lc = 25 - tmp.Length;
while (lc > 0) {
tmp = String.Format("%s ", tmp);  // add space
lc--;
}
inventoryListing = inventoryListing.Append(String.Format("[ - %s", tmp));
}
else inventoryListing = inventoryListing.Append(String.Format("- %s", tmp));   // right column
inventoryCount++;
rightColumn = 1 - rightColumn;     // alternate column
}
}
if(inventoryCount>0) {
  roomText.Text = inventoryListing;
} else {
roomText.Text = Game.GlobalMessages[996];
}
}


Not tested.
Title: Re: Text-based inventory? [SOLVED]
Post by: KiraHaraReturns on Fri 22/05/2015 18:43:49
Quote from: Blu Aardvark on Tue 16/09/2008 06:30:41
I'm designing a text-based (non-graphical) game, and found the above "quicky" script quite helpful (with a few modifications, of course).

My problem: I've discovered that I'm currently limited to displaying only 16 lines at a time, meaning only 15 inventory items would be visible, unless I changed the font or otherwise did something undesirable.

Is there a relatively simple way to space the list into two separate columns?

Here's what I'm looking at:

function show_inventory () {
String inventoryListing = "You are carrying:";
int i = 0;
int inventoryCount = 0;
while(i<Game.InventoryItemCount) {
i++;
if(player.InventoryQuantity[i]>0) {
inventoryListing = inventoryListing.Append(String.Format("[ - %s",inventory[i].Name));
inventoryCount++;
}
}
if(inventoryCount>0) {
  roomText.Text = inventoryListing;
} else {
roomText.Text = Game.GlobalMessages[996];
}
}


I would like to implement this code in my game. Can anyone explain what roomText is? I've created a textbox named roomText, but nothing happens :(
Title: Re: Text-based inventory? [SOLVED]
Post by: Khris on Fri 22/05/2015 23:28:50
A text box is for entering text; you need a label.
Title: Re: Text-based inventory? [SOLVED]
Post by: KiraHaraReturns on Fri 22/05/2015 23:42:50
ok I figured it out and it doesnt work as I expected. What I need is a list equivalent to an inventory window, but with names instead of icons. This one above creates just a list with names without implementing interactions :(
Title: Re: Text-based inventory? [SOLVED]
Post by: Khris on Sat 23/05/2015 00:05:05
There's actually a thread somewhere with code that does exactly that; the basic idea is to use DynamicSprites and draw the inventory item's name to them.
Create a global array like this:
DynamicSprite* invSprite[30];

Then iterate through the items in game start and do something like
  invSprite[i] = DynamicSprite.Create(60, 12);
  ds = invSprite[i].GetDrawingSurface();
  ds.Clear(0);
  ds.Drawingcolor = 15; // white
  ds.DrawString(1, 1, eFontNormal, inventory[i].Name);

(Not complete code)
Title: Re: Text-based inventory? [SOLVED]
Post by: KiraHaraReturns on Sat 23/05/2015 10:14:22
thanks Khrs