Morse Code Tutor Script

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
ozurr
Regular
Posts: 42
Joined: Sat Jun 21, 2003 12:07 am
Contact:

Morse Code Tutor Script

#1 Post by ozurr »

This script along with the two wav files is a simple morse code tutor.
It contains a section where you click on the character and hear it's morse equivalent and a section that tests what you know.
the zip contains a script and two wav files only, so you will have to have Ren'Py to run it.
I've only run it on linux but I assume it will run ok under windows.
Attachments
mct_v0.zip
Contains: script.rpy, dit800.wav, dah800.wav
(11.37 KiB) Downloaded 148 times

absinthe
Regular
Posts: 194
Joined: Sat Dec 10, 2005 12:26 am
Contact:

#2 Post by absinthe »

The "Info" part cracked me up. :)

It works just fine under Windows, XP at least.

I can't say I passed the test, but I now know how to say my name in Morse code! :D
My 2007 NaNo entry: Eidolon

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#3 Post by PyTom »

Okay, figured out the cause of the crackling under Linux.

SDL includes some MMX accelleration code for the sound mixing operation. Unfortunately, this code assumes that the size of a sound buffer is a multiple of 16 bytes long... an assumption that is as incorrect as it is undocumented. The last couple of samples failed to be mixed and were left at 0, causing the popping.

Why didn't we notice this? Well, it can only occur when a sound file is not a multiple of 4 samples in length. (Sound files have to be a multiple of 2 samples in length.) Most compressed audio formats have a frame size that is a multiple of 4... so it isn't a problem for them.

This will be fixed in the next release of Ren'Py, but isn't much of a problem in practice. It only affects wave files (and perhaps some other minor formats), and only if they have a number of samples that is not a multiple of 4.

There is still one pop at the end of each dash or dot, but that's due to the waveform of the file, and hence not my problem.

Some code you may wish to adapt:

Code: Select all

init:
    python:
        def morse(s):
            for c in s:
                if c == ".":
                    renpy.sound.queue("dit.wav", clear_queue=False)
                elif c == "-":
                    renpy.sound.queue("dah.wav", clear_queue=False)
                else:
                    renpy.sound.queue("pause.wav", clear_queue=False)

$ morse(".-. . -. .--. -.--")
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

ozurr
Regular
Posts: 42
Joined: Sat Jun 21, 2003 12:07 am
Contact:

#4 Post by ozurr »

Thanks PyTom.
I'll put the new function in when I work on the script in a day or two.
The pause wav is a nifty idea. Now I can do sentences. :)

Have a Happy and Prosperous New Year!
Last edited by ozurr on Mon Jan 02, 2006 8:40 pm, edited 2 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#5 Post by PyTom »

Another function might be the following:

Code: Select all


init:
   python:

       morse_table = {
            't' : '-',
            'o': '---',
            'm': '--',
            # etc... This is all the morse code I remember. Well, this 
            # and SOS.
       }

       def str_to_morse(s):
            s = s.lower()
            rv = ""

            for i in rv:
                rv += morse_table.get(i, i)
            return rv

$ code = str_to_morse("I am the very model of a modern major general")
$ morse(code)

"%(code)"
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

ozurr
Regular
Posts: 42
Joined: Sat Jun 21, 2003 12:07 am
Contact:

#6 Post by ozurr »

ReWrote the code to get rid of the huge blocks but haven't added any significat features so, I don't see any reason to update. It took me twice as long to do it this time, but It's turned out to be a good learning method. Seems there's lots of different ways to code something and get the same results, though some are faster than others. Used normal lists because the dictionary list doesn't return sequential items. I'll try it next time since I found some info on sorting dictionary lists. I imagine I'll end up rewriting this code many times, learning more and more in the process.

.--. -.-- - .... --- -. .. ... -.-. --- --- .-..

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#7 Post by PyTom »

What do you mean by a "dictionary list"? A dictionary isn't a list (this isn't lisp, after all), a dictionary is its own data type. Like sets, dictionaries do not have order.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Kocker, Semrush [Bot]