Jump to content




[1.31] Small Monitor API v1.2


  • This topic is locked This topic is locked
28 replies to this topic

#1 ihaveamac

  • New Members
  • 15 posts

Posted 13 March 2012 - 05:32 AM

While the API isn't really big, I think it would save me time rather than doing a bunch of "term.redirect(peripheral.wrap(side)) mycode() mycodeagain() term.restore() write("Did something")".
Currently I added normal write/print functions, flashing text and marquee left and right. More is coming.
Current functions:
Spoiler
Source:
Spoiler
Download: here (it may save as a .txt)

#2 Tron

  • Members
  • 63 posts
  • LocationMinecraftia

Posted 13 March 2012 - 06:10 PM

I keep getting
lua:43: attempt to call nil
when I try to Use this?

#3 ihaveamac

  • New Members
  • 15 posts

Posted 13 March 2012 - 10:43 PM

View Postluker2009, on 13 March 2012 - 06:10 PM, said:

I keep getting
lua:43: attempt to call nil
when I try to Use this?
You're calling a function that doesn't exist. It would be monitorapi.writeM(side, text), not write since it was calling itself and not the OS function write(). Unless someone can think of a workaround, some of them will have an M after that for Monitor.

#4 Tron

  • Members
  • 63 posts
  • LocationMinecraftia

Posted 14 March 2012 - 12:14 AM

Ok thanks, I forgot the monitorapi part :/

#5 mrgreaper

  • Members
  • 88 posts

Posted 15 March 2012 - 03:31 AM

this looks majorly useful, thank you

#6 bobster71

  • Members
  • 36 posts

Posted 15 March 2012 - 10:09 PM

I agree with mrgreaper. Very nice. Very useful. Thanks. Saves me the trouble of building something like it.

#7 mrgreaper

  • Members
  • 88 posts

Posted 16 March 2012 - 04:33 PM

bit of an error

--parallel.waitForAny(one,two,three,four,five)
function one()
monitorapi.marqueeLeft("top", "We have a facebook group and a webpage http://max-xtreme-server.enjin.com/ the facebook group will get you a faster response to any quaries", 5, 0.1)
end
function two()
monitorapi.marqueeLeft("top", "We run multiple plugins : Ask8ball Chestshop Citizens CommandBook dynmap dynmap-Herochat ecoCreature Falsebook(all modules but cart) Herochat iChat iConomy Lockette mcbans mcMMO MobCatcher Mobloot Myworlds PermissionsBukkit Residence ServerEvents Vault WorldEdit Worldguard", 4, 0.1)
end
function three()
monitorapi.marqueeLeft("top", "we also run multiple mods : IC2 Buildcraft animalbikes forestry morepistons computercraft", 3, 0.1)
end
function four()
monitorapi.marqueeLeft("top", "testing2..........", 2, 0.1)
end
function five()
monitorapi.marqueeLeft("top", "testing1..........", 1, 0.1)
end
one()
two()
three()
four()
five()

the long sentences dont appear it simply skips them (ignore the remed out parallel line i wanted to have multiple lines scrolling when i first made it but that wont work due to limitation of lua)

also when the testing2...... and 1 line scroll they start on the right as the whole word and disapear when the first letter hits the left side, they dont scroll like a marque should if that makes sense

im guessing its an error with the way i called the api?

#8 ihaveamac

  • New Members
  • 15 posts

Posted 16 March 2012 - 06:30 PM

View Postmrgreaper, on 16 March 2012 - 04:33 PM, said:

bit of an error

--parallel.waitForAny(one,two,three,four,five)
function one()
monitorapi.marqueeLeft("top", "We have a facebook group and a webpage http://max-xtreme-server.enjin.com/ the facebook group will get you a faster response to any quaries", 5, 0.1)
end
function two()
monitorapi.marqueeLeft("top", "We run multiple plugins : Ask8ball Chestshop Citizens CommandBook dynmap dynmap-Herochat ecoCreature Falsebook(all modules but cart) Herochat iChat iConomy Lockette mcbans mcMMO MobCatcher Mobloot Myworlds PermissionsBukkit Residence ServerEvents Vault WorldEdit Worldguard", 4, 0.1)
end
function three()
monitorapi.marqueeLeft("top", "we also run multiple mods : IC2 Buildcraft animalbikes forestry morepistons computercraft", 3, 0.1)
end
function four()
monitorapi.marqueeLeft("top", "testing2..........", 2, 0.1)
end
function five()
monitorapi.marqueeLeft("top", "testing1..........", 1, 0.1)
end
one()
two()
three()
four()
five()

the long sentences dont appear it simply skips them (ignore the remed out parallel line i wanted to have multiple lines scrolling when i first made it but that wont work due to limitation of lua)

also when the testing2...... and 1 line scroll they start on the right as the whole word and disapear when the first letter hits the left side, they dont scroll like a marque should if that makes sense

im guessing its an error with the way i called the api?
I had trouble trying to make it like a real one, where it would be "testing" then "esting" then "sting" and so on. I tried to make it and I didn't get it working. For now, you can make the monitor longer and cover the sides with blocks like RedPower cover plates (when the mod is updated). If anyone knows how to make it like a real marquee please tell me. I'll keep trying to make it work properly. Sorry, that's how it is right now. :D/>

The basic functionality of the text moving from one side to another works though.

Edit: You could also separate the long text into several lines.

#9 ihaveamac

  • New Members
  • 15 posts

Posted 17 March 2012 - 01:52 AM

Version 1.1 now here, added monitorapi.goto(side) (replacement for term.redirect(peripheral.wrap("side")) and monitorapi.runprgm(side, prgm, args). :D/>

#10 mrgreaper

  • Members
  • 88 posts

Posted 17 March 2012 - 10:15 PM

View Postihaveamac, on 16 March 2012 - 06:30 PM, said:

View Postmrgreaper, on 16 March 2012 - 04:33 PM, said:

bit of an error



the long sentences dont appear it simply skips them (ignore the remed out parallel line i wanted to have multiple lines scrolling when i first made it but that wont work due to limitation of lua)

also when the testing2...... and 1 line scroll they start on the right as the whole word and disapear when the first letter hits the left side, they dont scroll like a marque should if that makes sense

im guessing its an error with the way i called the api?
I had trouble trying to make it like a real one, where it would be "testing" then "esting" then "sting" and so on. I tried to make it and I didn't get it working. For now, you can make the monitor longer and cover the sides with blocks like RedPower cover plates (when the mod is updated). If anyone knows how to make it like a real marquee please tell me. I'll keep trying to make it work properly. Sorry, that's how it is right now. :D/>

The basic functionality of the text moving from one side to another works though.

Edit: You could also separate the long text into several lines.

how did they do it with the space ship animation on the hidden starwars film ? that used text scrolling
(if you dont know what im talking about build a big monitier but a computer under it then type cd rom cd programs cd secret and run monitor top alongtimeago)

mind you i guess they knew exactly what lines they were having so it could be just a load of write commands

shame we cant convert a line of text into seperate 1 char per variable and then write the variables one by one and scroll that way

#11 ihaveamac

  • New Members
  • 15 posts

Posted 18 March 2012 - 12:51 AM

View Postmrgreaper, on 17 March 2012 - 10:15 PM, said:

View Postihaveamac, on 16 March 2012 - 06:30 PM, said:

View Postmrgreaper, on 16 March 2012 - 04:33 PM, said:

bit of an error



the long sentences dont appear it simply skips them (ignore the remed out parallel line i wanted to have multiple lines scrolling when i first made it but that wont work due to limitation of lua)

also when the testing2...... and 1 line scroll they start on the right as the whole word and disapear when the first letter hits the left side, they dont scroll like a marque should if that makes sense

im guessing its an error with the way i called the api?
I had trouble trying to make it like a real one, where it would be "testing" then "esting" then "sting" and so on. I tried to make it and I didn't get it working. For now, you can make the monitor longer and cover the sides with blocks like RedPower cover plates (when the mod is updated). If anyone knows how to make it like a real marquee please tell me. I'll keep trying to make it work properly. Sorry, that's how it is right now. :D/>

The basic functionality of the text moving from one side to another works though.

Edit: You could also separate the long text into several lines.

how did they do it with the space ship animation on the hidden starwars film ? that used text scrolling
(if you dont know what im talking about build a big monitier but a computer under it then type cd rom cd programs cd secret and run monitor top alongtimeago)

mind you i guess they knew exactly what lines they were having so it could be just a load of write commands

shame we cant convert a line of text into seperate 1 char per variable and then write the variables one by one and scroll that way
In that program, it does use a bunch of print lines, so it does something like print("test") then print("est") then print("st") and so on. The code for the marquee function in this doesn't do that, it does the simple function of moving text from one side to another and doesn't use a bunch of print lines.

#12 Popinman322

  • New Members
  • 1 posts

Posted 28 March 2012 - 03:11 PM

function loopedMarqueeRight(side, text, ypos, sleep)
	if not peripheral.isPresent(side) then return end
	local control = true
	local function halt() control = false; end
	coroutine.wrap(function()
		while control do
			local screen = peripheral.wrap(side)
			for i = 1, text:len() do
				screen.setCursorPos(1,ypos)
				screen.clearLine()
				
				screen.write(text:sub(i) .. text:sub(1,i-1))
				
				os.sleep(sleep)
				screen.clearLine()
			end
		end
	end)()
	return halt
end

local haltLoop = loopedMarqueeRight("right", "Moocowsaysmoo! ", 1, 0.1)
sleep(10)
haltLoop()

Could anyone test this code out for me? I don't have access to a ComputerCraft MC client atm.

#13 ihaveamac

  • New Members
  • 15 posts

Posted 08 April 2012 - 12:35 AM

View PostPopinman322, on 28 March 2012 - 03:11 PM, said:

function loopedMarqueeRight(side, text, ypos, sleep)
	if not peripheral.isPresent(side) then return end
	local control = true
	local function halt() control = false; end
	coroutine.wrap(function()
		while control do
			local screen = peripheral.wrap(side)
			for i = 1, text:len() do
				screen.setCursorPos(1,ypos)
				screen.clearLine()
				
				screen.write(text:sub(i) .. text:sub(1,i-1))
				
				os.sleep(sleep)
				screen.clearLine()
			end
		end
	end)()
	return halt
end

local haltLoop = loopedMarqueeRight("right", "Moocowsaysmoo! ", 1, 0.1)
sleep(10)
haltLoop()

Could anyone test this code out for me? I don't have access to a ComputerCraft MC client atm.
I never got CC 1.32 since I never paid attention. I didn't really use mods for 1.2.4 other than TMI and a few others. I'll try to get CC for 1.2.5 when it comes out and try it.

#14 ihaveamac

  • New Members
  • 15 posts

Posted 17 April 2012 - 02:16 AM

View PostPopinman322, on 28 March 2012 - 03:11 PM, said:

function loopedMarqueeRight(side, text, ypos, sleep)
	if not peripheral.isPresent(side) then return end
	local control = true
	local function halt() control = false; end
	coroutine.wrap(function()
		while control do
			local screen = peripheral.wrap(side)
			for i = 1, text:len() do
				screen.setCursorPos(1,ypos)
				screen.clearLine()
				
				screen.write(text:sub(i) .. text:sub(1,i-1))
				
				os.sleep(sleep)
				screen.clearLine()
			end
		end
	end)()
	return halt
end

local haltLoop = loopedMarqueeRight("right", "Moocowsaysmoo! ", 1, 0.1)
sleep(10)
haltLoop()

Could anyone test this code out for me? I don't have access to a ComputerCraft MC client atm.
Doesn't work. It just printed the text but didn't scroll.

Yes, CC1.32 works with 1.2.5.

#15 iRiky

  • Members
  • 24 posts

Posted 20 April 2012 - 03:04 PM

i don't reach to use runprgm this is a part of code
:
runprgm("Top", "time")

how i can run the program ?
scuse me i'm new about computercraft and non english xD

#16 ihaveamac

  • New Members
  • 15 posts

Posted 23 April 2012 - 10:45 PM

View PostiRiky, on 20 April 2012 - 03:04 PM, said:

i don't reach to use runprgm this is a part of code
:
runprgm("Top", "time")

how i can run the program ?
scuse me i'm new about computercraft and non english xD
No, it's fine. I made this to make it easy for new lua programmers to do stuff with monitors.

Did you save the file in the apis directory? If you did, you need to do monitorapi.runprgm("top", "time") or else it doesn't know what API to use.

#17 MathManiac

  • Members
  • 60 posts
  • LocationWashington, United States

Posted 19 May 2012 - 03:37 AM

:3 Oh, monitors! I should make monitor programs!

#18 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 May 2012 - 05:07 AM

These may marquee properly:

function marqueeLeft(side, text, ypos, sleep)
    if peripheral.isPresent(side) then
	    term.redirect(peripheral.wrap(side))
	    local sx, sy = term.getSize()
	    text = string.rep(" ", sx - 1)..text
	    for i=1,string.len(text) do
		    term.clearLine()
		    displayString = string.sub(text, i, math.min(string.len(text), i + sx - 1))
		    write(displayString)
		    os.sleep(sleep)
	    end
	    term.clearLine()
	    term.restore()
    end
end
function marqueeRight(side, text, ypos, sleep)
    if peripheral.isPresent(side) then
	    term.redirect(peripheral.wrap(side))
	    local sx, sy = term.getSize()
	    text = string.rep(" ", sx - 1)..text
	    for i = 1,string.len(text) do
		    term.clearLine()
		    displayString = string.sub(text, -i, math.min(string.len(text), i + sx - 1))
		    write(displayString)
		    os.sleep(sleep)
	    end
	    term.clearLine()
	    term.restore()
    end
end


#19 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 19 May 2012 - 08:14 AM

You should add lua.
function mFunction(side, functionname)
  term.redirect(peripheral.wrap(side))
  functionname()
  term.restore()
end

function test()
  print "Hello world!"
end

mFunction("left", test)


#20 ihaveamac

  • New Members
  • 15 posts

Posted 15 June 2012 - 04:27 AM

Hey, sorry for my inactivity! I was busy on school and we were on a week-long road trip, but I'm back home and ready to work.

View PostLyqyd, on 19 May 2012 - 05:07 AM, said:

These may marquee properly:

function marqueeLeft(side, text, ypos, sleep)
	if peripheral.isPresent(side) then
		term.redirect(peripheral.wrap(side))
		local sx, sy = term.getSize()
		text = string.rep(" ", sx - 1)..text
		for i=1,string.len(text) do
			term.clearLine()
			displayString = string.sub(text, i, math.min(string.len(text), i + sx - 1))
			write(displayString)
			os.sleep(sleep)
		end
		term.clearLine()
		term.restore()
	end
end
function marqueeRight(side, text, ypos, sleep)
	if peripheral.isPresent(side) then
		term.redirect(peripheral.wrap(side))
		local sx, sy = term.getSize()
		text = string.rep(" ", sx - 1)..text
		for i = 1,string.len(text) do
			term.clearLine()
			displayString = string.sub(text, -i, math.min(string.len(text), i + sx - 1))
			write(displayString)
			os.sleep(sleep)
		end
		term.clearLine()
		term.restore()
	end
end
Thanks, I'll try this out when I can. :(/> I've never heard of math.min() though.

View PostComputerCraftFan11, on 19 May 2012 - 08:14 AM, said:

You should add lua.
function mFunction(side, functionname)
  term.redirect(peripheral.wrap(side))
  functionname()
  term.restore()
end

function test()
  print "Hello world!"
end

mFunction("left", test)
I'll try this out. It could be "monitorapi.lua("left", function() print("HELLO WORLD") end)". (yes, that should work)





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users