Coding Money??
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
- Eileen-Class Veteran
- Posts: 1686
- Joined: Mon Sep 21, 2009 8:03 pm
- Projects: E-mail me if you wanna rock the planet
- Location: USA
- Contact:
Re: Coding Money??
No, I haven't tried it yet but I'll stick around to update the wiki if problems arise.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com
https://cherylitou.wordpress.com
Re: Coding Money??
I have a simple question about this whole money-issue.
I managed to solve this "earn money, pay 10 moneyz, get item" thingy.
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.
Thanks in advance.
I managed to solve this "earn money, pay 10 moneyz, get item" thingy.
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.
Thanks in advance.
-
- Eileen-Class Veteran
- Posts: 1686
- Joined: Mon Sep 21, 2009 8:03 pm
- Projects: E-mail me if you wanna rock the planet
- Location: USA
- Contact:
Re: Coding Money??
If you look at the code for DynamicCharacter, you can get an idea http://www.renpy.org/wiki/renpy/doc/ref ... cCharacter
Any variable can take a dynamic string... or you can make a dynamic string take a variable. Hold on while I find another example on the Wiki... I'm tempted to say it's actually in the Coding Money cookbook recipe and walkthrough.
Any variable can take a dynamic string... or you can make a dynamic string take a variable. Hold on while I find another example on the Wiki... I'm tempted to say it's actually in the Coding Money cookbook recipe and walkthrough.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com
https://cherylitou.wordpress.com
-
- Eileen-Class Veteran
- Posts: 1265
- Joined: Fri Aug 31, 2007 7:02 am
- Projects: 0 completed game. Still haven't made any meaningfully completed games...
- Contact:
Re: Coding Money??
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."
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.
Re: Coding Money??
One more suggestion for handling items / inventory is by using python dictionaries. If someone has anything against this approach, please tell me, because I'm trying to evaluate the approach to use for my own project...
Basically code goes like this on python. In here we define inventory as list, and items as dictionary:
What good might this approach give you? I found this approach could make it easier to build inventory for multiple characters. We can make owner of inventory a dictionary, tell that he/she has inventory, and so that we can point certain character with a name to ask what he/she has in inventory!
Any reasons why not to do this with dictionaries? Please let me know. Otherwise, I might add this to wiki (with Renpy example of course).
Basically code goes like this on python. In here we define inventory as list, and items as dictionary:
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'}]
Last edited by reaktor on Wed Dec 09, 2009 4:32 am, edited 1 time in total.
-
- Eileen-Class Veteran
- Posts: 1686
- Joined: Mon Sep 21, 2009 8:03 pm
- Projects: E-mail me if you wanna rock the planet
- Location: USA
- Contact:
Re: Coding Money??
If it works completely, append it. Wikis are user-generated content.
Don't worry, we can get through it together. I didn't forget about you! I just got overwhelmed.
https://cherylitou.wordpress.com
https://cherylitou.wordpress.com
Re: Coding Money??
Here is stand-alone (script.rpy) demo of inventory using python dictionaries.
The reason I used this approach is that I haven't got into object oriented programming and my solutions usually rely using arrays.
Hope this gives some ideas for people. Remember to check my previous msg which had easier approach for single-owner data saving, since following demostrates more advanced approach with multiple inventory-owners.
btw. If anyone has idea how to loop through inventory without using "slot" variable, and still be able to save itemName as string, please let me know. I'm not that familiar with python programming yet and couldn't figure out how to use indexing integer with "for ... in" -loop... so this is kind of lame VisualBasic-solution
The reason I used this approach is that I haven't got into object oriented programming and my solutions usually rely using arrays.
Hope this gives some ideas for people. Remember to check my previous msg which had easier approach for single-owner data saving, since following demostrates more advanced approach with multiple inventory-owners.
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!"
Who is online
Users browsing this forum: Ahrefs [Bot], mivvy