import bge


def main():

    cont = bge.logic.getCurrentController()
    own = cont.owner
    dict = bge.logic.globalDict
    trick_string = dict.get('trick_string')
    #print(trick_string, "textstring")
    print_text_timer = own['print_text_timer']
    print_text_timer2 = own['print_text_timer2']
    print_text_timer3 = own['print_text_timer3']
    old_print_text = own['print_text']
    old_print_text2 = own['print_text2']
    old_print_text3 = own['print_text3']
    print_text = ''
    timer_length = 300
    #set strings
    show_tricks = 0
    if show_tricks == 1:
        if trick_string != None:
            if old_print_text == '':
            #if 1 == 1:    
                own['print_text'] = trick_string
                print_text_timer = timer_length
                print_text = trick_string
                own['print_text'] = print_text
            elif old_print_text2 == '':
                text = own['print_text']
                text = '\n' + str(text)
                own['print_text2'] = text
                own['print_text'] = trick_string
                print_text_timer2 = own['print_text_timer']
                print_text_timer = timer_length
                print_text = trick_string
                own['print_text'] = print_text 
            elif old_print_text3 == '':
                own['print_text3'] = own['print_text2']
                own['print_text2'] = own['print_text']
                text = own['print_text']
                text = '\n' + str(text)
                own['print_text2'] = text
                own['print_text'] = trick_string
                print_text_timer3 = own['print_text_timer2']
                print_text_timer2 = own['print_text_timer']
                print_text_timer = timer_length
                print_text = trick_string
                own['print_text'] = print_text                
            dict['trick_string'] = None

    #read timers
        #print("t1: ", print_text_timer, "t2: ", print_text_timer2)
        if print_text_timer3 > 0:
            print_text_timer3 = print_text_timer3 - 1
            print_text3 = own['print_text3']
            #own.text = (str(print_text) + str(print_text2))
            own['print_text_timer3'] = print_text_timer3
        if print_text_timer3 <=0:
            print_text3 = ''
            own['print_text_timer3'] = '' 
            own['print_text3'] = '' 
        if print_text_timer2 > 0:
            print_text_timer2 = print_text_timer2 - 1
            print_text2 = own['print_text2']
            #own.text = (str(print_text) + str(print_text2))
            own['print_text_timer2'] = print_text_timer2
        if print_text_timer2 <=0:
            print_text2 = ''
            own['print_text_timer2'] = '' 
            own['print_text2'] = ''    
        if print_text_timer > 0:
            print_text_timer = print_text_timer - 1
            print_text = own['print_text']
            #own.text = str(print_text)
            own['print_text_timer'] = print_text_timer
            #print("print text is: ", print_text)
        if print_text_timer <= 0:
            own.text = ''
            own['print_text'] = ''   
            own['print_text_timer'] = print_text_timer 
    #        own['print_text_timer3'] = print_text_timer3 
    #        own['print_text_timer2'] = print_text_timer2    
        dict['last_trick_string'] = dict.get('trick_string')
        print_text_timer = own['print_text_timer']
        old_print_text = own['print_text']
        old_print_text2 = own['print_text2']
        old_print_text3 = own['print_text3']
        output_text = str(old_print_text) + str(old_print_text2) + str(old_print_text3) 
        own.text = output_text
    #print("1: ", old_print_text, "2: ", old_print_text2, "3: ", old_print_text3)    
    #print(print_text_timer, " : timer")
    else:
        own.text = ''
main()
