a very simple screen-based inventory
Posted: Tue Feb 25, 2014 12:47 am
Here's a simple screen language inventory for people like me ;p. All this code requires to work is some lists and for loops. If your inventory is fairly simple and you only have s few items total, making it this way seems much simpler and faster to me. Maybe it will help someone else.
All you need to do to manipulate this is to define two lists, one will keep the item names, the other will keep the amount. This way you won't have to append any lists with new items, just define the items beforehand. You can define a list like any variable anywhere in the code, but these have to be defined before you open the inventory menu.
You could combine the lists into one list but I find it easier to control and read this way.
you can now modify the amount of item like this (note, all lists start with a 0 item, not 1):
to open the screen write:
to hide:
You may also need to define the a,b variables
in screens.rpy add the code which defines the inventory screen (just put it at the end or something)
you can now modify the inventory screen in various ways
for example you can show the amount of the item
you can turn the items into buttons, you would probably have to define a new list for actions
if you define it this way, you can use it as a jump or call to a label:
If will want to have image buttons you can define another list with the image names and just repeat what I did above.
This is only a starter, you can expand or modify it in a variety of ways. For example you could add a variable based always on-screen inventory button which opens or closes the inventory. You could change the inventory buttons into pictures and so on.
All you need to do to manipulate this is to define two lists, one will keep the item names, the other will keep the amount. This way you won't have to append any lists with new items, just define the items beforehand. You can define a list like any variable anywhere in the code, but these have to be defined before you open the inventory menu.
Code: Select all
$ item_name = ["cat","dog","unkle steve"]
$ item_amount = [0,0,0]
you can now modify the amount of item like this (note, all lists start with a 0 item, not 1):
Code: Select all
$ item_amount[0] += 1 # <- adds one to the first item
$ item_amount[1] = 5 # <- sets the amount of the second item to 5
Code: Select all
show screen simple_example_inventory
Code: Select all
hide screen simple_example_inventory
Code: Select all
$ a = 0
$ b = 0
Code: Select all
screen simple_example_inventory: # <- this is how you define the beginning of a screen
frame xalign 0.5 ypos 0.1:
vbox:
for a in range (0,len(item_name)): # <- for every item on the list between 0 and list length
if item_amount[a] > 0: # <- checks if the amount of that item is more than 0
$ b = item_name[a]
text "[b]" # <-display the item name
for example you can show the amount of the item
Code: Select all
screen simple_example_inventory:
frame xalign 0.5 ypos 0.1:
vbox:
for a in range (0,len(item_name)):
if item_amount[a] > 0:
$ b = variable_name[a]
$ c = variable_amount[a] # <-checks the amount of the item
text "[b]: [c]" # <-displays both values
you can turn the items into buttons, you would probably have to define a new list for actions
Code: Select all
$ item_action = ["petthecat", "lickthedog", "biteunkle"]
Code: Select all
screen simple_example_inventory:
frame xalign 0.5 ypos 0.1:
vbox:
for a in range (0,len(item_name)):
if item_amount[a] > 0:
$ b = item_name[a]
$ c = item_amount[a]
$ d = item_action[a] # <- checks the name of the corresponding label on the list
textbutton "[b]: [c]" action Jump(d)# <-turns the items into buttons which jump to the corresponding label but you need to have a label with the corresponding name somewhere or it will error
This is only a starter, you can expand or modify it in a variety of ways. For example you could add a variable based always on-screen inventory button which opens or closes the inventory. You could change the inventory buttons into pictures and so on.