how to add Add a counting variable(Solved)

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
kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

how to add Add a counting variable(Solved)

#1 Post by kahmehkahzeh »

So I decided since I cant figure out how to place the dialog box in the center and the options below...

I might as well get the script into the game (as it is finished)

but what I need to figure out is how to add a counting variable

choice 1 = +1
choice 2 = +0

jump end

if endcount = 1,2,3,4,5, or 6
jump badend

if endcount = 7, 8, or 9
jump normalend

if endcount = 10
jump trueend

for anyone who hasn't read my other questions this game goes through and you have a series of questions, (linear path mostly)

there is no background there is no sprites, and the goal is to have dialog in center of screen, and choices below left and right of each other. (which I haven't figured out yet).

So how would a count look?

my entire idea is basic... but my brain is saying this is how it should be.

Code: Select all

menu image with start and quit on bottom right

screen goes black, music plays white text dialog appears at about 8-12 cpm (click to fast finish each line)

choices make your end 

end selected based on your choices (3 ends) 

and that is really it. game is playable in 1 sitting
Last edited by kahmehkahzeh on Sun Apr 16, 2017 6:30 am, edited 1 time in total.

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

Re: how to add Add a counting variable

#2 Post by Imperf3kt »

you just need to use python
So you'd do something like this (if I am interpreting your question correctly)

Code: Select all

default points = 0
label start:
    menu:
        "choice 1":
            $ points += <amount># how much are we adding for selecting this option
            jump end
        "choice 2":
            $ points += <amount># how much are we adding for selecting this option
            jump end
# jump end isn't actually necessary if there's nothing between the choice menu and the next label.

label end:
    if points = 10:
        jump goodend
    elif points >= 7:
        jump normalend
    else:
        jump badend
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

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: how to add Add a counting variable

#3 Post by kahmehkahzeh »

so that's all the code needed?


and yes well the jump end wont be necessary, it was just for the example, as long as each one adds points or no points is all so example as a working script would be

Code: Select all

default points = 0
label start:
"who is your daddy, and what does he do"  

  menu:
        "an artichoke, takes over planets":
            $ points += 1 how much are we adding for selecting this option
            jump choice1        "an eggroll, a dishonor to our family and cow":
            $ points += 0 how much are we adding for selecting this option
            jump choice2
# jump end isn't actually necessary if there's nothing between the choice menu and the next label.

etc etc etc


label end:
    if points = 10:
        jump goodend
    elif points >= 7:
        jump normalend
    else:
        jump badend

figment
Regular
Posts: 33
Joined: Sat Apr 01, 2017 11:02 pm
Contact:

Re: how to add Add a counting variable

#4 Post by figment »

If a choice adds no points, you don't need +=0. Just a little cleaner to leave that out.

Also, I believe it should be ==10: or >=10.

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: how to add Add a counting variable

#5 Post by kahmehkahzeh »

alright well I will start playing with it when I get off work and see where it goes

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

Re: how to add Add a counting variable

#6 Post by Imperf3kt »

You need a new line on this line, also and some of your indentation is out. it's 4 spaces per block. Labels do not get any block level indentation.

Code: Select all

            jump choice1        "an eggroll, a dishonor to our family and cow":
It should be

Code: Select all

default points = 0
label start:
    "who is your daddy, and what does he do"  

    menu:
        "an artichoke, takes over planets":
            $ points += 1
            jump choice1
        "an eggroll, a dishonor to our family and cow":
            jump choice2

#etc etc etc


label end:
    if points == 10:
        jump goodend
    elif points >= 7:
        jump normalend
    else:
        jump badend
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

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: how to add Add a counting variable

#7 Post by kahmehkahzeh »

that makes sense, I can read code just not make it well XD

will there be a conflict if the >= 7 does not exclude 10?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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:

Re: how to add Add a counting variable

#8 Post by PyTom »

No, because points == 10 is checked first. If it's true, then points >= 7 is not checked at all.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

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

Re: how to add Add a counting variable

#9 Post by Imperf3kt »

Only if you place the check for "is equal to" 10 below the check for "is greater than or equal to" 7

By putting that first, Ren'Py will check like this:
"is points 10" no
"Is points greater than 7?" yes

Can points be 10? No, why? Because the first thing Ren'Py did was check if points were 10.

Heh, ninja'd by PyTom.
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

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: how to add Add a counting variable

#10 Post by kahmehkahzeh »

Blessed by the overlords presence! thank you both for the reply, now I have an easier question for my next one after I test this a bot, thank you again, I will edit this to solved when I get it towork :D

Post Reply

Who is online

Users browsing this forum: DewyNebula