How would you set up the inventory


Okay I want to make an inventory and add things to my inventory how would I code that


Depending on how your inventory system is, it’s not as easy as it sounds. First some details are required.

Are there limited slots or can you just carry everything? Items have different stats? Can players drop items whenever they want? Combine items?


There are limited slots (5). Items do not have different stats. They can drop stuff if they feel as if they don’t need it. no items can be combined.
I also want to know how to choose certain choices based on the stuff you have.


So you will need a counter for the current amount of items and a boolean variable for each item.

*create item_amount 0
*create has_pencil false
*create has_pen false
*create has_eraser false
*create has_sharpener false
*create has_crayon false
*create has_paintbrush false

So those will be our items. Whenever the player can pick up an item, you need to set it true and increase the item amount by 1.

You can pick up the pencil or the pen.

	#Pick up the pencil.
		*set has_pencil true
		*set item_amount +1
	#Pick up the pen.
		*set has_pen true
		*set item_amount +1
	#I won't pick up any of them.

Then later on you can use a condition to check which one the MC has on them to draw something for example.

*if (has_pencil)
	Using your pencil, you make a quick sketch.
*elseif (has_pen)
	With your pen, you are able to make a pretty drawing.
	Since you don't have anything you could draw with, you aren't able to do anything.

So if the player has too many items, you can disable them from picking up something.

	*selectable_if (item_amount < 5) #Pick up the paintbrush.
		*set has_paintbrush true
		*set item_amount +1

As for dropping items, there are two ways you could do it.

Either have it always be able to drop items (probably from the stat screen as that’s the only place in the game the player can always do something), but this could cause some unintended consequences if the player drops something in specific moments that your code is not ready for.

Or have the option to drop something to always be present when you can pick something up.

I’ll make the second one as it seems simpler, but you’ll need a *gosub for this or you’ll have to repeat code very often. We’ll need to make one common code that has the choice for dropping anything the player has.

The trick here is to only be able to drop something if you have it, so you need to list every item of the game in this choice with the condition that checks if has_x is true, so that the player is able to drop it. You can have it loop until the player picks the option to “go back” to where they were in the story. This way they can drop multiple items if they wish.

*label dropping_items
*temp dropped_item ""

	*if (has_pencil) #Drop the pencil.
		*set has_pencil false
		*set dropped_item "pencil"
	*if (has_pen) #Drop the pen.
		*set has_pen false
		*set dropped_item "pen"
	*if (has_eraser) #Drop the eraser.
		*set has_eraser false
		*set dropped_item "eraser"
	*if (has_sharpener) #Drop the sharpener.
		*set has_sharpener false
		*set dropped_item "sharpener"
	*if (has_crayon) #Drop the crayon.
		*set has_crayon false
		*set dropped_item "crayon"
	*if (has_paintbrush) #Drop the paintbrush.
		*set has_pen false
		*set dropped_item "paintbrush"
	#Go back.

*set item_amount -1
You drop the ${dropped_item} on the floor.

*goto dropping_items

So to use this *gosub, you can add it at every moment the player can drop something; here’s an example. If you want you can provide the option to drop things only if the inventory is full already; if you want to provide it anyway, simply remove the “*if (item_amount = 5)” condition from the choice.

*label paintbrush_on_floor

There is a paintbrush on the floor, you decide if you want to pick it up or not...

	*selectable_if (item_amount < 5) #Pick up the paintbrush.
		*set has_paintbrush true
		*set item_amount +1
		*goto after_paintbrush
	*if (item_amount = 5) #Drop something so I can pick up the paintbrush.
		*gosub dropping_items
		*goto paintbrush_on_floor
	#Continue without picking the paintbrush.
		*goto after_paintbrush

*label after_paintbrush

Moving on, you continue to search the location...

You’ll need to have the “dropping_items” *gosub in every file in your game if you do this method (or you can use *gosub_scene to have it on a separate file).

This should cover some of the basics for a simple inventory. If you didn’t understand something or have questions feel free to ask.

Also, here are some guides for what was used:


so how would I label it in the stats section


You mean to list the items you have in your inventory?




It’s a lot more complicated than it seems because of the commas and period. But I’ll make a simpler version here.

*temp current_inventory ""

*if (item_amount > 0)
	*if (has_pencil)
		*set current_inventory &" pencil"
	*if (has_pen)
		*set current_inventory &" pen"
	*if (has_eraser)
		*set current_inventory &" eraser"
	*if (has_sharpener)
		*set current_inventory &" sharpener"
	*if (has_crayon)
		*set current_inventory &" crayon"
	*if (has_paintbrush)
		*set current_inventory &" paintbrush"
	*set current_inventory " None."

Current inventory:${current_inventory}.

When you *set a text variable it will usually replace all of its content with whatever you’re setting, but if you add & it will only add the content to the text variable. This won’t have commas and other stuff but it will be a simple way to show the stuff the player has. The script will check the items the player is carrying and will add them to the “current_inventory” variable which will be displayed right after.


okay it’s coming up with this error

Startup line 19: Invalid expression, couldn’t extract another token.

is this right

*create name “”
*create surname “”
*create leadership 0
*create strength 0
*create agility 0
*create charm 0
*create rudeness 0
*create wealth 0
*create power 0
*create intelligence 0
*create has_food false
*create has_money false
*create has_clothes false
*create has_tools false.

Problem with invalid expression error

Remove the dot at the end from:

 *create has_tools false.


@GoldenSilver I have another problem concerning this

choicescript_stats line 36: It is illegal to fall in to an *else statement; you must *goto or *finish before the end of the indented block.

*temp current_inventory ""

*if (item_amount > 0)
 *if (has_money)
  *set current_inventory &" money"
 *if (has_clothes)
  *set current_inventory &" clothes"
 *if (has_tools)
  *set current_inventory &" tools"
 *if (has_books)
  *set current_inventory &" books"
 *if (has_food)
  *set current_inventory &" food"
 *set current_inventory " None"

Current inventory:${current_inventory}.


This is a block example:

*if something
 do something

Here are two blocks:

*if aaa
 do aaa
*if bbb
 do bbb

The error says: It is illegal to fall in to an *else statement; you must *goto or *finish before the end of the indented block.

That means you have to place a *goto or *finish at the end of the block


But i’m not trying to change the scene, end it or anything basically its supposed to add things to your inventory as you play-through in order to do certain things


Another way of thinking about what it’s asking you to do…

Mom gives you instructions, telling you to clean your room.
What should we do after cleaning the room?
We don’t know, because mom hasn’t told us anything.

*if aaa
 do aaa
 (what do we do now?)

If you don’t have a *goto or *finish at the end of the indented block, like the error code says, the code will not function properly because it did the thing you wanted, but doesn’t know what else to do afterwards.


Im thinking of it like this

If you have any random object add it to inventory


if you dont have any random object then say that there is “None>” in inventory


You can do that, but you must add *goto or *finish before the end of the indented block in your *if statements.


Where would i *goto or *finish


before the end of the indented block in your *if statements.

*if something
  do stuff
  do more stuff
  are we finished?
  *goto somelabel


CS requires a *goto, *finish, *ending or *goto_scene to be placed at the end of any *if if there is an *else on the chain. So the way to fix this you would need to do it like this:

*temp current_inventory ""

*if (item_amount > 0)
 *if (has_money)
  *set current_inventory &" money"
 *if (has_clothes)
  *set current_inventory &" clothes"
 *if (has_tools)
  *set current_inventory &" tools"
 *if (has_books)
  *set current_inventory &" books"
 *if (has_food)
  *set current_inventory &" food"
 *goto coming_down
 *set current_inventory " None"
 *goto coming_down

*label coming_down
Current inventory:${current_inventory}.

The long if chain does not require it because none of them have *else, however the first *if you used does use an *else at the end; so you need to add something to their ends.

You can deactivate this requirement for the *if/*else using implicit control flow if you wish; that would make your previous code work without any issues. More info on it here:


Ok this worked thank you again and you too Carlos.R