Vocab-Apps / anki-hyper-tts

HyperTTS Addon for Anki
GNU General Public License v3.0
81 stars 10 forks source link

Advanced templates aren't loaded properly #213

Open frifix opened 2 weeks ago

frifix commented 2 weeks ago

Hi,

I have flash cards like this: Front: I don't usualy eat [[ podwieczorek ]] Back: afternoon tea

ANKI_1

I have created an advanced template in HyperTTS that replace the word in [[ ]] brackets with the word that is on the back. Here it's my advanced template script:

def format_text(raw, use):
    first = True
    while True:
        start = raw.find('[')
        end = raw.find(']')
        if start == -1 or end == -1:
            break
        if first:
            raw = raw[:start] + use + raw[end+1:]
            first = False
        else:
            raw = raw[:start] + raw[end+1:]
    return raw

front = template_fields['Przód']
back = template_fields['Tył']
result = format_text(front, back)

For some reason when I want to add a sound it doesn't work properly for the first time, it shows an error:

ANKI_2

When I click "Show Settings" and click on "Note Id" it says: Error: No "result" variable found. You must assign the final template output to a result variable.

ANKI_3

When I change something in the script (e.g. remove one letter and add it again) then the whole script will be loaded again and the error no longer appears:

ANKI_4

It is very annoying that I have to do this every time when I want to add sounds for my flash cards. It would be great if this problem could be solved.

luc-vocab commented 1 week ago

looks there's a problem when initializing after loading an advanced template preset could be related to #204 ?