issue with multiple variables in if statement
I built a function in python that allows the user to receive a message like dlg in bgt. They can press enter or space to continue, or they can set a diration for it to automatically disappear. The manual method works, however the auto method won't execute my code. Code is below, and feel free to use this function if you want.
in msg.py.
#starting value
dmsg=3000
#auto scroll
automsg=True
#disable auto for 1 message
noauto=False
#enable auto for 1 message
yesauto=False
#add more time
extend=3000
#request the extra time
reqx=False
in main.py.
import time
import pygame
import lucia
from lucia.utils import timer
import msg as td
if lucia.running==False:
lucia.initialize()
p = lucia.audio_backend.SoundPool()
def main()
lucia.show_window("game")
while 1:
lucia.process_events()
if lucia.key_pressed(pygame.K_SPACE):
msg("testing")
lucia.output.speak("test successful")
def msg(message):
#total time
tmsg=td.dmsg
mt = timer.Timer()
#if auto is off but this message should be auto, turn it on for one message
if td.yesauto==True:
td.automsg=True
td.noauto=False
#if requested, add on additional time
if td.reqx==True:
tmsg+=td.extend
p.play_stationary("sounds/event/action.ogg")
lucia.output.speak(message)
mt.restart()
while 1:
lucia.process_events()
#a variable to virtually press enter
force=False
#if the timer has elapsed, and auto is on, and no auto for this message is off, automatically disappear
#this is the code that does not execute
if mt.elapsed>=tmsg and td.automsg==True and td.noauto==False:
force=True
#manual continue
if lucia.key_pressed(pygame.K_RETURN) or lucia.key_pressed(pygame.K_SPACE) or force==True:
#turn off request for next message
td.reqx=False
#if auto was turned off for this message only, turn it back on
if td.noauto==True:
td.noauto=False
#if auto is only turned on for this message, turn it off again
if td.yesauto==True:
td.automsg=False
break
if lucia.key_pressed(pygame.K_UP) or lucia.key_pressed(pygame.K_DOWN) or lucia.key_pressed(pygame.K_LEFT) or lucia.key_pressed(pygame.K_RIGHT):
lucia.output.speak(message)
time.sleep(0.05)
main()
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector