Typing Tutor

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
User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Typing Tutor

#1 Post by usul » Tue Mar 02, 2010 1:36 pm

I'm trying to figure out a way to check and compare keyboard input instantaneously to create a typing tutor. I'm playing around with the Konami code for input, but I can't figure out how to compare items in a string (I can convert a string to a list, but the Konami code example it only compares the code like so: pygame.K_a (for example). Does anyone have an idea on how I can get the input converted to a string so I can compare it with the "exercise"?

If you have a better idea than what I'm currently trying out, I'm open to suggestions.

F
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Typing Tutor

#2 Post by usul » Tue Mar 02, 2010 5:50 pm

I'm still trying to figure this out, going throught the magical boutique script.rpy I found this little bit of code that seems to use the keyboard and appears different from the Konami code. I'm looking into it, but if anybody out there has a better idea, do share ! :D

Code: Select all

# Setup the secret keys for the developer mode.

init:

    python:

#         config.keymap['developer'] = [ 'D' ]

#         config.underlay.append(renpy.Keymap(

#             developer=renpy.curried_call_in_new_context('developer')))

#         config.keymap['f_language'] = [ 'L' ]

#         config.underlay.append(renpy.Keymap(

#             f_language=renpy.curried_call_in_new_context('f_language')))

        config.keymap['gatherfix'] = [ 'C' ]

        config.underlay.append(renpy.Keymap(

            gatherfix=renpy.curried_call_in_new_context('gatherfix')))

#         config.keymap['gatherfix'] = [ 'V' ]

#         config.underlay.append(renpy.Keymap(

#             showversion=renpy.curried_call_in_new_context('showversion')))

 
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Guest

Re: Typing Tutor

#3 Post by Guest » Tue Mar 02, 2010 7:36 pm

Function names are abstract.

Code: Select all

charsToType = ['a', 'a', 'a', ' ', 'a']
for char in charsToType:
    code = readTypedKey()
    if codeToCharacter(code) == char:
        doIfCorrect()
    else
        doIfIncorrect()

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Typing Tutor

#4 Post by usul » Wed Mar 03, 2010 2:50 pm

Running the code I get the error: NameError: name 'readTypedKey' is not defined

Can anyone give me a pointer on how to go about defining this?
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Typing Tutor

#5 Post by JQuartz » Wed Mar 03, 2010 11:46 pm

This is something I made in the past. Not sure if you'll be able to use it since it's quite messy but maybe it'll help:

Code: Select all

init:
    $ test_text=None
    $ test_result=None
    $ test_had_started=None
    $ type_error=None
    $ shown_text=None
    $ number=0
    
  
    
    
    $ typed_button=None
    $ letter=""
    
   
   
    $ got_start_over=None
    $ got_done=None
    $ got_complete_test=True
    $ done=None
    
    $ limit="cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    
    


###############################################################################################################################
init python:
    def typing_text():
        if not test_had_started:
            return
        ui.frame(background='#fff', xpos=.05,ypos=.2, xminimum=700, yminimum=400)
        ui.null()
        ui.text(parser, xpos=0.099, ypos=0.3, color='#f00')
        ui.text(shown_text, xpos=0.1, ypos=0.3,color='#bbb')
        ui.text(parser_coverer,xpos=0.099, ypos=0.3, color='#fff')
        ui.text(test_result, xpos=0.1, ypos=0.3,color='#000')
    config.overlay_functions.append(typing_text)
 

############################################################################################################################## 


    
    
label start:
   pass
    
   
label test1:
    $ victory='test1_complete'
    $ test_text="Typing test start. Typing test end."
    
    jump typing_test
label test1_complete:
    
    "Test complete. Checking result."
   
    $ test_had_started=True
    $ renpy.pause()
    $ test_had_started=None
    
    if mistake:
        "Mistake made."
    elif not mistake:
        "No mistake made."
    "End"
    
    
    
    $ shown_text=""
    $ test_result=""
    
   
    
    
    
    
    
    
    
    
    

    $ renpy.full_restart()
###############################################################################################################################
label test_completed:
    $ renpy.jump(victory)
label typing_test:
    
    $ mistake=[]
    $ test_had_started=True
    $ got_start_over=True
    $ test_result=''
    $ type_error=''
    $ parser=''
    $ text_in_list_form=[]
    $ parser_coverer=''
    $ letter=test_text[0]
    $ number=0
    $ num=0
    $ text_bag=[]
    $ shown_text=test_text
    python:
        for alphabets in test_text:
            text_bag.append(alphabets)


label start_typing:
    if len(test_result)==len(limit) + (len(mistake) *20):
        $ test_had_started=None
        $ renpy.jump('test_completed')
    if number==len(test_text):
        $ test_had_started=None
        $ renpy.jump('test_completed')
    if not letter=='\n':
        $ parser=parser + "{b}{size=22}_{/size}{/b}"
    $ text_in_list_form.append(letter)
    if letter=='\n':
        $ number+=1
        $ test_result=test_result + '\n'
        
        if number==len(test_text):
            $ test_had_started=None
            $ renpy.jump('test_completed')
        $ letter=test_text[number]
        $ renpy.restart_interaction()
        $ parser_coverer=parser_coverer+'{u}'+test_text[number-1]+'{/u}'
        $ parser=''
        python:
            for value in text_in_list_form:
                parser=parser+value
        jump start_typing

    call keyboard
    $ num=0
    python:
        for alphabets in text_bag:
            if num==0:
                shown_text="{color=#fff}"
            
            if num==number:
                shown_text=shown_text+"{/color}"
            shown_text=shown_text+alphabets
            num=num+1
   
    if typed_button== letter:
        $ test_result=test_result + letter
        if number==len(test_text):
            $ test_had_started=None
            $ renpy.jump('test_completed')
        $ letter=test_text[number]
        
        $ renpy.restart_interaction()
    
    else:
        if typed_button=='Enter':
            $ typed_button=' '
            if typed_button==letter:
                $ test_result=test_result + letter
                if number==len(test_text):
                    $ test_had_started=None
                    $ renpy.jump('test_completed')
                $ letter=test_text[number]
                $ renpy.restart_interaction()
                $ parser_coverer=parser_coverer+test_text[number-1]
        
                $ num=0
                $ parser=''
                python:
                    for value in text_in_list_form:
                        parser=parser+value
    
    
                jump start_typing
                
        if letter==' ':
            $ letter='{u} {/u}'#
        $ test_result=test_result + "{color=#f00}"+letter +"{/color}"
        $ renpy.restart_interaction()
        $ mistake.append(number-1)
        if number==len(test_text):
            $ test_had_started=None
            $ renpy.jump('test_completed')
        
        $ letter=test_text[number]
    $ parser_coverer=parser_coverer+test_text[number-1]
        
    $ num=0
    $ parser=''
    python:
        for value in text_in_list_form:
            parser=parser+value
    
    
    jump start_typing
    
        
label keyboard:
    $ number +=1
label keyboard2:
    $ ui.keymap(a=ui.returns("a"))
    $ ui.keymap(b=ui.returns("b"))
    $ ui.keymap(c=ui.returns("c"))
    $ ui.keymap(d=ui.returns("d"))
    $ ui.keymap(e=ui.returns("e"))
    $ ui.keymap(f=ui.returns("f"))
    $ ui.keymap(g=ui.returns("g"))
    $ ui.keymap(h=ui.returns("h"))
    $ ui.keymap(i=ui.returns("i"))
    $ ui.keymap(j=ui.returns("j"))
    $ ui.keymap(k=ui.returns("k"))
    $ ui.keymap(l=ui.returns("l"))
    $ ui.keymap(m=ui.returns("m"))
    $ ui.keymap(n=ui.returns("n"))
    $ ui.keymap(o=ui.returns("o"))
    $ ui.keymap(p=ui.returns("p"))
    $ ui.keymap(q=ui.returns("q"))
    $ ui.keymap(r=ui.returns("r"))
    $ ui.keymap(s=ui.returns("s"))
    $ ui.keymap(t=ui.returns("t"))
    $ ui.keymap(u=ui.returns("u"))
    $ ui.keymap(v=ui.returns("v"))
    $ ui.keymap(w=ui.returns("w"))
    $ ui.keymap(x=ui.returns("x"))
    $ ui.keymap(y=ui.returns("y"))
    $ ui.keymap(z=ui.returns("z"))
    $ ui.keymap(A=ui.returns("A"))
    $ ui.keymap(B=ui.returns("B"))
    $ ui.keymap(C=ui.returns("C"))
    $ ui.keymap(D=ui.returns("D"))
    $ ui.keymap(E=ui.returns("E"))
    $ ui.keymap(F=ui.returns("F"))
    $ ui.keymap(G=ui.returns("G"))
    $ ui.keymap(H=ui.returns("H"))
    $ ui.keymap(I=ui.returns("I"))
    $ ui.keymap(J=ui.returns("J"))
    $ ui.keymap(K=ui.returns("K"))
    $ ui.keymap(L=ui.returns("L"))
    $ ui.keymap(M=ui.returns("M"))
    $ ui.keymap(N=ui.returns("N"))
    $ ui.keymap(O=ui.returns("O"))
    $ ui.keymap(P=ui.returns("P"))
    $ ui.keymap(Q=ui.returns("Q"))
    $ ui.keymap(R=ui.returns("R"))
    $ ui.keymap(S=ui.returns("S"))
    $ ui.keymap(T=ui.returns("T"))
    $ ui.keymap(U=ui.returns("U"))
    $ ui.keymap(V=ui.returns("V"))
    $ ui.keymap(W=ui.returns("W"))
    $ ui.keymap(X=ui.returns("X"))
    $ ui.keymap(Y=ui.returns("Y"))
    $ ui.keymap(Z=ui.returns("Z"))
    $ ui.keymap(K_PERIOD=ui.returns("."))
    $ ui.keymap(K_COMMA=ui.returns(","))
    $ ui.keymap(K_QUOTEDBL=ui.returns("'"))
    $ ui.keymap(K_SPACE=ui.returns(" "))
    
    $ ui.keymap(K_1=ui.returns("1"))
    $ ui.keymap(K_2=ui.returns("2"))
    $ ui.keymap(K_3=ui.returns("3"))
    $ ui.keymap(K_4=ui.returns("4"))
    $ ui.keymap(K_5=ui.returns("5"))
    $ ui.keymap(K_6=ui.returns("6"))
    $ ui.keymap(K_7=ui.returns("7"))
    $ ui.keymap(K_8=ui.returns("8"))
    $ ui.keymap(K_9=ui.returns("9"))
    $ ui.keymap(K_0=ui.returns("0"))
    $ ui.keymap(shift_K_1=ui.returns("!"))
    $ ui.keymap(K_RETURN=ui.returns("Enter"))
    $ ui.keymap(K_BACKSPACE=ui.returns("Backspace"))
    $ ui.keymap(K_QUOTE=ui.returns("'"))
    
  
   
    $ typed_button= ui.interact()
    return
    
label empty_paper:
    $ shown_text=""
    $ test_result=shown_text
    $ test_had_started=True
    $ ui.keymap(mouseup_1=ui.returns("_return"))
    $ ui.keymap(K_SPACE=ui.returns(" "))
    $ ui.interact()
    $ test_had_started=None
    return
    
label set_limit:
    $ limit="cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
    return
    
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
usul
Veteran
Posts: 415
Joined: Mon Oct 29, 2007 12:35 pm
Projects: Teachings of the Buddha, System-Addict, Generation XxX
Location: Quebec
Contact:

Re: Typing Tutor

#6 Post by usul » Thu Mar 04, 2010 3:06 pm

Hey thanks JQuartz,

I'm going to go through it with a fine comb and figure it out. It's a good start! I've been reading a bit on defining functions, classes and expanding my understanding of Python. It might work ;)
"The universe is non-simultaneously apprehended"
— Buckminster Fuller

Post Reply

Who is online

Users browsing this forum: hell_oh_world, Saitogami