Page 1 of 1

<foreach> Not executing

Posted: Thu Apr 21, 2011 9:38 am
by rquant
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:

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>
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:

Code: Select all

LOCAL: About to foreach over: [object Object],[object Object],[object Object],[object Object],[object Object]
LOCAL: Array length: 5
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.

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>
This time the log messages come out as follows:

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()
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.

Re: <foreach> Not executing

Posted: Thu Apr 21, 2011 10:30 am
by support
Hi,

Could you provide us with more context for how you're implementing your second <foreach>? Perhaps we can find something that may be causing it to not execute.

You can private message us this code if it contains sensitive material.

Regards,
Plum Support

Re: <foreach> Not executing

Posted: Thu Apr 21, 2011 2:19 pm
by support
Hi,

Have you attempted to run this foreach within a smaller script separate from the rest of the application? Reviewing what you have sent us, we have not yet found anything that would cause this foreach to fail.

Regards,
Plum Support