|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Jul 28, 2011 5:25 pm
[3.34]zs.func.db problems |
Not sure if it's me or if it's really a problem, but I can't seem to get zs.func.db("database", "key") to work in LUA. For that matter, I had a function that would return the proper value in zscript, but when trying to execute the function in lua using zs.execfunc("funcname", "arguments"), it returned nothing.
Am I missing something?
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="reverselanguage" type="Record" copy="yes">
<value>Slovak=sk|Ukrainian=uk|Albanian=sq|Slovenian=sl|Portuguese=pt|English=en|Swedish=sv|Chinese Simplified=zh-CN|Filipino=tl|Japanese=ja|Belarusian=be|Romanian=ro|German=de|Malay=ms|Vietnamese=vi|Finnish=fi|Catalan=ca|Norwegian=no|Maltese=mt|Arabic=ar|Swahili=sw|Afrikaans=af|Danish=da|Lithuanian=lt|Irish=ga|Galician=gl|Haitian Creole=ht|Spanish=es|Hindi=hi|Hungarian=hu|Welsh=cy|Macedonian=mk|Greek=el|Latvian=lv|French=fr|Polish=pl|Russian=ru|Italian=it|Croatian=hr|Persian=fa|Icelandic=is|Thai=th|Dutch=nl|Indonesian=id|Czech=cs|Bulgarian=bg|Yiddish=yi|Turkish=tr|Hebrew=iw|Estonian=et|Serbian=sr</value>
<json>{"Slovak":"sk","Ukrainian":"uk","Albanian":"sq","Slovenian":"sl","Portuguese":"pt","English":"en","Swedish":"sv","Chinese Simplified":"zh-CN","Filipino":"tl","Japanese":"ja","Belarusian":"be","Romanian":"ro","German":"de","Malay":"ms","Vietnamese":"vi","Finnish":"fi","Catalan":"ca","Norwegian":"no","Maltese":"mt","Arabic":"ar","Swahili":"sw","Afrikaans":"af","Danish":"da","Lithuanian":"lt","Irish":"ga","Galician":"gl","Haitian Creole":"ht","Spanish":"es","Hindi":"hi","Hungarian":"hu","Welsh":"cy","Macedonian":"mk","Greek":"el","Latvian":"lv","French":"fr","Polish":"pl","Russian":"ru","Italian":"it","Croatian":"hr","Persian":"fa","Icelandic":"is","Thai":"th","Dutch":"nl","Indonesian":"id","Czech":"cs","Bulgarian":"bg","Yiddish":"yi","Turkish":"tr","Hebrew":"iw","Estonian":"et","Serbian":"sr"}</json>
</var>
<func name="testas" language="Lua" copy="yes">
<value>return zs.func.db("reverselanguage", zs.param(1)) .. " : " .. zs.func.db("languagetable", zs.param(2))</value>
</func>
<var name="languagetable" type="Record" copy="yes">
<value>zh-CN=Chinese Simplified|yi=Yiddish|vi=Vietnamese|uk=Ukrainian|tr=Turkish|tl=Filipino|th=Thai|sw=Swahili|sv=Swedish|sr=Serbian|sq=Albanian|sl=Slovenian|sk=Slovak|ru=Russian|ro=Romanian|pt=Portuguese|pl=Polish|no=Norwegian|nl=Dutch|mt=Maltese|ms=Malay|mk=Macedonian|lv=Latvian|lt=Lithuanian|ja=Japanese|iw=Hebrew|it=Italian|is=Icelandic|id=Indonesian|hu=Hungarian|ht=Haitian Creole|hr=Croatian|hi=Hindi|gl=Galician|ga=Irish|fr=French|fi=Finnish|fa=Persian|et=Estonian|es=Spanish|en=English|el=Greek|de=German|da=Danish|cy=Welsh|cs=Czech|ca=Catalan|bg=Bulgarian|be=Belarusian|ar=Arabic|af=Afrikaans</value>
<json>{"zh-CN":"Chinese Simplified","yi":"Yiddish","vi":"Vietnamese","uk":"Ukrainian","tr":"Turkish","tl":"Filipino","th":"Thai","sw":"Swahili","sv":"Swedish","sr":"Serbian","sq":"Albanian","sl":"Slovenian","sk":"Slovak","ru":"Russian","ro":"Romanian","pt":"Portuguese","pl":"Polish","no":"Norwegian","nl":"Dutch","mt":"Maltese","ms":"Malay","mk":"Macedonian","lv":"Latvian","lt":"Lithuanian","ja":"Japanese","iw":"Hebrew","it":"Italian","is":"Icelandic","id":"Indonesian","hu":"Hungarian","ht":"Haitian Creole","hr":"Croatian","hi":"Hindi","gl":"Galician","ga":"Irish","fr":"French","fi":"Finnish","fa":"Persian","et":"Estonian","es":"Spanish","en":"English","el":"Greek","de":"German","da":"Danish","cy":"Welsh","cs":"Czech","ca":"Catalan","bg":"Bulgarian","be":"Belarusian","ar":"Arabic","af":"Afrikaans"}</json>
</var>
</cmud>
|
To use, do:
Code: |
#PRINT {@testas("en","Spanish")} |
It'll return nothing. Even when I've actually changed it to: return zs.func.db("languagetable", "en"), it still failed.
So, before I lose my mind, what's not working properly? |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Thu Jul 28, 2011 6:09 pm |
zs.func.db does work. But there are two problems that I can see from what you have provided. First, the first argument to zs.func.db needs to be a variable reference to a database record, not a string with the variable name. To get a CMUD variable reference in lua we must use zs.var.<variablename>. I edited your function to the following:
Code: |
<func name="testas" language="Lua" id="19">
<value>return zs.func.db(zs.var.reverselanguage, zs.param(1)) .. " : " .. zs.func.db(zs.var.languagetable, zs.param(2))</value>
</func> |
Secondly,
Code: |
#PRINT {@testas("en","Spanish")} |
You have your arguments backwards with respect to how the function is written if you're calling it this way. "en" is a VALUE in reverselanguage, "Spanish" is a VALUE in language table. Since these aren't keys zs.func.db still isn't going to return anything. If we make the previous code change and swap the parameters like this:
Code: |
#PRINT {@testas("Spanish","en")} |
We'll find it works as expected and we get the following output in CMUD:
As for zs.execfunc I'd have to more about what was going on there. zs.execfunc("funcname", "arguments") is all you should need.
Hope this helps. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Jul 28, 2011 6:21 pm |
Having the arguments backwards was my mistake on the forums (the code in the actual script I was using was correct, silly me).
Anyway, didn't realize that it had to be zs.var as well. Thanks for pointing that out! |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|