Are you planning to change this at runtime? I seem to remember a post on the mailing list from very long time ago (years) changing global variables that were being read at the same time had a small risk of a race condition that might segfault.<div><br></div><div>If so that has almost certainly been fixed by now, but if not you could also look at using mod_hash or mod_db.</div><div><br></div><div>Your simple script can be done in xml by the way without lua using inline api calls in the condition's field attributes. Entirely personal preference which you use. Lua will fetch the variable just once so dies have that advantage.<span></span><br><div><br></div><div><br></div><div><br></div><div><br><br>On Thursday, 9 June 2016, Pete Ashdown <<a href="mailto:pashdown@xmission.com">pashdown@xmission.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Answered my own question:<br>
<br>
In your dialplan:<br>
<action application="lua" data="script.lua"/><br>
<br>
In script.lua:<br>
mode = freeswitch.getGlobalVariable("mode")<br>
if (mode == "open") then<br>
session:speak("open")<br>
end<br>
if (mode == "techonly") then<br>
session:speak("teck only")<br>
end<br>
if (mode == "event") then<br>
session:speak("event")<br>
else<br>
session:speak("i dont know")<br>
end<br>
<br>
Make sure the global is created somewhere, like vars.xml:<br>
<X-PRE-PROCESS cmd="set" data="mode=open"/><br>
<br>
<br>
On 06/07/2016 08:50 AM, Pete Ashdown wrote:<br>
> What is the simplest way to have a conditional branch based on a global<br>
> variable in a dialplan? Actually using a global variable and xml is<br>
> giving me mixed results. Do I need to use Lua or another scripting<br>
> language?<br>
><br>
> This is what I have, which doesn't give the results desired. The<br>
> "speak" actions are merely debug placeholders. I know there are better<br>
> ways to do conditional voice to text.<br>
><br>
> <condition regex="any" field="${cond(${mode} == 'open' ? YES :<br>
> NO)}" expression="^YES$"><br>
> <action application="speak" data="open"/><br>
> </condition><br>
><br>
> <condition regex="any" field="${cond(${mode} == 'tech only' ? YES<br>
> : NO)}" expression="^YES$"><br>
> <action application="speak" data="teck only"/><br>
> </condition><br>
><br>
> <condition regex="any" field="${cond(${mode} == 'event' ? YES :<br>
> NO)}" expression="^YES$"><br>
> <action application="speak" data="event"/><br>
> </condition><br>
><br>
<br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'consulting@freeswitch.org')">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'FreeSWITCH-users@lists.freeswitch.org')">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</blockquote></div></div>