need help with code for a money system

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
User avatar
Lucky1443
Regular
Posts: 128
Joined: Tue Jul 07, 2015 11:59 am
Projects: SACRIFICE
Tumblr: Lucky1443
Deviantart: Lucky1443
Contact:

need help with code for a money system

#1 Post by Lucky1443 »

I need some help adding to the money system code, where if you don't have enough money you cant buy something, I can't really think of a way too do that.
OPEN for SPRITE/CG ART viewtopic.php?f=62&t=38654 FREE TO USE ASSETS viewtopic.php?f=52&t=39634

User avatar
chocojax
Miko-Class Veteran
Posts: 705
Joined: Sun Oct 25, 2009 11:27 am
Projects: Umbra, Familiarity, Maleficent Justice
Tumblr: chocojax
Location: California
Contact:

Re: need help with code for a money system

#2 Post by chocojax »

You could do something simple like:

Code: Select all

# assuming money is a global var
def check_money( item_cost ):
    if money < item_cost:
        return False # cannot buy
    return True # can buy, probably add code to add/have the item

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: need help with code for a money system

#3 Post by trooper6 »

I you don't know much about Python, I'd recommend you take the free course over at codeacademy.com
I say this because a money system is mostly just some basic python.
If is an if statement.

Code: Select all

if money < cost:
    "You don't have enough money."
else:
    "You have enough money."
You might want to look over this thread I posted in as well. http://lemmasoft.renai.us/forums/viewto ... +inventory

But to the code academy python course.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Lucky1443
Regular
Posts: 128
Joined: Tue Jul 07, 2015 11:59 am
Projects: SACRIFICE
Tumblr: Lucky1443
Deviantart: Lucky1443
Contact:

Re: need help with code for a money system

#4 Post by Lucky1443 »

trooper6 wrote:I you don't know much about Python, I'd recommend you take the free course over at codeacademy.com
I say this because a money system is mostly just some basic python.
If is an if statement.

Code: Select all

if money < cost:
    "You don't have enough money."
else:
    "You have enough money."
You might want to look over this thread I posted in as well. http://lemmasoft.renai.us/forums/viewto ... +inventory

But to the code academy python course.
For my game how would I change the code, because I can't keep track of what choices people pick that may give them more money, so that if the amount of money they have is more than the cost they can buy it, and if they have to little they cant? sorry If i sound confusing
OPEN for SPRITE/CG ART viewtopic.php?f=62&t=38654 FREE TO USE ASSETS viewtopic.php?f=52&t=39634

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: need help with code for a money system

#5 Post by trooper6 »

Lucky1443 wrote: For my game how would I change the code, because I can't keep track of what choices people pick that may give them more money, so that if the amount of money they have is more than the cost they can buy it, and if they have to little they cant? sorry If i sound confusing
You do not sound like you know anything about how to use basic variables. But you also want to do complicated things that will necessitate understanding how variables work.

What I recommend doing, rather than just asking for some code you don't understand (and what you are asking for is a complete inventory system), you should learn some basic Python so you can do what you want and better understand what help people give you.

Go to codeacademy.com and take their free basic Python course. The whole hing takes maybe 12 hours. You can do it in a weekend and it will make you much better able to do what you are asking as well as help you with everything else you might want to do with your game.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Lucky1443
Regular
Posts: 128
Joined: Tue Jul 07, 2015 11:59 am
Projects: SACRIFICE
Tumblr: Lucky1443
Deviantart: Lucky1443
Contact:

Re: need help with code for a money system

#6 Post by Lucky1443 »

Ok thanks
OPEN for SPRITE/CG ART viewtopic.php?f=62&t=38654 FREE TO USE ASSETS viewtopic.php?f=52&t=39634

User avatar
mediawriterdude
Newbie
Posts: 12
Joined: Fri Sep 04, 2015 10:55 am
Completed: None
Projects: None! Starting from Scratch!
Organization: V. Valdemar
Location: Somewhere in New England
Contact:

Re: need help with code for a money system

#7 Post by mediawriterdude »

trooper6 wrote:
Lucky1443 wrote: Go to codeacademy.com and take their free basic Python course. The whole hing takes maybe 12 hours. You can do it in a weekend and it will make you much better able to do what you are asking as well as help you with everything else you might want to do with your game.
I don't know if this question has been asked before, but... What recommendations would anyone make on off-line resources for learning Python? Any books?

I currently lack a dedicated internet connection, and learning on-line would be impossible! :cry:
__________________________________
Greatest Retro Show Opening Of All Time:
https://youtu.be/j2PoXfZdYVU

Also, Anime:
https://youtu.be/jjieygKSXpQ

__________________________________

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: need help with code for a money system

#8 Post by philat »

You can buy Learn Python the Hard Way, which is both more difficult and a bit more tedious than the codecademy course, but available with video classes and a full pdf, which you can just download and print out. You can do the practice questions without an internet connection once you set up python and powershell on your computer. You can also just print out the book part only for free, but do consider supporting the author if you find you're benefiting from the book.

User avatar
mediawriterdude
Newbie
Posts: 12
Joined: Fri Sep 04, 2015 10:55 am
Completed: None
Projects: None! Starting from Scratch!
Organization: V. Valdemar
Location: Somewhere in New England
Contact:

Re: need help with code for a money system

#9 Post by mediawriterdude »

philat wrote:You can buy Learn Python the Hard Way, which is both more difficult and a bit more tedious...
Thank you for the quick reply, philat! I'm gonna look into this. :D
__________________________________
Greatest Retro Show Opening Of All Time:
https://youtu.be/j2PoXfZdYVU

Also, Anime:
https://youtu.be/jjieygKSXpQ

__________________________________

Post Reply

Who is online

Users browsing this forum: No registered users