Two Questions about Creating an Inventory

56 views
Skip to first unread message

cressid...@gmail.com

unread,
Jan 6, 2015, 10:38:42 AM1/6/15
to twee...@googlegroups.com
Okay, I have two questions when it comes to arrays.  I am creating an array called $inv for inventory.  I have a link on the left sidebar to check inventory, and when you click it, it takes you to a room that has

<<print $inv >>

So two questions:

1. When you start the game, I want to display the message "You have nothing" when you click that check inventory link.  But once you pick up items, I want it to display the items in the array.  How do I create the <<if>><<else if>> statement so it displays one message if the array is empty and another message if the array has objects?

2. Currently, when I do <<print $inv >>, it gives the list like this:

milk,eggs,sugar

I want it to give the list with one object per line so it looks like this:

milk
eggs
sugar

Is there a way to set it to that?  Maybe by CSS?

Thanks!

cressid...@gmail.com

unread,
Jan 6, 2015, 11:26:44 AM1/6/15
to twee...@googlegroups.com
And with another hour of tinkering, I think I found the solution.

The inventory checking room now contains this one piece of code:

<<if $inv is 0>>You have nothing.<<elseif>><<print $list = $inv.join('\n');>><<endif>>

It prints "You have nothing" if you haven't picked up anything, and it prints the list in a column if you have.

Reply all
Reply to author
Forward
0 new messages