First item in the player's inventory?

Hi all,
I’m currently working on a game that has a “hand system”, so the player can only carry two things (left hand/right hand). Whenever the player takes anything or drops anything, it appends “(left hand)” or “(right hand)” to the message depending on how many items the player is currently carrying.

I would like to implement an item that changes depending on whether it is carried in the player’s left hand or right hand, along these lines:

The gold brick is a thing. The description of the gold brick is "[if entry 1 in the inventory is the brick]A brick that you are holding in your left hand.[else]A brick that is NOT in your left hand.[end if]"

Is there a way I can get something’s position in the player’s inventory?
Thanks!

You can’t rely on the ordering of inventory AFAIK. If you want to implement hands like this, you’ll need to add this explicitly, along lines similar to this:

Lab is a room.

The triangle is in the lab. The square is in the lab. The circle is in the lab.

a person has an object called the left hand contents.
a person has an object called the right hand contents.

Definition: a person is emptyhanded if the left hand contents of it is nothing and the right hand contents of it is nothing.			

Definition: a person is fullup if the left hand contents of it is something and the right hand contents of it is something.	

Check taking something:
	if the player is fullup:
		say "Your hands are full!" instead;
		
After taking something:
	if the left hand contents of the player is something:
		now the right hand contents of the player is the noun;
	otherwise:
		now the left hand contents of the player is the noun;
	continue the action;		
4 Likes

I think the syntax is:

if entry 1 of the list of things enclosed by the player is the brick

(You might want “carried” rather than “enclosed”, now that I think about it…)

NB this will give you a run time error if there’s nothing enclosed/carried by the player at the time it’s evaluated, so you should make sure you have a check for the inventory being empty before getting to this!

1 Like

If the player won’t be wearing anything during the game and they have a carrying capacity of two, then all you would need is the first thing held by the player and the next thing held after the first thing held by the player(after checking that the first thing held isn’t nothing) to get the first and second things. Otherwise you could look at position within the list of things carried by the player.

This accomplishes what you’re after, I think:

The carrying capacity of the player is 2.

This is the handed inventory rule:
let l be the list of things carried by the player;
if the number of entries in l > 0 begin;
  say "  [an entry 1 in l] (left hand)[line break]";
  if the number of entries in l > 1, say "  [an entry 2 in l] (right hand)[line break]";
end if;
now everything worn by the player is marked for listing;
list the contents of the player, listing marked items only, with newlines, indented, including contents, giving inventory information, with extra indentation.

The handed inventory rule is listed instead of the print standard inventory rule in the carry out taking inventory rules.

Edited: in the not leaving good enough alone department…

Chirality is a kind of value. The chiralities are left, right.

This is the handed inventory rule:
  let t be the first thing held by the player;
  let handedness be left;
  while t is not nothing begin;
    if t is carried begin;
      say "  [a t] ([handedness] hand)[line break]";
      now handedness is right;
    else; 
      now t is marked for listing;
    end if;
    now t is the next thing held after t;
   end while;
  list the contents of the player, listing marked items only, with newlines, indented, including contents, giving inventory information, with extra indentation.
6 Likes