lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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 : lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] De la part de Dan - Lintouch user
Envoyé : 24 octobre 2006 18:26
À : lua@bazar2.conectiva.com.br
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/