If statements, the best way for my idea?

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
Zia
Newbie
Posts: 3
Joined: Sun Jul 11, 2010 9:09 am
Projects: Mesoamerican Expedition
Contact:

If statements, the best way for my idea?

#1 Post by Zia »

I'm making a game where the player can practice Spanish, and a large part of the game involves vocabulary. I plan to display the English word and have the user type in the Spanish word. I'm thinking something like this

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."
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?

Thanks for reading!

-Zia

cosmo
Regular
Posts: 120
Joined: Mon Aug 29, 2011 11:01 am
Projects: | ZUKUNFT | Wayang Kulit - A Shadow Play (WIP version 0.1) |
Location: Germany
Contact:

Re: If statements, the best way for my idea?

#2 Post by cosmo »

Hi Zia!

There will be several ways to do this!

If you are new to ren'py - and maybe to programming, this will be just fine, I think! Go on with it! :) It is a good way!

I would say the next step of this kind of program may be that the user can have a chance to enter his/her own vocabulary … and save it, so that it can be used later on. This will involve to look into the python language and to get familiar with some basics of it. But it depends on yourself! Decide what you would just love to do, where your aims and borders lie.

I would like to add that I am currently a total newbie to renpy – and I just worked out a small program that does similar things with multiplication learning. Drop me a PM if you are interested in program and code. I have not decided yet to upload it in the forum as it is so small ;) - But may do that later on perhaps…
Project: Wayang Kulit - A Shadow Play
Status: First demo version "Proof of Concept" of my first project is out.

bink
Regular
Posts: 49
Joined: Sat Jul 09, 2011 4:34 pm
Contact:

Re: If statements, the best way for my idea?

#3 Post by bink »

That's really not a good way at all.
If the programm contains a list of 100 words (which is not a lot), you'd have to write 100 check labels and 100 if-conditions, etc.
You should instead use Pythons built-in dictionary class.
An example would look like this:

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!"

Another
Regular
Posts: 82
Joined: Sun Apr 18, 2010 8:57 am
Contact:

Re: If statements, the best way for my idea?

#4 Post by Another »

When it's about a vocabulary test, I'm a bit dubious about requiring the player to type in an exact answer. What about the different meanings of the word in the question? And the synonyms or different spellings of the answer? Are you ready to implement all these?

I think a multiple-choice test would provide a better gameplay and ease your life. If you haven't already, have a look at EVEning Course. Mikey did a wonderful job in keeping the tests both entertaining and reasonably challenging. :D

cosmo
Regular
Posts: 120
Joined: Mon Aug 29, 2011 11:01 am
Projects: | ZUKUNFT | Wayang Kulit - A Shadow Play (WIP version 0.1) |
Location: Germany
Contact:

Re: If statements, the best way for my idea?

#5 Post by cosmo »

bink wrote:That's really not a good way at all.
Hey, guys! :D 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!

I think that after coding several lines of code like this one will naturally wish for more flexibility. And more features!
And then you are right. And you already gave nice hints to code this maybe next level!


Btw: Zia, the if statement will be necessary and will also be used if you decide to add more to your program.


I just want to say: Don't repel people to peek into programming with higher standards of programming. For a special case it may even be a more time consuming thing to learn about python dictionaries and other things then just to write, write, write simple vocabulary… and have usable solution after only a small time! :)


(Just some thoughts on that… don't bother… go on! :) )

@ Another:
Thank you very much for the EVEning Course link. I have just not been able to reach the download site. Maybe it's currently down?
Project: Wayang Kulit - A Shadow Play
Status: First demo version "Proof of Concept" of my first project is out.

Another
Regular
Posts: 82
Joined: Sun Apr 18, 2010 8:57 am
Contact:

Re: If statements, the best way for my idea?

#6 Post by Another »

I can't talk on Zia's behalf, but I don't see any reason to be repelled by our answers to the question stated above:
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?
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. :D


But since I realize now I pointed out to a possible problem without providing a complete solution, here's a code example showing how to implement a vocabulary test with menus:

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."
You're right, the direct link to EVEning Course from the Lemmasoft thread is apparently broken. :evil: You can download it, amongst Mikey's other projects, on ATP's website. 8)
Last edited by Another on Fri Sep 16, 2011 5:13 pm, edited 3 times in total.

cosmo
Regular
Posts: 120
Joined: Mon Aug 29, 2011 11:01 am
Projects: | ZUKUNFT | Wayang Kulit - A Shadow Play (WIP version 0.1) |
Location: Germany
Contact:

Re: If statements, the best way for my idea?

#7 Post by cosmo »

ah, great! Thanks! Will take a look at it! :)
Project: Wayang Kulit - A Shadow Play
Status: First demo version "Proof of Concept" of my first project is out.

Zia
Newbie
Posts: 3
Joined: Sun Jul 11, 2010 9:09 am
Projects: Mesoamerican Expedition
Contact:

Re: If statements, the best way for my idea?

#8 Post by Zia »

Thank you cosmo, bink and Another; you all had very helpful insights to my question. All those If functions would have been a pain in comparison to the lovely solutions presented.

Thanks Another for providing the link to EVEning, I'll check it out as soon as I can.

Post Reply

Who is online

Users browsing this forum: Google [Bot]