Code: Select all
$ above = renpy.input("Above", length=20)
Label check_above:
if above = por encima de:
t "That is correct!"
else:
t "Sorry, that is incorrect."
Thanks for reading!
-Zia
Code: Select all
$ above = renpy.input("Above", length=20)
Label check_above:
if above = por encima de:
t "That is correct!"
else:
t "Sorry, that is incorrect."
Code: Select all
# first - in a init block, you can define the dictionary and the function to check it
init python:
import random # this is required if you want to pick random words to ask for
d = dict() # create a dictionary
d["foo"] = "bar" # create some fake entries. use the real words here please ;)
d["bla"] = "bla"
def checkVocabulary(word): # function to check if the answer is true
answer = renpy.input(word,"",length=20) # let the user input their answer
if answer == d[word]: # compare the real answer to the one the user gave
return True # return true if its the same
else:
return False # or false if its not
# then - later in your script, you can use those
$ word = random.choice(d.keys()) # this will pick a random word
$ correct = checkVocabulary(word) # will ask the user to input the correct answer
if correct:
"Correct!"
else:
"Wrong!"
Hey, guys! Just wait a little moment please! I know you are perfectly right! You instantly hinted a very better solution and even delivered the code to it! Great! … But, as far as I understood this invokes to be a bit familiar with Python. (Zia, please correct me here if I go wrong ). To learn a programming language as python might be easier than others. And it is also a task that can be done… in quite some time… and it is great! But as far as I understood Ren'Py has also the power to be used by nearly totally inexperienced users and to seduce them into programming. Just with the typing above you are instantly able to write a program that can solve a local problem with the help of Ren'Py SDK! And with solving a problem and providing something usable it is a great thing to do!bink wrote:That's really not a good way at all.
We are not aiming here at defending high standards of programming, but simply at saving people's time (I'm sure many are interested by Zia's question). Less time wasted in the programming means more time for the artistic part of a project. Bink's code fits perfectly this goal, and is also very well commented and comprehensible.Since these exercises will include a large amount of vocabulary, is the above the best way to accomplish this? Is there a more elegant way, or am I on the right track?
Code: Select all
init:
define me = Character("Me", color="#c8c8ff")
define t = Character("Teacher", color="#c8ffc8")
$ import random
$ style.test_button.size_group = "testbutton"
$ d = {"a carrot":"zanahoria", "a dog":"perro", "a party":"tertulia", "a turtle":"tortuga", "above":"por encima de", "amazing":"pasmoso", "to live":"vivir", "to package":"empaquetar", "thankfully":"agradecidamente", "whenever":"cada vez que"} # I don't speak Spanish, so please forgive me for the possible errors XD
screen ask_question:
$ word = words[k]
$ choices = d.keys()
$ choices.remove(word)
$ random.shuffle(choices)
$ choices.insert(random.randint(0,nchoices-1), word)
vbox align (0.5, 0.5) style_group "test":
textbutton word
for i in range(nchoices):
textbutton d[choices[i]] action Return(d[word] == d[choices[i]])
label start:
t "Good morning! Are you ready for tomorrow's exam?"
me "Yes, sure! But I wouldn't mind if you tested my knowledge."
t "Ok, let's proceed..."
$ score1 = 0
$ k = 0
$ nwords = 5 # can't be bigger than the number of keys in the dictionnary
$ words = ["a party", "a turtle", "above", "amazing", "whenever"] # a list of at least nwords keys from the dictionnary
# for a global test, write: $ words = d.keys()
$ random.shuffle(words)
$ nchoices = 4 # can't be bigger than the number of keys in the dictionnary
label test1:
while k < nwords:
call screen ask_question
if _return:
$ score1 += 1
t "Correct!"
else:
t "Wrong!"
$ k += 1
jump test1
label continue:
if score1 < nwords/2.0:
t "%(score1)d/%(nwords)d. Don't worry, you'll do better tomorrow...{p}If you work hard tonight!"
else:
t "%(score1)d/%(nwords)d... Good! I'm sure you'll do fine."
Users browsing this forum: Google [Bot]