help multiple: how to change text based on variable

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
shatteredfox
Regular
Posts: 27
Joined: Tue Oct 19, 2010 10:25 pm
Projects: Winter Blue Bells. (3%) // A Mirror of Life(20%)
Contact:

help multiple: how to change text based on variable

#1 Post by shatteredfox »

UNSOLVED

SOLVED:
1.)
How do you have a "jump" send you to another .rpy

because I have

Code: Select all

    jump GV_Test:
and everytime I get

Code: Select all

ScriptError: could not find label 'GV_Test'.
I assume there's a specific way to send to another .rpy?
2.)
How exactly do I get it where a specific text is based on a variable.

Let's say I have

Code: Select all

$ aline = 4
in the next following line I would have something similar to

Code: Select all

"You have ($ aline) points
<-- completely fake and does not work, I did however try this.
and it would come out

Code: Select all

"You have 4 points"
What is exactly the correct way to do this.
3.)
Another problem. While trying to run this it keeps looping between

Code: Select all

if aline >= 0[code]

[code]
label a_execution:
    if aline >= 10:
        "that is enough, you \"won the game\" (well rather a)"
        jump GV_End

    if aline >= 3:
        "you gained 1 experience for a. You now have 4, rank up. "
        $ aline += 1
        jump GV_Test        

    if aline >= 0:
        "you gained 1 experience for a"
        $ aline += 1
        jump GV_Test
         

label b_execution:
    if bline >= 0:
        "you gained 1 experience for b"
        $ bline += 1
        jump GV_Test
             
    if bline = 3:
        "you gained 1 experience for b. You now have 4, rank up. "
        $ aline += 1
        jump GV_Test
            
    if bline = 10:
        "that is enough, you \"won the game\" (well rather b)"
        jump GV_End            
and I get the error

Code: Select all

I'm sorry, but an uncaught exception occurred.

SyntaxError: invalid syntax (script.rpy, line 113)

While running game code:
 - script at line 113 of /Downloads/renpy-6.11.1/Test Project/game/script.rpy

-- Full Traceback ------------------------------------------------------------

  File "/Downloads/renpy-6.11.1/renpy/bootstrap.py", line 254, in bootstrap
  File "Downloads/renpy-6.11.1/renpy/main.py", line 310, in main
  File "Downloads/renpy-6.11.1/renpy/main.py", line 93, in run
  File "3/Downloads/renpy-6.11.1/renpy/execution.py", line 259, in run
  File "Downloads/renpy-6.11.1/renpy/ast.py", line 1301, in execute
  File "Downloads/renpy-6.11.1/renpy/python.py", line 994, in py_eval
  File "/Downloads/renpy-6.11.1/renpy/python.py", line 243, in py_compile
SyntaxError: invalid syntax (script.rpy, line 113)

While running game code:
 - script at line 113 of /Downloads/renpy-6.11.1/Test Project/game/script.rpy

Ren'Py Version: Ren'Py 6.11.1b


I'll probably have more and instead of cluttering the entire forum with like 40 topics by me I'm gonna just keep updating this post or posting in this topic :X.
Last edited by shatteredfox on Thu Oct 21, 2010 4:51 pm, edited 2 times in total.

fortaat
Regular
Posts: 183
Joined: Tue May 18, 2010 1:16 pm
Contact:

Re: help multiple: how to change text based on variable

#2 Post by fortaat »

2.

Code: Select all

"You have %(aline) points"
Text formatting.

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: help multiple: how to change text based on variable

#3 Post by LordShiranai »

shatteredfox wrote:1.) How do you have a "jump" send you to another .rpy

because I have

Code: Select all

    jump GV_Test:
and everytime I get

Code: Select all

ScriptError: could not find label 'GV_Test'.
I assume there's a specific way to send to another .rpy?
Jump goes to a label, not a file.

If in script.rpy, you have this:

Code: Select all

label start:
    # ...
    jump label_2
And in script2.rpy (or whatever the name is), you have this:

Code: Select all

label label_2:
    "You've reached a new label."
    #...
It should work just fine.
Don't Blame Me. I Voted for Vermin Supreme.

shatteredfox
Regular
Posts: 27
Joined: Tue Oct 19, 2010 10:25 pm
Projects: Winter Blue Bells. (3%) // A Mirror of Life(20%)
Contact:

Re: help multiple: how to change text based on variable

#4 Post by shatteredfox »

Another problem. While trying to run this it keeps looping between

Code: Select all

if aline >= 0[code]

[code]
label a_execution:
    if aline >= 10:
        "that is enough, you \"won the game\" (well rather a)"
        jump GV_End

    if aline >= 3:
        "you gained 1 experience for a. You now have 4, rank up. "
        $ aline += 1
        jump GV_Test        

    if aline >= 0:
        "you gained 1 experience for a"
        $ aline += 1
        jump GV_Test
         

label b_execution:
    if bline >= 0:
        "you gained 1 experience for b"
        $ bline += 1
        jump GV_Test
             
    if bline = 3:
        "you gained 1 experience for b. You now have 4, rank up. "
        $ aline += 1
        jump GV_Test
            
    if bline = 10:
        "that is enough, you \"won the game\" (well rather b)"
        jump GV_End            
and I get the error

Code: Select all

I'm sorry, but an uncaught exception occurred.

SyntaxError: invalid syntax (script.rpy, line 113)

While running game code:
 - script at line 113 of /Downloads/renpy-6.11.1/Test Project/game/script.rpy

-- Full Traceback ------------------------------------------------------------

  File "/Downloads/renpy-6.11.1/renpy/bootstrap.py", line 254, in bootstrap
  File "Downloads/renpy-6.11.1/renpy/main.py", line 310, in main
  File "Downloads/renpy-6.11.1/renpy/main.py", line 93, in run
  File "3/Downloads/renpy-6.11.1/renpy/execution.py", line 259, in run
  File "Downloads/renpy-6.11.1/renpy/ast.py", line 1301, in execute
  File "Downloads/renpy-6.11.1/renpy/python.py", line 994, in py_eval
  File "/Downloads/renpy-6.11.1/renpy/python.py", line 243, in py_compile
SyntaxError: invalid syntax (script.rpy, line 113)

While running game code:
 - script at line 113 of /Downloads/renpy-6.11.1/Test Project/game/script.rpy

Ren'Py Version: Ren'Py 6.11.1b

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: help multiple: how to change text based on variable

#5 Post by Alex »

3.
What is on line 113? I suppose

Code: Select all

if bline = 3:
Single equal sign (=) is used to asign values and double equal sign (==) - for comparing values, so

Code: Select all

if bline == 3:
should help.
Also check next "if" condition.

Here you can see an example of if-condition usage

And this also might be interesting for you.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: help multiple: how to change text based on variable

#6 Post by Jake »

It's also worth pointing out that Ren'Py always does stuff exactly in the order it encounters it, so if you have a series of tests in this order:

Code: Select all

    if bline >= 0:
        ...
        jump GV_Test
             
    if bline == 3:
        ...
            
    if bline == 10:
        ...
then the second two tests are never going to evaluate to true. If 'bline' is 3 or 'bline' is 10, then it will never get to those checks, because it always will have jumped off to 'GV_Test' because it always will have passed the first test (since 3 and 10 are both greater than 0).

So if 'GV_Test' is a label somewhere above this code, then that could explain why you're getting looping. For example, if you have something like this:

Code: Select all

label test:
    "Checking points"

    if myVar >= 0:
        "Level up!"
        myVar = myVar + 1
        jump test

    if myVar == 10:
        "You won!"
        jump end
then the game will loop, constantly saying "Level up!".

Say the player has 9 points when he gets here; it'll pass the first check because 9 >= 0, say "Level up!", give him an extra point (making 10) and jump to test. Then it'll pass the first test (because 10 >= 0) and say "Level up!" and give him an extra point, then jump to test. Then it'll pass the first test (because 11 >= 0) and say "Level up!" and... you get the idea.

Generally, it's best to check the least-inclusive condition first - the one that's least likely to be satisfied, and/or the one you want to override all of the other checks. So first check to see if the player has enough points to have won, because that's more important than everything else; next check whether he has enough points to have got a rank up, because that's more important than level-up, and then after both of those you can check whether he has enough points for a level up.
Server error: user 'Jake' not found

shatteredfox
Regular
Posts: 27
Joined: Tue Oct 19, 2010 10:25 pm
Projects: Winter Blue Bells. (3%) // A Mirror of Life(20%)
Contact:

Re: help multiple: how to change text based on variable

#7 Post by shatteredfox »

Jake wrote:It's also worth pointing out that Ren'Py always does stuff exactly in the order it encounters it, so if you have a series of tests in this order:

Code: Select all

    if bline >= 0:
        ...
        jump GV_Test
             
    if bline == 3:
        ...
            
    if bline == 10:
        ...
then the second two tests are never going to evaluate to true. If 'bline' is 3 or 'bline' is 10, then it will never get to those checks, because it always will have jumped off to 'GV_Test' because it always will have passed the first test (since 3 and 10 are both greater than 0).

So if 'GV_Test' is a label somewhere above this code, then that could explain why you're getting looping. For example, if you have something like this:

Code: Select all

label test:
    "Checking points"

    if myVar >= 0:
        "Level up!"
        myVar = myVar + 1
        jump test

    if myVar == 10:
        "You won!"
        jump end
then the game will loop, constantly saying "Level up!".

Say the player has 9 points when he gets here; it'll pass the first check because 9 >= 0, say "Level up!", give him an extra point (making 10) and jump to test. Then it'll pass the first test (because 10 >= 0) and say "Level up!" and give him an extra point, then jump to test. Then it'll pass the first test (because 11 >= 0) and say "Level up!" and... you get the idea.

Generally, it's best to check the least-inclusive condition first - the one that's least likely to be satisfied, and/or the one you want to override all of the other checks. So first check to see if the player has enough points to have won, because that's more important than everything else; next check whether he has enough points to have got a rank up, because that's more important than level-up, and then after both of those you can check whether he has enough points for a level up.
I assumed so which is why I changed aline to how it was. Never got to bline because I was concetrating on aline. This is my fault for accidentally including b and not being specific. I apologize. However you still managed to solve my problem thanks! ^o^.

I scrapped that test entirely and redoing it and see if I can do it properly. You guys are God among men, women, anime, and novels :o.

Post Reply

Who is online

Users browsing this forum: No registered users