Python CoSpace how to make time.sleep(2)?

I need delay in my code. How to make python time.sleep(2)?

from cospaces import *
import math
import random

egyptianRoyalWoman = scene.get_item('Egyptian royal woman')
seniorRomanMan = scene.get_item('Senior Roman man')
seniorRomanWoman = scene.get_item('Senior Roman woman')
egyptianBoy = scene.get_item('Egyptian boy')

talk = 'Talk neutral'
text = 'Hi, I am ghost'

myList = [egyptianBoy, seniorRomanMan, seniorRomanWoman, egyptianRoyalWoman]

for item in myList:
    item.transition.move_to(Vector3(0.0,1.8,0.1), 3.00)
    # need delay
    item.speech = text
    # need delay
1 Like

Hi @Medard

there is no such functionality as sleep, but you can typically pass callback to transition methods to execute some action when transition has completed, also you can use time.schedule to execute some function after a specified period of time.

Here is an example:

from cospaces import *
import math
import random

boy: AnimatedItem = scene.get_item('QPTu49Ym')
girl: AnimatedItem = scene.get_item('n3WLxjLX')

dialog_queue = [boy, girl] 
current_character = 0

def move():
    character = dialog_queue[current_character]
    character.transition.move_to(Vector3(0, -2, 0), 2.0, talk)

def talk():
    global current_character

    character = dialog_queue[current_character]
    character.animation.play_looping('Talk neutral')
    character.speech = "Hi!"

    current_character += 1
    time.schedule(move, 2)


Thank you, now the code is working as it should.

1 Like