VoxCommando
Help and Support (Using VoxCommando) => Python Scripting => Topic started by: xtermin8r on April 22, 2014, 01:47:31 PM
-
Hi
vc.callAction("TTS.SpeakSync",lastresult, None) = not working (https://voxcommando.com/forum/proxy.php?request=http%3A%2F%2Fwww.freesmileys.org%2Fsmileys%2Fsmiley-angry015.gif&hash=fd73a522480b28b6ccf52ba2aba587b5b32ac9cd) (http://www.freesmileys.org/smileys.php)
What is the correct syntax ?
thanks.
-
per the wiki: void callAction(string strActionType, string strParams, List<string> payloads)
... doesn't look as though you've defined lastresult as a string?
-
There are examples and explanations for python here:
http://voxcommando.com/mediawiki/index.php?title=Python
Your second parameter should be a string, but as Nime5ter points out, you probably did not define a string variable named lastresult. There is no way to know since you only showed us one line of your code.
One of the examples on the page I linked to above is this:
print vc.getObject("LastResult","")
so you could adapt this to grab the lastresult from vc and store it in your variable:
myLastResult = vc.getObject("LastResult","")
vc.callAction("TTS.SpeakSync", myLastResult, None)
-
this is what I was trying to do
vc.callAction("Weather.TWN.1","gbxx0037",None)
myLastResult = vc.getObject("LastResult","")
vc.callAction("TTS.SpeakSync", myLastResult, None)
working fine now, thanx for the xplanation.
but why doesn't this work ?
myTime = vc.getObject("ShortTime","")
vc.callAction("TTS.SpeakSync", myTime, None)
I get that ShortTime is not a strObject, so what is the correct format ?
-
but why doesn't this work ?
myTime = vc.getObject("ShortTime","")
...
Please see the reference material that I linked to. That doesn't work for the same reason that the following code does not work:
myBalance = vc.getObject("HowMuchMoneyIsInMyBank","")
You can't just make up object names. The objects are listed on the page I linked to. More specifically they can be found here:
http://voxcommando.com/mediawiki/index.php?title=Python#getObject
I should probably point out that if you were calling a python function from within a VC macro (instead of just running python code) then you could do something like this:
py.execstring myFunc({ShortTime})
This is because actions will look at anything in {} to see if it can be replaced with a payload, variable, map value etc. but this does not apply to python code. And before you ask, no that isn't going to change. However, I could probably add a new method to accept a string and do these substitutions, and return a string with the substituted values in place.
-
To code in Python, why not use Python methods?
The following returns a "short time" string in Python speak:
import time
myTime= time.localtime(time.time())
print time.strftime("%H:%M", myTime)
-
It makes total sense now thank you both.