Mudlet features and API requests

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Mudlet API requests

Post by Lezard »

I recently found this: http://rainbowcoding.com/how-to-create- ... avascript/
And I was wondering if you could make a Mudlet function to make text rainbow colored :D Is this possible?

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Mudlet API requests

Post by chris »

You can do this in lua. Just have a rainbowecho() function or whatever. The arguments would be your starting point/end point, and word. Then just divide your RGB spectrum defined by your gradient range by your word length.

Something like this (written in a browser, so it probably won't work and some functions might not exist as they're written :). Also, change end to something that isn't a reserved name. You can do the same if you want to change the background too)
Code: [show] | [select all] lua
function rainbowecho(start,end,word)
 --get your range
 local red = end[1]-start[1]
 local green = end[2]-start[2]
 local blue = end[3]-start[3]
 local increment = (abs(red)+abs(green)+abs(blue))/length(word)
 for i,letter in pairs(word) do
  decho(letter, start[1]..","..start[2]..","..start[3],"0,0,0")
  local cindex = 1
  local iamt=increment
  while cindex<3 and iamt do
    if start[cindex]<255 then
      local imax = 255-start[cindex]
      if imax>iamt then
         start[cindex]=start[cindex]+iamt
      else
         iamt=iamt-255-start[cindex]
         start[cindex]=255
      end
      cindex=cindex+1
    end
  end
 end
end
rainbowecho({255,125,0},{255,255,0},"this is a test")

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Mudlet API requests

Post by kevutian »

o.O

I prefer to simplify basic things like this personally. How about:
Code: [show] | [select all] lua
function rainbow(args)
	local str = ""
	local colours = { "<red>", "<green>", "<blue>", "<yellow>", "<orange>", "<cyan>" }

	for char in args:gmatch"." do
		str = str .. colours[math.random(#colours)] .. char
	end

	return cecho(str)
end
?

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Mudlet API requests

Post by kevutian »

Alternative method. (Just change the colours as required.)
Code: [show] | [select all] lua
function rainbow(args)
	local str = ""
	local colours = { "<red>", "<orange>", "<yellow>", "<green>", "<blue>", "<blue_violet>", "<DarkViolet>" }
	local pass = 1

	for char in args:gmatch"." do
		str = str .. colours[pass] .. char
		if pass == #colours then pass = 1 end
		pass = pass + 1
	end

	return cecho(str)
end

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Mudlet API requests

Post by Lezard »

Thanks Chris, and Phasma! Let's say I wanted to use string.format() on it, how would I go about getting this code to work:
Code: [show] | [select all] lua
function rainbow(args, ...)
        local str = ""
        local colours = { "<red>", "<orange>", "<yellow>", "<green>", "<blue>", "<blue_violet>", "<DarkViolet>" }
        local pass = 1

        for char in args:gmatch"." do
                str = str .. colours[pass] .. char
                if pass == #colours then pass = 1 end
                pass = pass + 1
        end

        return cecho(string.format(str, (...)))
end
Basically, what I'm trying to accomplish is something like this:
rainbow("This is a %s", "Test")

Thanks! :)

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: Mudlet API requests

Post by kevutian »

It really depends on what you want to format it to, although simply doing:
Code: [show] | [select all] lua
return cecho(string.format("%s", str))
Will ensure it gets formatted as a string.

Lezard
Posts: 36
Joined: Wed Aug 29, 2012 6:47 pm

Re: Mudlet API requests

Post by Lezard »

I also did this, and it seems to work nicely..
Code: [show] | [select all] lua
function sys.echo(...)
	cecho(rainbow(string.format(...)))
end
:D

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

Re: Mudlet API requests

Post by Vadi »

A function to check if the selection is underlined/bold/italic would be nice - useful in scripts.

Ginga Giri Giri
Posts: 11
Joined: Mon Dec 17, 2012 2:58 am

Re: Mudlet API requests

Post by Ginga Giri Giri »

How about extended IRC support? An idea we've been throwing around on a MUSH I play is how cool it would be to have a sub-channel for scripts, like in WoW, that talk to one another for various networking purposes. Implementing better IRC functionality in Mudlet would make this very possible.

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: Mudlet API requests

Post by Omni »

Would be nice to have events for when installing packages either through the gui or the new function. One for erroring and another for success.

Also, the ability to give a profile argument to the connect and disconnect functions.

Post Reply