Problems with inventory system


#1

I’m having trouble with programming my inventory system to actually recognise it has an item registered there. And… yet when I go to current_inventory, it still says I have no items registered in the inventory itself, what gives?

*label inventory

*if (item_amount > 0)
 ```*if (has_flour)
*set item_amount + 1
 ```*set current_inventory &"bags of flour"
  *if (has_metal)
 ```*set item_amount + 1
 ```*set current_inventory &" metal"
  *if (has_paper)
 ```*set item_amount + 1
 ```*set current_inventory &" paper"
  *if (has_pen)
  ```*set item_amount + 1
  ```*set current_inventory &" pen"
  *if (has_pencil)
  ```*set item_amount + 1
  ```*set current_inventory &" pencil"
  *if (has_sketchbook)
 ```*set item_amount + 1
 ```*set current_inventory &" sketchbook"
  *if (has_telescope)
```*set item_amount + 1
```*set current_inventory &" telescope"
```*set item_amount + 1
  *if (has_wires)
```*set item_amount + 1
```*set current_inventory &" wires"
  *else
```*set current_inventory "None"
```You have nothing in your inventory, ${name}!
```*goto current_inventory

#2

So, your [current_inventory] gives you “None”?


#3

Yes, no matter how many items I buy from the shops, the current inventory still says “None”


#4

Hmm. Just a bit of wild guess, but in the ex. you posted, the indentation seems to be off. Perhaps there’s something to do with it?


Otherwise, assuming you got the indentation right, the only thing I can think of is you haven’t set up the [has_XX] variable correctly in the shop. Or the [item_amount] stays less than 1 somehow.


#5

I’m not sure about the indentation, but it looks like you’re not actually changing item_amount unless item_amount is already above 0… :confused: If you delete *if (item_amount > 0), change the *else to *if (item_amount = 0) and reduce the indent of everything that needs it, would that work? :thinking:


#6

Could you put it into a script format so that I can understand it easier? I’m new to coding.


#7
*label inventory
*if (has_flour)
    *set item_amount + 1
    *set current_inventory &"bags of flour"
*if (has_metal)
    *set item_amount + 1
    *set current_inventory &" metal"
[etc]
*if (item_amount = 0)
    *set current_inventory "None"
    You have nothing in your inventory, ${name}!
*goto current_inventory

I think this is what you’re after, although without seeing your shop code, I can’t be sure. :thinking:


#8

Sometimes, the code gets confused, with too many *if statements at once, particularly in older versions of choicescript.

Make sure you’re using the most recent one, and…my next suggestion would be to make it

*if (has_pencil = true)

etc.

The code can get iffy, without the = true or =/= true.

It may also be getting overwhelmed, due to the number of *if statements in a row, with no *elseif or *else.

I also agree that indentation seems off.


#9

Here’s what I have now:

```Let's see what's in your backpack, ${name}!
```*if (item_amount >= 1)
```*if (has_flour = true)
    *set item_amount + 1
    *set current_inventory &"bags of flour"
  *if (has_metal = true)
    *set item_amount + 1
    *set current_inventory &" metal"
  *if (has_paper = true)
    *set item_amount + 1
    *set current_inventory &" paper"
  *if (has_pen = true)
    *set item_amount + 1
    *set current_inventory &" pen"
  *if (has_pencil = true)
    *set item_amount + 1
    *set current_inventory &" pencil"
  *if (has_sketchbook = true)
    *set item_amount + 1
    *set current_inventory &" sketchbook"
  *if (has_telescope = true)
    *set item_amount + 1
    *set current_inventory &" telescope"
    *set item_amount + 1
  *if (has_wires = true)
    *set item_amount + 1
    *set current_inventory &" wires"
  *else
    *set current_inventory "None"
    You have nothing in your inventory, ${name}!
    *goto current_inventory

*label current_inventory

[b]Current Inventory:[/b] ${current_inventory}

#10

Is it working as intended, now, or are you still having issues?


#11

I’m still having issues with the coding in regards to the fact that item never turns up in the inventory


#12

Silly question, but, in that set of code, has the player actually set any of those flags to true, yet?

IE: before this whole subroutine (I assume within the stats menu) plays out, is there any code that has run within startup.txt, or wherever else, that sets any of the values to true?

ETA:

If so, I think the issue lies within the first two lines. The program may be getting confused due to the

`*if (item_amount >= 1)
```*if (has_flour = true)
    *set item_amount + 1

especially if the code hasn’t already set item to >=1. Basically, since you’re running the "if (has_flour = true) and everything else simultaneously to "if (item_amount >= 1).

Try removing the line about item_amount >=1, if nothing else works, because, from what I’m seeing, the code is just automatically assuming “none”, due to the fact that you’re running “*if (item_amount >= 1)” before “set item_amount + 1”, which makes the program assume that item = 0

Also, it looks like your indentation is off again. Make sure to count your spaces :slight_smile: you removed a space starting with *if metal, and you only want one space for *if flour - so *if metal and all following are indented properly. *if flour is indented 1 too many times.

And yes, I do realize I have edited this a lot. I’m just noticing more things that could potentially be causing the issue, and I don’t like to double post.


#13

shops line 238: increasing indent not allowed, expected 0 was 2


#14

Oh, oops, I had a brainfart.

Yeah, the issue you might be having is that you need to have all of the *if statements at the same indentation. I brainfarted and was like “oh, you should indent it the once”, but no, it should look like…

Let's see what's in your backpack, ${name}!
*if (item_amount >= 1)
*if (has_flour = true)
 *set item_amount + 1
 *set current_inventory &"bags of flour"
*if (has_metal = true)
 *set item_amount + 1
 *set current_inventory &" metal"
*if (has_paper = true)
 *set item_amount + 1
 *set current_inventory &" paper"
*if (has_pen = true)
 *set item_amount + 1
 *set current_inventory &" pen"
*if (has_pencil = true)
 *set item_amount + 1
 *set current_inventory &" pencil"
*if (has_sketchbook = true)
 *set item_amount + 1
 *set current_inventory &" sketchbook"
*if (has_telescope = true)
 *set item_amount + 1
 *set current_inventory &" telescope"
 *set item_amount + 1
*if (has_wires = true)
 *set item_amount + 1
 *set current_inventory &" wires"
*else
 *set current_inventory "None"
 You have nothing in your inventory, ${name}!
 *goto current_inventory
 *label current_inventory
 [b]Current Inventory:[/b] ${current_inventory}

If the only issue is indentation, that will fix the problem. If that doesn’t fix the problem, remove the line

*if (item_amount >= 1)

If that still doesn’t fix the issue, we’ll have to dig a little bit deeper.

Also, I usually use fairmath EG:

*set Derrick %+5

…so I may be wrong, but your issue could also be that you’re supposed to do +1, rather than + 1. I don’t think it likes the spaces.


#15

shops line 239: invalid indent, expected at least one line in ‘if’ true block… And the errors keep on coming


#16

Can you post a screenshot of the file, so that I can see, say, lines 230-250, or more?

Like so

lol, oops, I realized this might be a better example, because it actually shows some commands -


#17

This whole page of code! :sweat_smile: Keep in mind I’m new to this


#18

As I said earlier, you really don’t want the *if (item_amount >= 1) there, as it’ll be checked before anything is actually put into your inventory. Try deleting that, and reducing the indent of *if (has_flour). Also, you don’t want to end with an *else, as this’ll activate if you don’t have any wires, overwriting any earlier inventory.

Did you try my suggestion? (I think it might need to be amended to reset the item_amount, admittedly.)

*label inventory
*set item_amount 0
*if (has_flour)
    *set item_amount + 1 
    *set current_inventory &"bags of flour" 
*if (has_metal) 
    *set item_amount + 1 
    *set current_inventory &" metal" 
[etc] 
*if (item_amount = 0) 
    *set current_inventory "None" 
    You have nothing in your inventory, ${name}! 
*goto current_inventory

#19

So … did you try fixing what it told you to fix?

Because at line 239 you have an invalid indent. Move it two spaces back so that the indent is correct.

That’s what the error “invalid indent at line 239” means.


#20

It seems to have worked, at least for now!