Jump to content




computercrafts terminal


23 replies to this topic

#1 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 10 August 2018 - 06:48 PM

I have two qestions for you guys today

1. are we limited to the colors in the colors api? I know we can chance sharders or what ever right? can somebody explain? (in opencomputers you are able to give 8bit rgb values but as i understand we can only use hard coded colors)
2. in opencomputers you are able to get whats on a spesific cordinate on the screen
component.gpu.get(x,y)
that returned the background color, foreground color, charecter, and color range is this possible in computercraft?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 August 2018 - 08:37 PM

1. You can only use the built in colors; however in later versions what those colors are can be changed on the fly. Example: http://www.computerc...s-a-great-idea/
2. No.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 August 2018 - 02:00 AM

Are you sure OC doesn't use 24bit RGB values? 8bits per colour is fairly uncommon, whereas 8bits per channel is the norm.

ComputerCraft uses a sixteen colour palette. You need v1.80+ in order to change its contents.

You can't get the hardware-based terminal to tell you what it's drawn, but you can write a software buffer with that capability, and then redirect all terminal output through that. For example, it would be fairly trivial to create a modified version of the window API that simply adds a few "get" functions for retrieving buffer contents.

Not really sure why you'd want that, though. The only point I can see to gathering screen content is so that you can redraw it later, and buffers tend to be able to do that without outside help - eg.

#4 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 11 August 2018 - 08:46 AM

View PostBomb Bloke, on 11 August 2018 - 02:00 AM, said:

Are you sure OC doesn't use 24bit RGB values? 8bits per colour is fairly uncommon, whereas 8bits per channel is the norm.

ComputerCraft uses a sixteen colour palette. You need v1.80+ in order to change its contents.

You can't get the hardware-based terminal to tell you what it's drawn, but you can write a software buffer with that capability, and then redirect all terminal output through that. For example, it would be fairly trivial to create a modified version of the window API that simply adds a few "get" functions for retrieving buffer contents.

Not really sure why you'd want that, though. The only point I can see to gathering screen content is so that you can redraw it later, and buffers tend to be able to do that without outside help - eg.

--OC color exaple (sorry i wasn't clear i meant 8 bit for evrey channel)

compunent.gpu.setBackgroundColor(0xffffff) --r:255,g:255,b:255
compunent.gpu.setBackgroundColor(0x000000) --r:0,g:0,b:0


#5 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 11 August 2018 - 08:54 AM

the only reson i use CC is becuse of OC is relistic so it limits the amout of updates per secount resolveing in lagy grafics allso CC computers sems to have no hard limit of how much ram they are allowed to use (given that i just told my video format to play a video that was 270KB witch as i understand is really big for 1980's standarts) (right?) you are running out of ram alot in OC

anybody know a fix for that btw? slow processors and low RAM (yeah of course this is not the place for a OC qestion i know...)

Edited by Ta©ti_Tac0Z, 11 August 2018 - 09:27 AM.


#6 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 11 August 2018 - 09:14 AM

View PostKingofGamesYami, on 10 August 2018 - 08:37 PM, said:

1. You can only use the built in colors; however in later versions what those colors are can be changed on the fly. Example: http://www.computerc...s-a-great-idea/

ahhhh ok simpler that i thouth it was but if the funcalaity is there why can't we freely define colors like this...
i know its becuse of servers and its limitations right? but OC pulled it off?

at least let us define new colors

i mean it all is just stubit... the input that goes in term.setBackgroundColor IS a rgb value the problem is that only hard writen rgb values is allowed to be used! its just stubit! again i know the idea is that the color can be send as a single byte to the client on a server but... makeing it rgb will just add 2 extra bytes to the mix i know thats a lot for the biggest resolotion monitor but... can some body back me up here?

View PostKingofGamesYami, on 10 August 2018 - 08:37 PM, said:

2. No.

fuck well there goes that idea

#7 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 11 August 2018 - 09:19 AM

allso it sems that files is limited to 8bit per charector is this a commen limitation?

strings in CC is limit to 63 in binary witch was a pain to figere out is that common in lua or is that one more of for-some-reson laying-a-lot-of-power-into-servers thing again?

#8 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 11 August 2018 - 09:37 AM

View PostTa©ti_Tac0Z, on 11 August 2018 - 08:54 AM, said:

Anybody know a fix for that by the way? Slow processors and low RAM
There should be config options for most OC features, so you can bump the RAM limits for each tier. Alternatively just use Computronics' magical memory, though that is a creative-only item. As far as slow processors go, I believe there's some fixes for that in the works - these two PRs provide some substantial boosts.

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:19 AM, said:

Also it seems that files are limited to 8bit per character. Is this a common limitation?
Lua strings are effectively immutable byte arrays, and so each character represents one byte. It's possible to emulate unicode within Lua, though given CC doesn't draw it, there isn't much benefit.

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:19 AM, said:

strings in CC is limit to 63 in binary witch was a pain to figere out is that common in lua or is that one more of for-some-reson laying-a-lot-of-power-into-servers thing again?
I'm afraid I don't understand what you're saying here. Can you give an example or clarify?

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 August 2018 - 02:37 PM

After seeing OC running Windows (among other things), I have a hard time believing that it's all that limited.

That said, computers play videos that're larger than their RAM total all the time: it's simply a matter of continuously loading a bit of data from disk, playing it, and then discarding it. The entirety of the video doesn't have to reside all in RAM all at once.

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:19 AM, said:

strings in CC is limit to 63 in binary witch was a pain to figere out is that common in lua or is that one more of for-some-reson laying-a-lot-of-power-into-servers thing again?

If you attempt to run non-ASCII characters through a text mode file or web handle, or print them, older versions of ComputerCraft convert them to \63: a question mark.

In cases where these behaviours are an issue, it's generally best to either use binary mode instead of text mode, or if that's not available (you need CC1.80+ for binary mode web handles for eg), a binary-to-text encoding method such as base64.

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:14 AM, said:

the input that goes in term.setBackgroundColor IS a rgb value the problem is that only hard writen rgb values is allowed to be used!

Actually no, term.setBackgroundColor accepts indexes into ComputerCraft's sixteen colour palette, effectively rounding them off if you pass it any other numeric value. colours.orange doesn't actually hold a representation of the colour orange, for example - it merely holds a palette index.

And as mentioned, as of v1.80, you can redefine the colours within that palette.

#10 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 01:16 PM

View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

That said, computers play videos that're larger than their RAM total all the time: it's simply a matter of continuously loading a bit of data from disk, playing it, and then discarding it. The entirety of the video doesn't have to reside all in RAM all at once.



as i said the format is made by me and all bits are loaded at the same time (for now anyway) so indeed a computercraft computer is storeing a table with 270KB of data in side it in RAM

View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:19 AM, said:

strings in CC is limit to 63 in binary witch was a pain to figere out is that common in lua or is that one more of for-some-reson laying-a-lot-of-power-into-servers thing again?

If you attempt to run non-ASCII characters through a text mode file or web handle, or print them, older versions of ComputerCraft convert them to \63: a question mark.

In cases where these behaviours are an issue, it's generally best to either use binary mode instead of text mode, or if that's not available (you need CC1.80+ for binary mode web handles for eg), a binary-to-text encoding method such as base64.


yes thats why i use a table insted of a string now


View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

colours.orange doesn't actually hold a representation of the colour orange, for example - it merely holds a palette index.


wrong...:
Posted Image

the organges rgb color value is 2 (EDIT: not just the color index) as stated in the table: http://computercraft...ki/Colors_(API)


View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

And as mentioned, as of v1.80, you can redefine the colours within that palette.


as mentioned i said add not chance






View PostSquidDev, on 11 August 2018 - 09:37 AM, said:

View PostTa©ti_Tac0Z, on 11 August 2018 - 09:19 AM, said:

strings in CC is limit to 63 in binary witch was a pain to figere out is that common in lua or is that one more of for-some-reson laying-a-lot-of-power-into-servers thing again?
I'm afraid I don't understand what you're saying here. Can you give an example or clarify?
yeah just forget it

Edited by Ta©ti_Tac0Z, 12 August 2018 - 01:19 PM.


#11 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 01:27 PM

also now that i have you two anyways is there anyway of getting the secounts sence start with CC? the os.start() gives minecraft time witch is minor unuseable for most cases

View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

After seeing OC running Windows (among other things), I have a hard time believing that it's all that limited.


if you look closely you will be able to see some fligere and lag mainly becuse the speed of witch lua commands are run in OC is limited to the speed factor of the proccesor used

#12 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 01:33 PM

View PostSquidDev, on 11 August 2018 - 09:37 AM, said:

View PostTa©ti_Tac0Z, on 11 August 2018 - 08:54 AM, said:

Anybody know a fix for that by the way? Slow processors and low RAM
There should be config options for most OC features, so you can bump the RAM limits for each tier. Alternatively just use Computronics' magical memory, though that is a creative-only item. As far as slow processors go, I believe there's some fixes for that in the works - these two PRs provide some substantial boosts.

EDIT: i'm useing the magical ram yes

i may be stubit but the links... i don't really understand :D

Edited by Ta©ti_Tac0Z, 12 August 2018 - 01:34 PM.


#13 valithor

  • Members
  • 1,053 posts

Posted 12 August 2018 - 02:09 PM

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:27 PM, said:

also now that i have you two anyways is there anyway of getting the secounts sence start with CC? the os.start() gives minecraft time witch is minor unuseable for most cases

os.clock()
Returns the amount of time since the in-game computer was started.
http://www.computerc...o/wiki/Os.clock

#14 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 August 2018 - 03:25 PM

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:16 PM, said:


View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

colours.orange doesn't actually hold a representation of the colour orange, for example - it merely holds a palette index.


wrong...:
Posted Image

the organges rgb color value is 2 (EDIT: not just the color index) as stated in the table: http://computercraft...ki/Colors_(API)


You are mistaken. "2" is not an RGB value.

ComputerCraft uses binary indexes (2^0,2^1,2^2 ... 2^15). This is primarily to support passing multiple colors as one number to bundled cables. For example, to turn on blue and green you would pass 2^11 + 2^13, or 10,240 in base 10.

The RGB value of colors.orange is, by default, red 242, green 178, blue 51, as shown in the Display column of the table you reference.

#15 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 05:06 PM

View Postvalithor, on 12 August 2018 - 02:09 PM, said:

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:27 PM, said:

also now that i have you two anyways is there anyway of getting the secounts sence start with CC? the os.start() gives minecraft time witch is minor unuseable for most cases

os.clock()
Returns the amount of time since the in-game computer was started.
http://www.computerc...o/wiki/Os.clock

ahhh i seached for "time" (ctrl+f) in the os api overview but i some how didn't see os.clock, thanks

View PostKingofGamesYami, on 12 August 2018 - 03:25 PM, said:

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:16 PM, said:

View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

colours.orange doesn't actually hold a representation of the colour orange, for example - it merely holds a palette index.


wrong...:
Posted Image

the organges rgb color value is 2 (EDIT: not just the color index) as stated in the table: http://computercraft...ki/Colors_(API)


You are mistaken. "2" is not an RGB value.

ComputerCraft uses binary indexes (2^0,2^1,2^2 ... 2^15). This is primarily to support passing multiple colors as one number to bundled cables. For example, to turn on blue and green you would pass 2^11 + 2^13, or 10,240 in base 10.

The RGB value of colors.orange is, by default, red 242, green 178, blue 51, as shown in the Display column of the table you reference.

...
ohhhh well what do i saw? sorry bomb block, yeah it does make sence like that i see

View PostKingofGamesYami, on 12 August 2018 - 03:25 PM, said:



This is primarily to support passing multiple colors as one number to bundled cables. For example, to turn on blue and green you would pass 2^11 + 2^13


yeah there is a exable of that in the wiki i can't see the use for it tho, i mean why go throw so much truble so we can do that?


anyway i find it complitly absulete that the color chanceing functions uses these large numbers when it just makes them to the (0-15) way anyway, i know we can make bit oprations becuse of that but it still sems unesesary


if i took my time and looked at the table in just 60sec more i whould see the patten (0x0,0x01,0x001,0x001, ...) but my fingers typed before that ):

#16 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 11:36 PM

View PostBomb Bloke, on 11 August 2018 - 02:00 AM, said:

You can't get the hardware-based terminal to tell you what it's drawn, but you can write a software buffer with that capability, and then redirect all terminal output through that. For example, it would be fairly trivial to create a modified version of the window API that simply adds a few "get" functions for retrieving buffer contents.

am not a fan of editing apis and even less when they are build in
i surpose a nother way to do this is that the program witch need to get screen infomation is the one running the targeted program the problem i see with that is the fact the the term api is being redefined after makeing a new lua env. witch will overwrite any chances further then that as i know computercraft doesn't like the idea of you editing a api table at runtime like this do it?

i hate the idea of haveing a all most exact copy of the window api laying around, any other way of doing that?

the other way is to rewire the gfx functions such as:
function write(str)
  term.write(str)
  --add the text and the cord'ss to some global table
end

--and so on

but that whould be a pain and the method is no longer universal (given that a program need to be writen with this in mind)

if the rewirting of the window api is the only option (witch i hope it isn't) have some body done that and uploaded it some where (i don't know how the window api function or work, i nerver use it)

#17 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 13 August 2018 - 12:05 AM

"A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the term table"

so what you're telling me is that if i make a table of function witch works at the same way then that whould work

tho am running into a qestion

so if we say we make the function:
buffer = {}
T = {}
function buffer.write(str)
  T[#T + 1] = {str, term.getCursorPos(), etc...}
  term.write(str)
end

given that as i understand when a redirect is made all calls gets redirected to the buffer so whouldn't this try to run term.write for ever and make a infinet loop?

B = term
B.writeTerm = B.write
T = {}
print("fine 1")
function B.write(str)
	T[#T + 1] = str
	term.writeTerm(str)
end
print("fine2")
term.redirect(B)/>/>/>
print("fine3")
term.write("TEST! HALLO WOLRD!\n")
term.redirect(term.native())
print(#T, T[#T])

yeah there is that infintet loop i was talking about

EDIT: it sems that
buffer
is a global value used by the term api or some thing becuse the computer chashes when i use buffer insted of B

Edited by Ta©ti_Tac0Z, 13 August 2018 - 12:09 AM.


#18 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 August 2018 - 03:09 AM

View PostKingofGamesYami, on 12 August 2018 - 03:25 PM, said:

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:16 PM, said:

the organges rgb color value is 2

You are mistaken. "2" is not an RGB value.

Heh, well, it is, but it certainly doesn't come out to be orange. ;)

View PostTa©ti_Tac0Z, on 12 August 2018 - 05:06 PM, said:

View PostKingofGamesYami, on 12 August 2018 - 03:25 PM, said:

This is primarily to support passing multiple colors as one number to bundled cables. For example, to turn on blue and green you would pass 2^11 + 2^13

yeah there is a exable of that in the wiki i can't see the use for it tho, i mean why go throw so much truble so we can do that?

Bundled cables can be very useful! Being able to send up to sixteen different redstone signals through each block makes for much more compact builds, and they also allow a single ComputerCraft computer to send out many more redstone signals than it'd otherwise be able to.

If you're asking why the colour values are treated as bitflags, that's simply because it's by far the easiest way to do it. Any other method would be much more complex.

View PostTa©ti_Tac0Z, on 12 August 2018 - 11:36 PM, said:

the problem i see with that is the fact the the term api is being redefined after makeing a new lua env

No, it's not - the term API should contain the same function pointers from the moment a computer boots until the moment it shuts down.

When you use term.redirect(), you're changing the terminal object that the functions in the term table will work with in future, but those functions themselves remain the same. You can change your environment table all you like and it won't mess with that fact.

View PostTa©ti_Tac0Z, on 12 August 2018 - 11:36 PM, said:

i hate the idea of haveing a all most exact copy of the window api laying around, any other way of doing that?

I suppose you could write a "not" almost exact copy? Whatever you find fun. :)

View PostTa©ti_Tac0Z, on 13 August 2018 - 12:05 AM, said:

so what you're telling me is that if i make a table of function witch works at the same way then that whould work

Yes, that's exactly what window.create() makes for you, for example.

View PostTa©ti_Tac0Z, on 13 August 2018 - 12:05 AM, said:

given that as i understand when a redirect is made all calls gets redirected to the buffer so whouldn't this try to run term.write for ever and make a infinet loop?

If you did it like that, then yes, you'd have an infinite loop. So instead you might do:

local parentTerm = term.current() --# Record the terminal object currently in use.

local buffer = {}
local T = {}

function buffer.write(str)
  T[#T + 1] = {str, parentTerm.getCursorPos(), etc...}
  parentTerm.write(str)
end

In this case, the previous terminal object you were directing output to acts as a "parent" to the new terminal object you're constructing: the output gets recorded in T, and then displayed through the parent.

It's also important to note that the terminal you start off with probably won't actually be term.native(). When an advanced computer boots, it starts up multishell, which in turn uses window objects to manage tabs. Even if you only have one tab open (and hence don't have the multishell tab bar visible), that tab is still outputting its content through one of those windows.

RecGif has a ten line snippet that builds a "recording" terminal like the one you seem interested in, covering lines 65 to 75. This constructs one function in the recTerm table for every function in the oldTerm table (term.current(), which is again acting as a parent), each of which runs the equivalent parent function while recording in the curCalls table. After redirecting to the recTerm object, lines 86 to 117 run the script to be recorded in a special way that allows the addition of timing and user input information to be added to curCalls, and later in the script, the data recorded in curCalls is used to build a GIF animation.

Edited by Bomb Bloke, 13 August 2018 - 03:52 AM.


#19 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 13 August 2018 - 06:56 AM

this works!:
oldTerm = term.current()

recTerm = {}

T = {}

for key, func in pairs(oldTerm) do
	print(key) --os.pullEvent()
	os.sleep()
	if key == "write" or key == "clear" or key == "clearLine" then
	--if true then
		recTerm[key] = function(...)
			local result = {pcall(func, ...)}
	  
			if result[1] then
			--curCalls[callCount] = {key, ...}
			--callCount = callCount + 1
				local x,y = term.getCursorPos()
				local mainArg = ({...})[1]
				if mainArg == nil then mainArg = "nil" end
				T[#T + 1] = {key, mainArg, x,y, term.getBackgroundColor(), term.getTextColor()}
			  
				return unpack(result, 2)
			else error(result[2], 2) end
		end
	else
		recTerm[key] = func
	end
end


term.redirect(recTerm)

--record env. start

term.setCursorPos(1,1)
term.clear()
term.write("THIS WORKS!")
term.setCursorPos(1,2)
print("great with this infomation in hand i can easy do what i want")
os.sleep(3)
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
os.sleep(3)

term.clear()
--print(term.getCursorPos())

--record env. end

term.redirect(oldTerm)
print()
for key,value in ipairs(T) do
	os.sleep(1.5)
	print(key)
	print("  command: "..value[1])
	print("  text: "..value[2])
	print("  cursor: x: "..value[3]..", y: "..value[4])
	print("  background color: "..value[5])
	print("  text color: "..value[6])
	--for key2,value2 in ipairs(value) do
	--	print("  "..tostring(value2))
	--end
end

thanks!

#20 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 17 August 2018 - 02:46 PM

View PostTa©ti_Tac0Z, on 12 August 2018 - 01:27 PM, said:

also now that i have you two anyways is there anyway of getting the secounts sence start with CC? the os.start() gives minecraft time witch is minor unuseable for most cases

View PostBomb Bloke, on 11 August 2018 - 02:37 PM, said:

After seeing OC running Windows (among other things), I have a hard time believing that it's all that limited.


if you look closely you will be able to see some fligere and lag mainly becuse the speed of witch lua commands are run in OC is limited to the speed factor of the proccesor used

a guy on the opencomputers forum explained that only one compunent call is allowed per tick meaning that the terminal in OC is limited to 4 updates/calls per sec! good bye OC ):
that is game breaking ):





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users