Page 1 of 2

Prompt echo not working correctly.

Posted: Thu Jan 14, 2010 7:55 pm
by Pain
The problem is, that mudlet isn't echoing my health after the prompt.
Just a test to try and figure this client out.

Here's my output:

3297h, 3894m cexkdb-

When it should be:

3297h, 3894m cexkdb-3297(100)h,

here's my code:

Code: Select all

RegExp: ^(\d+)h\, (\d+)m (\w+)\-$


  -- Acquire current/previous health/mana
  
  hp.prev = hp.cur
  mp.prev = mp.cur
  hp.cur = tonumber(matches[2])
  mp.cur = tonumber(matches[3])
 
  -- Acquire defences
  
  local defs = matches[4]

  aff.prone = (string.find (defs, 'p') ~= nil)
  bal.bal = (string.find (defs, 'x') ~= nil)
  bal.eq = (string.find (defs, 'e') ~= nil)
  def.blind = (string.find (defs, 'b') ~= nil)
  def.deaf = (string.find (defs, 'd') ~= nil)
  def.phased = (string.find (defs, '@') ~= nil)

  hp.per = math.floor (100 * ( hp.cur / hp.max ))
  mp.per = math.floor (100 * ( mp.cur / mp.max ))

  if hp.per > 66 then
    hp.col = 'green'
  elseif hp.per > 33 then
    hp.col = 'gold'
  elseif hp.per > 0 then
    hp.col = 'red'
  else
    hp.col = 'silver'
  end

  if mp.per > 66 then
    mp.col = 'green'
  elseif mp.per > 33 then
    mp.col = 'gold'
  elseif mp.per > 0 then
    mp.col = 'red'
  else
    mp.col = 'silver'
  end

  cecho ('green', 'black',hp.cur)
  cecho ('silver','black','('..hp.per..')h,')
Here's some things in my scripts folder:

Code: Select all

color_table = {
  green                 = {0, 128, 0},
  lime	                = {0, 255, 0},
  silver	        = {192, 192, 192},
  }

function cecho (fgcol, bgcol, str)
  fg(fgcol)
  bg(bgcol)
  echo (str)
  resetformat()
end
Any suggestions?

Re: Prompt echo not working correctly.

Posted: Thu Jan 14, 2010 8:51 pm
by Heiko
couple of hints:

- resetFormat() - Lua is case sensitive
- check debug console for your scripting errors (button in the script editor)
- most common error is undefined global variables
- mudlet has its own cecho function

Re: Prompt echo not working correctly.

Posted: Thu Jan 14, 2010 9:19 pm
by Pain
Thanks, how does the cecho function work? I don't see it in the help files at all.

Re: Prompt echo not working correctly.

Posted: Thu Jan 14, 2010 9:23 pm
by Pain
Additionally, I get this error from the debug console. Can't copy from debug console but, it says that I'm attempting to index field '?' (a nil value) from line 690 of LuaGlobal.lua.

Code: Select all

689: function bg(name)
690:   setBgColor(color_table[name][1], color_table[name][2], color_table[name][3])
691: end

Re: Prompt echo not working correctly.

Posted: Thu Jan 14, 2010 9:29 pm
by Vadi
That's because you broke the color_table by defining your down very small one which doesn't have the color you're asking for.

Use right-click to copy from debug

Re: Prompt echo not working correctly.

Posted: Fri Jan 15, 2010 1:45 pm
by Pain

Code: Select all

new line arrived:3297h, 3894m exdb-

Trigger name=prompt(^(\d+)h\, (\d+)m (\w+)\-$) matched.
capture group #1 = <3297h, 3894m exdb->
capture group #2 = <3297>
capture group #3 = <3894>
capture group #4 = <exdb>
LUA: ERROR running script prompt (Trigger6) ERROR:Lua error:...ts and Settings/Matthew/.
config/mudlet/LuaGlobal.lua:690: attempt to index field '?' (a nil value)

Re: Prompt echo not working correctly.

Posted: Fri Jan 15, 2010 1:46 pm
by Pain
Shouldn't it have been fine because I was adding to the table? Maybe I missed something.

Re: Prompt echo not working correctly.

Posted: Fri Jan 15, 2010 4:49 pm
by ixokai
You didn't add to the table, you defined a new table with the same name -- thus overwriting the existing one. If you want to add to the table, you'd do like:

Code: Select all

color_table.green = {0, 128, 0}
color_table.lime = {0, 255, 0}
color_table.silver = {192,192,192}
Although I'm not sure if you really need to add new stuff, aren't those colors already represented?

Re: Prompt echo not working correctly.

Posted: Fri Jan 15, 2010 9:11 pm
by Pain
no, those are the colors Nick Gammon and Zugg agreed to use in their clients that are not used in this client. Lime (bright green) is normally green, there's no actual green, and there's no silver, heh.

And thanks a ton for all of your help guys :)

Re: Prompt echo not working correctly.

Posted: Sat Jan 16, 2010 5:05 am
by Alexander Divine
The names aren't the same but a lot of standard colors are in the color_table. In Mudlet we call lime "green."