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.
-
wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
-
Contact:
#1
Post
by wyverngem » Mon Aug 20, 2012 1:11 pm
I've been looking for an answer, but I'm not sure this is right. I have a basic payday system where you get paid on the 28th. It activates right, but it doesn't do the math. Did I write it wrong?
Code: Select all
if day == 28: #Payday
if LDeductions = True: #Late last month take 10% from pay.
$ pay += (((baserate * PLevel) * 28) - 10%)
else:
$ pay += ((baserate * PLevel) * 28) #base rate (5 x PlayerLevel) x 28 days.
ttext "After deductions I recieve [pay] gold."
$ coins += pay
$ pay = 0
Last edited by
wyverngem on Mon Aug 20, 2012 9:03 pm, edited 1 time in total.
-
netravelr
- Miko-Class Veteran
- Posts: 504
- Joined: Thu Jan 28, 2010 2:31 am
- Completed: Culina: Hands in the Kitchen, Culina: The Spirit of Cooking, Saving Zoey
- Projects: Love at the Laundromat
- Organization: Lakeview Interactive
- Deviantart: netravelr
- Location: USA
-
Contact:
#2
Post
by netravelr » Mon Aug 20, 2012 1:20 pm
The problem is the %. that's not 10%, that's the modulo operator which is really confusing to people starting out with programming.
What you could do is:
Code: Select all
$ pay = (((baserate * PLevel) * 28) )
$ deductions = pay * .1
#assuming you what a whole number
$pay = int(pay - deductions)
That help?
Technical Designer/Programmer
Game Design Portfolio - Project updates on my
Twitter
Experienced in: C/C++/C#, Python, Unreal, Unity, and Flash
_________________
"Space can be very lonely. The greatest adventure is having someone share it with you."
-
Minnfae
- Regular
- Posts: 106
- Joined: Mon Dec 07, 2009 5:01 am
- Projects: Undecided
-
Contact:
#3
Post
by Minnfae » Mon Aug 20, 2012 1:53 pm
Instead of adding a variable, you could just multiply by 0.9, and then convert to integer
Code: Select all
$ pay += int(0.9*((baserate * PLevel) * 28))
and shouldn't
be like this?
My avatar art is a freebie by SilverHyena. Thanks a lot!
-
Anima
- Veteran
- Posts: 448
- Joined: Wed Nov 18, 2009 11:17 am
- Completed: Loren
- Projects: PS2
- Location: Germany
-
Contact:
#4
Post
by Anima » Mon Aug 20, 2012 1:55 pm
Even better would be:
It's the same as Minnfae version, but more in line with python style.
Avatar created with
this deviation by Crysa
Currently working on:
- Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III
-
wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
-
Contact:
#5
Post
by wyverngem » Mon Aug 20, 2012 6:23 pm
Okay, I figured the out the percent, the first example works out great. I have a second problem. Every time I use this even in a call it runs twice. Giving the payday out twice. What happened?
Code: Select all
label PayRent: #Payday and rent events.
if day == 3:
if coins >= rent:
$ coins -= rent
if LDeduction == True:
"There, I was able to finally pay rent on time."
$ LDeduction = False
$ PDeduction = 0
else:
ttext "Room and board are always due on the 3rd of every season. Paid [rent] for rent."
jump dayplanner
else:
if LDeduction == True:
$ coins = (coins * 0.75)
ttext "Again! I don't have rent, well here's 75 percent of what I have now I guess...I'm going to be dudcuted an additional 10 percent!"
$ PDeduction += 0.1
else:
$ coins = (coins * 0.75)
ttext "I don't have enough for rent! I'll have to pay 75 percent of what I have now I guess..."
$ LDeduction = True
$ PDeduction += 0.1
if day == 28: #Payday
if LDeduction == True: #Late last month take 10% from pay.
if PLevel == 0: #This is just a safeguard if you're still level 0 the first month. I hope not!
$ pay = ((baserate * (PLevel + 1)) * day)
$ deductions = int(pay * PDeduction)
$ pay = int(pay - deductions)
else:
$ pay += (((baserate * PLevel) * day) - 10)
$ deductions = int(pay * PDeduction)
$ pay = int(pay - deductions)
elif LDeduction == False:
if PLevel == 0: #This is just a safeguard if you're still level 0 the first month. I hope not!
$ pay += ((baserate * (PLevel + 1)) * day)
else:
$ pay += ((baserate * PLevel) * day) #base rate (5 x PlayerLevel) x 28 days.
ttext "After deductions I recieve [pay] gold."
$ coins += pay
$ pay = 0
return
-
PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
-
Contact:
#6
Post
by PyTom » Mon Aug 20, 2012 6:41 pm
It's hard to say, since we don't know what you intended.
It looks like you're mostly incrementing pay (+=) rather than assigning it (=), so that could be the cause.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama •
https://www.patreon.com/renpytom
-
wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
-
Contact:
#7
Post
by wyverngem » Mon Aug 20, 2012 9:02 pm
Hmm, when I switched the day == 28 and day == 3 around ti ended up working fine. Probably just a way it's stated.
Users browsing this forum: Google [Bot], Ocelot