Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Jun 16, 2009 2:13 am   

Broken output after running this lua alias... why?
 
I have the following alias that shows a calendar of the month based on the parameters. I have a script that sends chats to a different window. The script is below:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="showcal" language="Lua" copy="yes">
    <value><![CDATA[do
local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

  local function is_leap_year(year)
    return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
  end

  function get_days_in_month(month, year)
    if month == 2 and is_leap_year(year) then
      return 29
    else
      return days_in_month[month]
    end
  end
end

function get_day_of_week(dd, mm, yy)
  dw=os.date('*t',os.time{year=yy,month=mm,day=dd})['wday']
  return dw,({"Sun","Mon","Tue","Wed","Thu","Fri","Sat" })[dw]
end

function get_date_parts(date_str)
  _,_,y,m,d=string.find(date_str, "(%d+)-(%d+)-(%d+)")
  return tonumber(y),tonumber(m),tonumber(d)
end

-- based on original code from sam_lie
function show_calendar(cdate)
  local yy, mm, dd = get_date_parts(cdate)
  local month_days = get_days_in_month(mm, yy)
  local day_week = get_day_of_week(1, mm, yy)

        --- day in which the calendar day start.. 1=Sunday, 2="Monday"
  local day_start = 1

  local days_of_week = {{ "Sun", 1 }, { "Mon", 2 } , { "Tue", 3 }, { "Wed", 4 }, { "Thu", 5 }, { "Fri", 6 }, { "Sat", 7 }}
  local days_of_week_ordered = {}
 
  for k=1, 7 do
    p = k+day_start-1
    if (p>7) then
      p=p-7
    end
    v = {}
    v.dayname = days_of_week[p][1]
    v.daynum = days_of_week[p][2]
    table.insert(days_of_week_ordered, v)
  end

  local out = "<h3>" .. cdate .. "</h3>"
  out = out .. "<tr>"
  for i,v in ipairs(days_of_week_ordered) do
    out = out .. v.dayname .. "  "

    if (day_week == v.daynum) then
      d = - i + 2
    end
  end
  out = out .. "<p>"

  while (d < month_days) do
    out = out .. "<p>"
    for i,v in ipairs(days_of_week) do
      if (d>=1 and d <=month_days) then
        if (d<10) then
          if (d==dd) then
          out = out .. "<font color='red'> 0" .. d .. "</font>  "
          else
          out = out .. " 0" .. d .. "  "
          end
        else
        if (d==dd) then
          out = out .. "<font color='red'> " .. d .. "</font>  "
        else
        out = out .. " " .. d .. "  "
        end
      end
      else
        out = out .. "     "
      end

      d = d + 1
    end
    out = out .. "<p>"
  end

  out = out .. "<p>"

  return out
end

zs.cmd.mxp(show_calendar(zs.param(1) .. '-' .. zs.param(2) .. '-' .. zs.param(3)))
]]></value>
  </alias>
</cmud>


Whenever I run the script, my chat window winds up breaking like so:

Code:
xxxxx gametalks
:
xxxxxxx
(
imm
)
 xxxxx: xxxxxxxxxxxx
xxxxx gametalks
:
xxxxxx
xxxxxxx gametalks
:
xxxxxxxxx


Any idea why? I'm stumped on this... The main window isn't affected. The alias outputs to the main window. I have to restart the Chat window in order for it to start showing up appropriately again.

Charneus
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net