Foraging and inventory


#1

How would I go about creating a system that allows a user to forage items? It would be based on a luck stat so a higher luck means a higher chance of getting an item. I’m really just starting to figure out if statements but still think they are a little confusing. Also how is an inventory created to store items?


#2

It depends on how you want to make the item system. There isn’t a pre-made inventory system in ChoiceScript. You can make a separate variable for every single item, like a health_potion_lvl1 variable that tells you how many level one health potions you have. You can also make item_slot_1, item_slot_2, and ect up to however many item slots you want a player to have. Then you can do stuff like set item_slot_1 to “Magic boomerang” or something like that. You can also combine the two and have separate inventory and equipment sections. If a player doesn’t have an item that they shouldn’t know about yet, like an “earth orb, corrupt”, then you can put the display text for it in an if statement that checks if you have more than zero of whatever the item is. For unique items you might want to use non-numbery variables. For instance, you might have a variable has_necronomicon that can be set to “true” or “false”. You can display the items you have in the stats screen, and you can in fact have buttons in the stat screen that let you go to different pages within the stats text file, like an “inventory” page. Of course, you still want to make sure that there is an “exit” button that will use the *goto command to go to a label at the end of the stats page. You really don’t want to leave the stats page any other way, to my knowledge

You probably want to use the random number generator thing for foraging. I usually hate random numbers in CoG games, but if you don’t use a random number then you will always get the same thing when foraging depending on your luck stat. You can do something like the following:

*create forage_result
*rand forage_result 1 10
*set forage_result +whatever_you_named_your_luck_stat
*if forage_result > 19
__Wow! You must have been really lucky! You found buried treasure!
__*set gold +1000
__*set magic_amulets +2
__*set empty_treasure_chest +1
*elseif forage_result > 14
__Nice haul. You found some kind of care kit.
__*set first_aids +3
__*set food +20
__*set water +10
*elseif forage_result > 9
__Hmm… this could be useful.
__*create food_or_water
__*rand food_or_water 1 2
__*if food_or_water = 1
____*You found a dead animal. Delicious!
____*set food +12
__*else
____*You found a cactus with water in it. Delicious!
____*set water +8
*else
__Wow, you found an old boot full of holes! Wait, that isn’t very useful at all. You throw it away.

The *rand command lets you set a variable to random number from one number to another number, inclusive I think. So forage_result becomes 1, or 2, or 3… or 10. If I made it *rand forage_result 20 103, then forage_result could end up being 20, 21, 22… or 103. After that I directly added luck in. You might want to make luck count differently though. Also notice that if the person gets any forage_result from 9 to 14, they will either get food or water, randomly. Oh yeah, and the “_” are supposed to be spaces. I need to learn how to write in the fancy yellow code thing I’ve been seeing where it keeps the spacing.


#3

Oh thanks!!
I’m not doing exactly that but you really managed to get those gears in my head turning. I’ll have to experiment with it a little. I’m almost finished with chapter one which involves the background story and character development. I’ll probably write a little more then post it or something.


#4

@peglegpenguin
I was going through the forum and found this:

Also if you post < code> on the life before your code and < /code> after it (without the spaces). It will maintain the spacing (which may be important)
Hope it helps.


#5

Hooray, thank you Monkey!


#6

I don’t really want to be rude, but did u mean ‘forging’ items?


#7

Nope foraging is to gather.
Forging is to make something.
To forge counterfeit money.
To forge a sword as a blacksmith.


#8

What Myth meant is whether you might have meant forging and just made a typo.


#9

Forging would actually be pretty cool. If you’re still making the stranded game, how about making a combine item system? Stick + sharp rock = spear?


#10

Haha thats already planned which was why I needed the foraging system to find those items. An achievement will be finding all the possible items to make.