Stackable Inventory?

Started by Weston_Kaunk, Mon 12/01/2015 07:15:01

Previous topic - Next topic

Weston_Kaunk

I'm still super new with coding and working through the tutorials available but does anyone know a good way to have stackable items in your inventory?

I don't know if i'm "code thinking" enough yet, but would that just be using a variable to measure and switch out 1carrot with 2carrots and vice versa/ect as different objects in a big nested if statement. Or would an or/else thing be cleaner, but i think this would limit my possible total number?

I'm gonna try some things tonight but I just wanted to throw out a thing so someone could tell me if I'm way off and there's a much easier way I'm just not thinking of.
tldr: I say too much
http://westonkaunk.itch.io/

Slasher

#1
Hi,

You could change an inventory graphic (1 carrot image to show 2 carrots image) then this can be done.

In an if/else statement simply change it's graphic from there.

Unless you mean multiple separate carrots, this also can be done.

Weston_Kaunk

Quote from: slasher on Mon 12/01/2015 08:33:07
Hi,

You could change an inventory graphic (1 carrot image to show 2 carrots image) then this can be done.

In an if/else statement simply change it's graphic from there.

Unless you mean multiple separate carrots, this also can be done.

yes, I'm sorry, this is what I meant with objects, I meant inven graphics. Like it's one inventory graphic but this one represents 4 objects. /every object picked up adds to the variable which switches out the appropriate inventory graphic.. like.. I'm going to try some things tomorrow long as I find time. But, still learning, half the time I try to code a thing I either do it wrong were it breaks or I do it wrong where I took the longest route possible which leads to problems farther down the line. I've mostly just been coding in room transitions so this if/else stuff isn't something I've explored yet, I just didn't want to spend two days scribbling pseudo code then working in the code in the project, all to end up deleting it. The anxiety of that in itself is a bit of a momentum killer, going through with it and the frustration of being on the wrong track entirely is.. like you need a break for a bit after that's happened so much. 

For all I know I'm just overthinking it. I'll get back to you guys after I give it a go.
tldr: I say too much
http://westonkaunk.itch.io/

Andail

You'll probably use a global integer to keep track of the number of carrots. Then every time you use the carrot on something, or look at it, you'll first check the state of that integer.

Let's say you declare the variable
int carrotnumber;

Every time you pick up a new carrot, or lose one, you'll just use the - or + operators to modify that integer.
[upon picking up a new carrot]
carrotnumber ++;

Then when you look at the inventory item, you can use
Display ("I have %d carrots in my bag.", carrotnumber);

Just some points to help you get started, there are many things to consider and check before this works perfectly.

Matti

If you want to change the image of the inventory item according to the quantity, maybe this will help. I had a similar question years ago.

http://www.adventuregamestudio.co.uk/forums/index.php?topic=37701.msg495597#msg495597

SMF spam blocked by CleanTalk