How to let function execute only once each time when if flag is true?

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
Li yuanlin
Regular
Posts: 93
Joined: Sat Aug 04, 2018 8:42 pm
Location: Hong Kong
Contact:

How to let function execute only once each time when if flag is true?

#1 Post by Li yuanlin »

if flag:
$ renpy.run(...
stay hungry,stay foolish.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: How to let function execute only once each time when if flag is true?

#2 Post by jeffster »

Code: Select all

if flag:
    $ renpy.run(...)
    $ flag = False
or

Code: Select all

default execute = True

label start:

if flag and execute:
    $ renpy.run(...)
    $ execute = False
Or if it's inside a screen, then perhaps use SetVariable instead of changing the flag in a Python statement.

User avatar
Li yuanlin
Regular
Posts: 93
Joined: Sat Aug 04, 2018 8:42 pm
Location: Hong Kong
Contact:

Re: How to let function execute only once each time when if flag is true?

#3 Post by Li yuanlin »

find a way:

Code: Select all

label set_qte1_word_name(formal_test=False):
    if formal_test:
        $ word = renpy.random.choice(list(formal_test_words_dict.keys()))

    else:
        $ word = renpy.random.choice(list(temp_test_words_dict.keys()))

    $ word_color = renpy.random.choice([blue,green,yellow,red])
    jump qte_begin
    return
in screen:

Code: Select all

timer .1 action Call("set_qte1_word_name",formal_test=persistent.qte1_formal_test)
in game label:

Code: Select all

label start:

    show screen qte1()

    label qte_begin:

    $ ui = ui.interact()
stay hungry,stay foolish.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot