0 votes
by (470 points)

Hello. I use Simple Inventory System by ChapelR now and i have a some questions.

First. While i creating a new inventory with some items in StoryInit

<<newinventory '$rightmenu' 'a'>>

a have something like "Error [StoryInit]: <<newinventory>>: incorrect number of arguments" but this guide says what i can do this. 

Second. In default strings i set empty to empty.

defaultStrings : {
        empty     : '',
        ..
    }

Next made an epmty inv and try to make a condition

<<if $backpack.has('')>>
  do something..
<</if>>

but its not works. Its possible to do this or something like this?

and last. How i can transfer all items from 1st inv in <<transfer>> macros?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

Your 1st issue is due to an inconsistency between the documentation and the current version of the code for the <<newinventory>> macro. I have notified ChapelR of this inconsistency.

Your 2nd issue may be due to a misunderstanding about what the defaultStings option is for.

A number of the macros included with Simple Inventory Library automatically output a text message under certain conditions, one such macro is the <<inventory>> macro which outputs a pre-determined message if the passed inventory variable contains no items. (is empty).

The defaultStrings option allows you to change some of these pre-determined messages, such as what is displayed by the <<inventory>> macro when an inventory is empty.

eg. Adding the following to the correct location within the Story Javascriprt area will change the empty inventory message from its default of "The inventory is empty..." to be "Narda, Nothing, Zilch!" instead.

setup.simpleInv.options.defaultStrings.empty = 'Narda, Nothing, Zilch!';


Your 3rd issue is due to you using the wrong technique to programmatically check if an inventory is empty.

The purpose of the <inventory>.has() function is to check is an inventory contains a specific String value, this means that your <<if $backpack.has('')>> code is actually checking if the backpack contains an Empty String value and not if the backpack is empty.

There isn't currently a documented method to programmatically determine if an inventory is empty, and I have notified ChapelR about this.

WARNING: The following temporary solution relies on an undocumented feature of the Simple Inventory library, and as such it shoud be used with caution as it may cease working in the future.

Each inventory variable currently has a hidden property named inv which references the Array used to contain that inventory's items. The length property of that Array can be used to determine how many items are in that inventory.

<<if $backpack.inv.length === 0>>
  The Backpack is empty, do something..
<</if>>

 

by (63.1k points)
I'll be updating the simple inventory soon to address these issues.
by (470 points)
edited by
Oh, thank you! This questions has been bothering me for a month. But what about <<transfer>>?

I mean, what how i can transfer all items what contains in first inventory from which the transfer will take place?
by (63.1k points)

To transfer all the items, something like this sbould work: 

<<transfer $treasureChest $playerInventory $treasureChest.toArray()>>

The <inventory>.toArray() method will take all the items in the given inventory in question and turn them into an array, so the above call will take all the items in $treasureChest and put them in $playerInventory, while also removing them from $treasureChest. 

by (470 points)
It works. Thank you!
by (63.1k points)
I've updated the simple inventory to fix the behavior of <<newinventory>> (it was erroniously changed in version 2.1.0), and add two new methods, <inventory>.count() and <inventory>.isEmpty().
by (470 points)

I hurried with the answer. This guy still not working. Page is just refreshing without changings

<<if !($player.righthand.isEmpty())>>
  <<link 'Unequip'>>
    <<transfer '$player.righthand' '$backpack' '$player.righthand.toArray()'>>
    <<refresh>>
  <</link>>
<</if>>

while <<refresh>> contains

<<widget "refresh">>
	<<script>>
		state.display(state.active.title, null, "back")
	<</script>>
<</widget>>

This macros need to unequip items from right hand to backpack if righthand is not empty. Empty is working now and its amazing, thankies again :^)

...