Jump to content

[Solucionado] No reconoce el setTimer, pero si el resto


Recommended Posts

Posted (edited)

El problema que tengo es, NO FUNCIONA el setTimer, y el resto del script si, osea :roll:

sx,sy = guiGetScreenSize() 
t = {} 
tt = { 
["b1"]=0 
} 
function returnRelative (x,z) 
z = z+1 
return -x+(x*z) 
end 
function renderVIP () 
    if getElementData(localPlayer, "tiempoSEC") >= 144000 then 
    dxDrawRectangle(returnRelative(sx,0), returnRelative(sy,1), sx, returnRelative(sy,-0.05), "0xaa000000") 
    dxDrawRectangle(0,returnRelative(sy, 0.95),sx,returnRelative(sy,0.0025), "0xFF000000") 
    dxDrawText("[VIP MENU] |", returnRelative(sx,0.005), returnRelative(sy,0.95),0,0, "0xFFFFFFFF", 2, "default-bold") 
    --Botones VIP 
        if t["b1"] == nil then 
        t["b1"] = guiCreateButton(returnRelative(sx, 0.2), returnRelative(sy, 0.95),returnRelative(sx, 0.1), returnRelative(sy,0.05), "Vida", false) 
        addEventHandler("onClientGUIClick", t["b1"], bma) 
        end 
    end 
end 
addEventHandler("onClientRender", root, renderVIP) 
function counter () 
    for k,v in ipairs(tt) do 
    --outputChatBox(tostring(k)..tostring(v)) 
    end 
end 
setTimer(counter, 1000, 0) 
function vidaButton () 
    if tt["b1"] <= 0 then 
    guiSetText(t["b1"], "Vida") 
    --removeEventHandler("onClientRender", root, vidaButton) 
    else 
    guiSetText(t["b1"], tostring(math.floor(tt["b1"]))) 
    end 
end 
function bma () 
    if source == t["b1"] then 
        if tt["b1"] <= 0 then 
        tt["b1"] = 60 
        end 
    addEventHandler("onClientRender", root,vidaButton) 
    end 
end 

Edited by Guest
Posted

El timer probablemente está funcionando, quizás lo que falla es el loop.

Cuando usas tablas que no están indexadas numéricamente o no están ordenadas, debes usar pairs()

Aquí tienes un ejemplo de lo que pasa:

Tabla usada:

  
t = { 
  [1] = 'eggs'; 
  [2] = 'cereal'; 
  [3] = 'pancakes'; 
  [5] = 'waffles'; -- I skipped 4 for a reason. 
  
  myfavorite = 'bacon'; 
  myleastfavorite = 'toast'; 
} 
  

Prueba con pairs() e ipairs().

  
Pairs   1   eggs 
Pairs   2   cereal 
Pairs   3   pancakes 
Pairs   5   waffles 
Pairs   myfavorite  bacon 
Pairs   myleastfavorite toast 
  
Ipairs  1   eggs 
Ipairs  2   cereal 
Ipairs  3   pancakes 
  

Función utilizada:

  
for i,v in pairs(t) do 
   print ("Pairs", i,v) 
end 
for i,v in ipairs(t) do 
   print ("Ipairs", i,v) 
end 
  

Una mejor explicación: http://www.computercraft.info/forums2/i ... __p__41709

Posted
El timer probablemente está funcionando, quizás lo que falla es el loop.

Cuando usas tablas que no están indexadas numéricamente o no están ordenadas, debes usar pairs()

Aquí tienes un ejemplo de lo que pasa:

Tabla usada:

  
t = { 
  [1] = 'eggs'; 
  [2] = 'cereal'; 
  [3] = 'pancakes'; 
  [5] = 'waffles'; -- I skipped 4 for a reason. 
  
  myfavorite = 'bacon'; 
  myleastfavorite = 'toast'; 
} 
  

Prueba con pairs() e ipairs().

  
Pairs   1   eggs 
Pairs   2   cereal 
Pairs   3   pancakes 
Pairs   5   waffles 
Pairs   myfavorite  bacon 
Pairs   myleastfavorite toast 
  
Ipairs  1   eggs 
Ipairs  2   cereal 
Ipairs  3   pancakes 
  

Función utilizada:

  
for i,v in pairs(t) do 
   print ("Pairs", i,v) 
end 
for i,v in ipairs(t) do 
   print ("Ipairs", i,v) 
end 
  

Una mejor explicación: http://www.computercraft.info/forums2/i ... __p__41709

En el pasado tambien me habia ocurrido errores de este tipo, ahora entendi la diferencia

i[ndex]pairs()

pairs()

Gracias tomas :D

Time to scripting HARD

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...