View Full Version : need CASE or SWITCH loop in lua4
cdebuhr
November 6th, 2004, 10:27 AM
hi,
for translation of english string values into german i need a case or switch loop like:
switch(weather)
{
case "rain": ....
case "sunny": ...
}
is something like this known or possible?
tia
chris
Promixis
November 6th, 2004, 11:42 AM
Chris,
Lua doesn't have a case switch but you can implement one - see the lua website.
But for what you want to do I thinka table will work ie.
EtoG = {
Rain = "xxxx",
Clear = "yyyy"
}
german = EtoG [weathertextvariable]
cdebuhr
November 6th, 2004, 12:50 PM
hi mike,
thx for your fast help.
but i tried to use your code here, and lua says "error: table index is nil".
EtoG = {
rain = "regen",
sunny = "sonnig",
clear = "klar"
}
german=EtoG[rain]
print (german)
what am i doing wrong?
tia
chris
Promixis
November 6th, 2004, 01:55 PM
Must be....
EtoG ["rain"]
cdebuhr
November 6th, 2004, 02:15 PM
thx a lot, mike. it works perfectly now.
Promixis
November 6th, 2004, 02:38 PM
Great!
Please upload you work when done to developer/upload.
cdebuhr
November 6th, 2004, 02:41 PM
sure.
i am modifing jlee´s NR gml -> translating the english-weatherdata.
i am not sure, if you really want that. ;-)
thx
chris
Promixis
November 6th, 2004, 02:43 PM
when using a variable, do not use quotes.
if you are getting an error message, use a print to make sure the variable is not nil
danward79
November 6th, 2004, 02:56 PM
Chris,
You are translating my script!
Do weather.com not have a german page? If you have a look at the xml feed, they may do... perhaps...
http://de.weather.com/
If you have a scout around on this site, and can find a german source of xml data on it. It maybe possible to change the weather script.
cdebuhr
November 6th, 2004, 03:03 PM
CDBWetter = {
MostlyCloudy = "Meist bewölkt",
AMShowers = "Frühe Schauer",
Showers = "Schauer",
LightRain = "Leichter Regen",
PartlyCloudy = "Teils bewölkt",
ShowersLate = "Späte Schauer",
}
That MostlyCloudy should Mostly Cloudy, but that gives an error.
how can i use multiple-word-expressions?
danward79
November 6th, 2004, 03:07 PM
You would have to either remove the space or add a character.
using GSUB or Format
x = "Mostly Cloudy"
x = gsub(x, " ", "")
print (x)
You may find this useful
http://www.lua.org/manual/4.0/
cdebuhr
November 6th, 2004, 03:09 PM
hi dan, you are everywhere. ;-)
hmm. you shocked me with that german site! all my work for nothing? but no... the german site does not seem to offer xml-export of their data.
thx
chris
danward79
November 6th, 2004, 03:12 PM
hi dan, you are everywhere.
Sorry :cry: :cry:
the german site does not seem to offer xml-export of their data.
Worth a try, Oh well you better get back to work.....
Promixis
November 6th, 2004, 04:36 PM
CDBWetter = {
MostlyCloudy = "Meist bewölkt",
AMShowers = "Frühe Schauer",
Showers = "Schauer",
LightRain = "Leichter Regen",
PartlyCloudy = "Teils bewölkt",
ShowersLate = "Späte Schauer",
}
That MostlyCloudy should Mostly Cloudy, but that gives an error.
how can i use multiple-word-expressions?
Then create the table like this....
["Mostly Cloudy"] = ...
cdebuhr
November 6th, 2004, 05:31 PM
thx. works fine now.
danward79
November 6th, 2004, 05:50 PM
Chris,
Just updated the weather code!
http://www.promixis.com/phpBB2/viewtopic.php?p=103912#103912
:D
Don't worry should not effect you too much!! it is on the NR side not Girder.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.