Prompt echo not working correctly.

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Prompt echo not working correctly.

Post 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?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Prompt echo not working correctly.

Post 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

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Re: Prompt echo not working correctly.

Post by Pain »

Thanks, how does the cecho function work? I don't see it in the help files at all.

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Re: Prompt echo not working correctly.

Post 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

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Prompt echo not working correctly.

Post 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

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Re: Prompt echo not working correctly.

Post 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)

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Re: Prompt echo not working correctly.

Post by Pain »

Shouldn't it have been fine because I was adding to the table? Maybe I missed something.

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: Prompt echo not working correctly.

Post 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?

Pain
Posts: 18
Joined: Sat Jan 09, 2010 1:13 am

Re: Prompt echo not working correctly.

Post 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 :)

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: Prompt echo not working correctly.

Post 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."

Post Reply