Friday 15 June 2012

if statement - Lua: Coloring "Win" status fails -



if statement - Lua: Coloring "Win" status fails -

i've had function 2 years now, , can't seem figure out why it's not working colorizing. here's entire function, you'll see core parts aren't working below.

function showscoreboard() local function len(arg) homecoming string.len(arg) end local function tbuff(arg) if len(arg) < 3 homecoming arg.." " else homecoming arg end end local function sbuff(arg) if len(arg) < 2 homecoming " "..arg else homecoming arg end end local function cteam(t,s) local status = s or nil local forecolor = "" if status == "p" forecolor = "yellow" elseif status == "w" forecolor = "cyan" else forecolor = "limegreen" end homecoming "<color fore="..forecolor..">"..t.."</color>" end local function bcolor(i) local = or 0 if i%2 == 1 homecoming "maroon" else homecoming "navy" end end local scorestring = "" local allteams = {["atl"]=0,["was"]=0,["mia"]=0,["cle"]=0,["oak"]=0,["sd"]=0,["ind"]=0,["nyj"]=0,["ten"]=0,["sea"]=0,["phi"]=0,["den"]=0,["gb"]=0,["buf"]=0,["tb"]=0,["pit"]=0,["min"]=0,["hou"]=0,["det"]=0,["tb"]=0,["car"]=0,["chi"]=0,["stl"]=0,["nyg"]=0,["ari"]=0,["no"]=0,["kc"]=0,["sf"]=0,["ne"]=0} local byeweek = "" _,v in ipairs(nflscores.ss) allteams[v[5]] = 1 allteams[v[7]] = 1 end i,v in pairs(allteams) if v == 0 byeweek = byeweek .. "<color white>".. .."</color>\r" end end i,v in ipairs(nflscores.ss) local hteam = v[7] local ateam = v[5] local qgame = v[3] local hscre = v[8] or 0 local ascre = v[6] or 0 if v[4] qtime = "<color white>time: "..v[4].."</color>" else qtime = "" end local gposs = v[9] or "" if gposs ~= "" if gposs == hteam hteam = cteam(tbuff(hteam),"p") ateam = cteam(tbuff(ateam)) else ateam = cteam(tbuff(ateam),"p") hteam = cteam(tbuff(hteam)) end else hteam = cteam(tbuff(hteam)) ateam = cteam(tbuff(ateam)) end if qgame == "final" or qgame == "final overtime" if hscre > ascre hteam = cteam(tbuff(hteam),"w") ateam = cteam(tbuff(ateam)) elseif hscre < ascre ateam = cteam(tbuff(ateam),"w") hteam = cteam(tbuff(hteam)) else ateam = cteam(tbuff(ateam)) hteam = cteam(tbuff(hteam)) end if qgame == "final" qgame = "<color cyan>f</color>" elseif qgame == "final overtime" qgame = "<color cyan>f/ot</color>" end elseif qgame == "pregame" qgame = "<color cyan>pre</color>" elseif qgame == "halftime" qgame = "<color white>"..qgame.."</color>" else qgame = "<color white>q"..qgame.."</color>" end scorestring = scorestring .. "<color back="..bcolor(i) .. ">".. v[1] .. ": " .. ateam .. "<color white>: " .. sbuff(ascre) .. "</color> <color black>@</color> " .. hteam .. "<color white>: ".. sbuff(hscre) .."</color></color> " .. qgame .. " " .. qtime .. "\r" end homecoming scorestring .. "<color white>bye week:</color>\r"..byeweek end

the part isn't working is:

if hscre > ascre hteam = cteam(tbuff(hteam),"w") ateam = cteam(tbuff(ateam)) elseif hscre < ascre ateam = cteam(tbuff(ateam),"w") hteam = cteam(tbuff(hteam)) else ateam = cteam(tbuff(ateam)) hteam = cteam(tbuff(hteam)) end

the function cteam is:

local function cteam(t,s) local status = s or nil local forecolor = "" if status == "p" forecolor = "yellow" elseif status == "w" forecolor = "cyan" else forecolor = "limegreen" end homecoming "<color fore="..forecolor..">"..t.."</color>" end

now, colors "p" status fine. when status changes "w", fails, , life of me, cannot figure out why. missing something? code lot cleaner?

edit: haven't found issue problem, apparently "elseif status == "w" statement bypassed. when games beingness played, right team in possession shows yellow. however, after game over, both teams lime green, if no score higher other.

2nd edit: error listed in first reply has been corrected. still, doesn't solve issue. i'm still quite @ loss.

nothing jumps out , can't test here here things check:

you mention cteam works correctly during game, , it's 1 time game on cteam doesn't give right final result. logic of cteam correct. problem must in code calls cteam: cteam ever called s equals "w": never happen if hscre , ascre same. there typo in branch code calls cteam:

if hscre > ascre hteam = cteam(tbuff(hteam),"w") ateam = cteam(tbuff(ateam)) elseif hscre < ascre ateam = cteam(tbuff(ateam,"w")) -- err hteam = cteam(tbuff(hteam)) else ateam = cteam(tbuff(ateam)) hteam = cteam(tbuff(hteam)) end

the line tagged err should be:

ateam = cteam(tbuff(ateam),"w")

about cleaning code: post question on stackoverflow's code review forum.

if-statement lua

No comments:

Post a Comment