<foreach> Not executing
Posted: Thu Apr 21, 2011 9:38 am
I have struggled for a day or so to get one of my <foreach> tags to execute as expected. I making use of the tag in an identical fashion in other areas of my application, but there is one that does not seem to execute at all.
I am building my array of objects in external javascript, then reading them as follows. This is an except from a *working* foreach loop:
So before I do the iteration I print the value of the variable as well as the length. Those log messages come out as follows:
And then it speaks the five audio items (using both wave files and TTS) correctly. Then, about 20 lines later in the script there is another loop that I want to speak a series of messages, but I cannot get the loop to run at all.
This time the log messages come out as follows:
So you can see that it appears to be an array, I can read the length value appropriately, and I can even access the first element directly and get the expected contents. However, the inside of the <foreach> tag never executes, even if I just put in static speech.
Do you have any suggestions on how to debug what might be the underlying cause for why this would be happening?
Thanks.
I am building my array of objects in external javascript, then reading them as follows. This is an except from a *working* foreach loop:
Code: Select all
<assign name="Timestamp" expr="speakTimestamp(MenuEcma.LastMessageUpdate)" />
<log expr="'About to foreach over: ' + Timestamp.toString()" />
<log expr="'Array length: ' + Timestamp.length" />
<prompt bargein="false">
<foreach item="AudioItem" array="Timestamp" >
<audio expr="AudioItem.Wave">
<value expr="AudioItem.Tts.toString()"/>
</audio>
</foreach>
<break time="300ms" />
</prompt>
Code: Select all
LOCAL: About to foreach over: [object Object],[object Object],[object Object],[object Object],[object Object]
LOCAL: Array length: 5
Code: Select all
<log expr="'About to foreach over: ' + MenuMessages.toString()" />
<log expr="'Array length: ' + MenuMessages.length" />
<log expr="'Message TTS: ' + MenuMessages[0].Tts" />
<prompt>
<foreach item="Message" array="MenuMessages" >
<value expr="Message.Tts" />
</foreach>
</prompt>
Code: Select all
LOCAL: About to foreach over: [object Object],[object Object],[object Object]
LOCAL: Array length: 3
LOCAL: Message TTS: This is the message.
VXI::foreach_element()
Do you have any suggestions on how to debug what might be the underlying cause for why this would be happening?
Thanks.