I would like to know what’s the equivalent of the Coblock function “say … for a duration/period of time” in Typescript.
It looks like speech is treated as property/attribute of an object, instead of a function. Currently I have not found a straightforward to let a character say something for a given period of time.
I have written a function like this using the Time.schedule method, it can achieve similar effect when used individually.
function timedSpeech (char, sentence: string, duration: number) {
char.speech = sentence
Time.schedule(() => {
char.speech = null
}, duration);
}
But when it is put inside a loop (because I want the character to say a list of lines), the problem emerged.
const speechlist = ["line A", "line B", "line C"]
let i = 0;
while (i < speechlist.length) {
Debug.log("i=" + i)
Debug.log("s=" + speechlist[i])
timedSpeech(andy, speechlist[i], 5)
i = i+1;
}
The loop will not wait for Time.schedule to be executed before proceeding to next iteration. What ends up happening is that the character would immediately jump to last line of the list.
Hope this is a clear question and that someone can share some insight.