Default points?

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
CellHG
Regular
Posts: 61
Joined: Fri May 05, 2017 3:01 pm
Contact:

Default points?

#1 Post by CellHG »

So I'm using a points system to keep track of cash & I've come to something i don't know...

Basically the cash default is $50, so I've done "default cash = 50" as my code.

When ever I want to add or take cash I use "$ cash +=10" and same for minus.

However, I've come to a scene where someone needs to give all his remaining money to another person, but at the point in the game the user can have either $50 still or $30 ( as he had the option to lend $20 earlier in the game ).

Is their a way to take all the cash off the person without doing "$ cash -=30" or "$ cash -=50"? as if I do it as -30 then the person would be left with 20 if they didn't lend the cash out earlier and would be -20 if I did -50 but if they didn't lend the cash out...if that makes any sense xD

I'd assume i'd use an if statement?

Like:

if $cash >30:
then just -30
elif $cash >30:
then take -50

as the character has over $50...but i'm not sure how to write it xD

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: Default points?

#2 Post by mitoky »

I am not that good with coding, but wouldnt it work if write:
$ cash = 0
Since you want to give everything away it doesnt matters what you had as you can simply make it zero then.

As said, not that good with coding yet so if someone can confirm it or has a better solution that would be appreticiated.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Default points?

#3 Post by Imperf3kt »

If you're taking all of the cash, you can just do it the simple way:

Code: Select all

$ cash = 0
but for references' sake, lets say you do it the proper way, because it may be useful in future. I'll also show two ways you can test the value.

Code: Select all

# First, we test the biggest number. The following says "if there's more than $49", i.e. $50
if cash > 49:
    $ cash -= 50
#Now we test to see if the value is 30. Since this will only happen if the first line fails, it will only happen if there's less than $50
elif cash = 30:
    $ cash -= 30
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

CellHG
Regular
Posts: 61
Joined: Fri May 05, 2017 3:01 pm
Contact:

Re: Default points?

#4 Post by CellHG »

Ahhh, So i was on the right lines with the if's, I put if cash >= 50: and it wasn't work xD now i see what i did wrong, thanks =]

Post Reply

Who is online

Users browsing this forum: Google [Bot]