Variable frankenstein

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Variable frankenstein

Dan - Lintouch user
How to create new variable from mount name?

Trink.   multiples variables and fix sufix     ??.large , ??.small ??.tiny

check(S1) ---other file call function
---------
function check(sensor)
if not (sensor .. ".large" == nil) then    <--ok not error       var -> S1.large
         sensor .. ".tiny" = 20     <--- get error               var->  S1.tiny 
end
print( sensor .. ".tiny") --print
end --end function

Or sugest corret implementation: clear, direct ,not complex.





		
_______________________________________________________ 
Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora! 
http://br.mobile.yahoo.com/mailalertas/ 
 


Reply | Threaded
Open this post in threaded view
|

RE: Variable frankenstein

Ram Firestone
Hmmmmm? Well, you seem to be confusing strings with tables. I'm not sure what you are trying to do or exactly what your application
is. I mean assuming sensor was a table you can use constructs like:

sensor.large = ....

or 

suffix = "large"
sensor[suffix] = ...


However I would suggest you get a copy of "Programming in Lua" and read though that. It should have the answers you are looking for.


> -----Original Message-----
> From: [hidden email] [[hidden email]] On Behalf Of
> Dan - Lintouch user
> Sent: Tuesday, October 24, 2006 3:26 PM
> To: [hidden email]
> Subject: Variable frankenstein
> 
> How to create new variable from mount name?
> 
> Trink.   multiples variables and fix sufix     ??.large , ??.small ??.tiny
> 
> check(S1) ---other file call function
> ---------
> function check(sensor)
> if not (sensor .. ".large" == nil) then    <--ok not error       var -> S1.large
>          sensor .. ".tiny" = 20     <--- get error               var->  S1.tiny
> end
> print( sensor .. ".tiny") --print
> end --end function
> 
> Or sugest corret implementation: clear, direct ,not complex.
> 
> 
> 
> 
> 
> 
> _______________________________________________________
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho
> agora!
> http://br.mobile.yahoo.com/mailalertas/
> 


Reply | Threaded
Open this post in threaded view
|

RE: Variable frankenstein

Jerome Vuarand-2
In reply to this post by Dan - Lintouch user
Your problem is not well explained, but for sure your code is wrong.

If sensor is a string or a number, sensor..".tiny" is also a string, and you can't assign anything to a string, only to a variable or a table slot. If sensor is something else (a table, nil, whatever), there is an execution error while trying to concatenate it with a string.

If I understand your problem correctly, you have a table with fields called "large", "small" and "tiny". In that case your code should look like:

function check(sensor)
   if not (sensor.large == nil) then
      sensor.tiny = 20
   end
   print(sensor.tiny)
end

Or if you absolutely want explicit strings:

function check(sensor)
   if not (sensor["large"] == nil) then
      sensor["tiny"] = 20
   end
   print(sensor["tiny"])
end


-----Message d'origine-----
De : [hidden email] [[hidden email]] De la part de Dan - Lintouch user
Envoyé : 24 octobre 2006 18:26
À : [hidden email]
Objet : Variable frankenstein

How to create new variable from mount name?

Trink.   multiples variables and fix sufix     ??.large , ??.small ??.tiny

check(S1) ---other file call function
---------
function check(sensor)
if not (sensor .. ".large" == nil) then    <--ok not error       var -> S1.large
         sensor .. ".tiny" = 20     <--- get error               var->  S1.tiny 
end
print( sensor .. ".tiny") --print
end --end function

Or sugest corret implementation: clear, direct ,not complex.





		
_______________________________________________________
Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora! 
http://br.mobile.yahoo.com/mailalertas/