Is this a Renpy problem or a Python problem?

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
Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Is this a Renpy problem or a Python problem?

#1 Post by Mild Curry »

I'm making a mini-game where the player must press keys in a certain sequence in order to win, and I want the game to stop if the player makes a mistake. The former part works; the latter is giving me trouble.

Code: Select all

label practice:
  $ i = 0  
  $ right_answer = "DLRLRL"
  $ input_answer = ""
  $ end = len(right_answer)
  "Type in %(right_answer)s."
  
##input code
    
label check:
for i in range(end):
       if input_answer == right_answer[:end-i]:
         $ good = True
if input_answer == right_answer:
        jump win
if !good:
       "FAILURE."
Now, I could check it like this:

Code: Select all

if input_answer == "D":
  $ good = True
elif input_answer == "DL":
  $ good = True
And so on and so forth, but that's tedious and I will never finish it that way.

After a bit of research into Python strings and for-loops(which I have never touched before); I wrote the above, but it keeps returning this error:

Code: Select all

On line 36 of C:\Users\Curry\Documents\renpy projects\PRACTICE/game/music.rpy: expected statement.
for i in range(end):
    ^ 
It occurred to me that with my limited knowledge of Python and Renpy, I could be attempting to mix the two without realizing it. So, what I want to know is if the problem lies within my Python code or my integration of it into Renpy. Or perhaps the real error lies in the novice of the programmer?

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Is this a Renpy problem or a Python problem?

#2 Post by KimiYoriBaka »

renpy error. renpy script doesn't have for loops so you need to put it in a python block.

Code: Select all

python: 
   for i in range(end):
       if input_answer == right_answer[:end-i]:
         good = True
the code itself looks fine.

Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: Is this a Renpy problem or a Python problem?

#3 Post by Mild Curry »

Ah! Of course! Why didn't I think of trying that?

Thank-you so much!

shahab96
Veteran
Posts: 228
Joined: Mon May 24, 2010 5:40 am
Location: Lahore, Pakistan
Contact:

Re: Is this a Renpy problem or a Python problem?

#4 Post by shahab96 »

just a little suggestion to make the checking more effiecient you coulde use this

Code: Select all

python:
    good = True
    for i in range(end):
        if input_answer != right_answer[:end-i]:
            good = False
            break
    if good:
        jump win
    else:
        "Failure!"
just a suggestion
The true measure of a man is what he does with his power.

Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: Is this a Renpy problem or a Python problem?

#5 Post by Mild Curry »

Hm, yes, that would work, and it is certainly efficient, but I want the 'win' condition to come only when the entire string has been inputted. The rest is so that it only shows error when the input answer deviates from the correct string.

shahab96
Veteran
Posts: 228
Joined: Mon May 24, 2010 5:40 am
Location: Lahore, Pakistan
Contact:

Re: Is this a Renpy problem or a Python problem?

#6 Post by shahab96 »

oh. ok. then your first one is certainly bettter.
The true measure of a man is what he does with his power.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], voluorem