Re: Coding Money??
Posted: Sat Nov 14, 2009 3:26 pm
No, I haven't tried it yet but I'll stick around to update the wiki if problems arise.
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
Use overlay like so:Meji wrote:But, the thing is, I would like to have the current amount of gold you have shown in the upper right corner of the game.
Any tips on how to fix this?
Oh, and one should easily be able to hide it, in case some epic BG scenes were to be shown.
Code: Select all
init python:
gold=10
show_money=False
def money_overlay():
if show_money:
ui.frame(xalign=1.0)
ui.text("Gold = "+str(gold))
config.overlay_functions.append(money_overlay)
label start:
$ show_money=True
"Game starts..."
$ show_money=False
show Epic BG Scene
"Epic BG scene showing so the overlay is not shown."
Code: Select all
>>> inv = []
>>> items = {}
>>> items["hp_bottle_small"] = {"price": 10, "itemName": "Small health bottle"}
>>> items["hp_bottle_big"] = {"price": 20, "itemName": "Big health bottle"}
>>> inv.append(items["hp_bottle_small"])
>>> inv.append(items["hp_bottle_big"])
>>> print inv[0]
{'price': 20, 'itemName': 'Small health bottle'}
>>> print inv[0]["itemName"]
Small health bottle
Code: Select all
>>> inventoryOwner = {} # Create dictionary for characters who have inventory
>>> items = {} # Create dictionary for items
>>> items["hp_bottle_small"] = {"price": 10, "itemName": "Small health bottle"} # Create item "Small health bottle"
>>> items["hp_bottle_big"] = {"price": 20, "itemName": "Big health bottle"} # Create item "Big health bottle"
>>> inventoryOwner["Roger"] = [] # Create inventory for "Roger" character
>>> inventoryOwner["Rabbit"] = [] # Create inventory for "Rabbit" character
>>> inventoryOwner["Roger"].append(items["hp_bottle_small"]) # Add small bottle for Roger
>>> inventoryOwner["Rabbit"].append(items["hp_bottle_big"]) # Add big bottle for Rabbit
>>> inventoryOwner["Rabbit"].append(items["hp_bottle_small"]) # Add small bottle for Rabbit
>>> print inventoryOwner["Roger"][0]["itemName"] # Print name of first item of Roger
Small health bottle # ...
>>> print inventoryOwner["Rabbit"][0]["itemName"]
Big health bottle
>>> print inventoryOwner["Rabbit"][1]["itemName"]
Small health bottle
>>> for i in inventoryOwner["Rabbit"]: # Here we check if Rabbit has Big health bottle, and if he has then remove it
... if (i["itemName"] == "Big health bottle"):
... inventoryOwner["Rabbit"].remove(items["hp_bottle_big"])
...
>>> print inventoryOwner["Rabbit"]
[{'price': 10, 'itemName': 'Small health bottle'}]
Code: Select all
init:
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
$ nar = Character(' ', color="#c8ffc8")
$ roger = Character('Roger', color="#c8ffc8")
$ rabbit = Character('Rabbit', color="#c8ffc8")
# The game starts here.
label start:
"This is demostration of inventory system using python dictionaries."
"Dictionaries are quite similar to lists and arrays."
"Arrays can be pointed only with number, but dictionaries have 'keywords' which can be pointed to."
"Arrays are defined as [], and dictionaries as \{}"
python:
inventoryOwner = {} # Create dictionary for characters who have inventory
items = {} # Create dictionary for items
items["hp_bottle_small"] = { # Create item "Small health bottle"
"price": 10,
"itemName": "Small health bottle"
}
items["hp_bottle_big"] = { # Create item "Big health bottle"
"price": 20,
"itemName": "Big health bottle"
}
inventoryOwner["Roger"] = [] # Create inventory for "Roger" character
inventoryOwner["Rabbit"] = [] # Create inventory for "Rabbit" character
inventoryOwner["Roger"].append(items["hp_bottle_small"]) # Add small bottle for Roger
inventoryOwner["Rabbit"].append(items["hp_bottle_big"]) # Add big bottle for Rabbit
inventoryOwner["Rabbit"].append(items["hp_bottle_small"]) # Add small bottle for Rabbit
# Here we point DIRECTLY to certain item in inventory.
# Number is indicating inventory slot
$ item = inventoryOwner["Roger"][0]["itemName"]
roger "I have %(item)s"
$ item = inventoryOwner["Rabbit"][0]["itemName"]
rabbit "I have %(item)s"
$ item = inventoryOwner["Rabbit"][1]["itemName"]
rabbit "I also have %(item)s"
"Lets see ones more what items Rabbit has:"
# This following python code could be written as user-defined function, but here is just an quick example
python:
slot = 0
remove_item = False
for i in inventoryOwner["Rabbit"]: # Here we go through Rabbits inventory ...
nar (inventoryOwner["Rabbit"][slot]["itemName"]) # ... print what it contains
if (i["itemName"] == "Big health bottle"): # And if there is Big health bottle...
remove_item = items["hp_bottle_big"] # ... then we mark it to be removed
slot += 1
if remove_item: # Read: "If remove_item is not False"
inventoryOwner["Rabbit"].remove(remove_item) # Then: Remove this item
"But because we took \"Big bottle away\", he has now:"
python:
slot = 0
for i in inventoryOwner["Rabbit"]:
nar(inventoryOwner["Rabbit"][slot]["itemName"] + ", which you can buy for " + str(inventoryOwner["Rabbit"][slot]["price"]) + " gold")
slot += 1
"So there is inventory system for you. Piece of cake!"