This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Emma's profile picture

ArrayIndexOutOfBoundsException

Started by Emma, 15 August 2014 - 05:09 PM
Emma #1
Posted 15 August 2014 - 07:09 PM
Hi, I'm making a joke os, but I ran into a hiccup. Its explained in this video: [media]http://www.youtube.com/watch?v=orJkw5eWU2w[/media]
Weirdest thing
Colors API : pastebin.com/y7i7vcX6
Desktop : pastebin.com/f39PmjAU
Edited on 15 August 2014 - 05:11 PM
MKlegoman357 #2
Posted 15 August 2014 - 08:32 PM
Because of how the term API works you should never directly overwrite term.*. Why? Well, because strange things start to happen. Basically, when the computer starts, it automatically loads a Lua API called "term". In that API the real "term" API gets overwritten for the purpose of redirection, not the game "Redirection", but term.redirect. Currently, redirection works in a way that even when you redirect to something, the term.* functions, as Lua functions, don't change. In that Lua-side "term" API all term functions get overwritten with functions which calls specific functions from the current redirect target, so calling term.* calls currentRedirectTarget.*. When you overwrite term.* directly, you remove those functions, so they are not able to call functions from redirect object.

To avoid this problem, instead of overwriting term.* you should simply make a redirect object, with modified functions, and redirect to that.

Also, don't bump a topic when it has only been here for one hour, bumping after 1-2 days in my opinion is OK though. Remember that there aren't people sitting here, waiting for someone to ask something 24/7 and sometimes the question you might have can be too difficult to answer for a lot of people and, because of that, sometimes you might not get an answer.
Emma #3
Posted 17 August 2014 - 12:10 AM
Because of how the term API works you should never directly overwrite term.*. Why? Well, because strange things start to happen. Basically, when the computer starts, it automatically loads a Lua API called "term". In that API the real "term" API gets overwritten for the purpose of redirection, not the game "Redirection", but term.redirect. Currently, redirection works in a way that even when you redirect to something, the term.* functions, as Lua functions, don't change. In that Lua-side "term" API all term functions get overwritten with functions which calls specific functions from the current redirect target, so calling term.* calls currentRedirectTarget.*. When you overwrite term.* directly, you remove those functions, so they are not able to call functions from redirect object.

To avoid this problem, instead of overwriting term.* you should simply make a redirect object, with modified functions, and redirect to that.

Also, don't bump a topic when it has only been here for one hour, bumping after 1-2 days in my opinion is OK though. Remember that there aren't people sitting here, waiting for someone to ask something 24/7 and sometimes the question you might have can be too difficult to answer for a lot of people and, because of that, sometimes you might not get an answer.

Ok thanks! :)/>
EDIT: I tried what you said and I'm still getting the error :/ except, now it errors upon loading the api instead of later on, new colors api: kKKNca2J
Edited on 16 August 2014 - 10:20 PM
MKlegoman357 #4
Posted 17 August 2014 - 12:36 AM
You forgot the first argument for window.new, read on the wiki ;)/>. Also, I would highly suggest not to use the window API because it is very unoptimized and lags a lot. For your use case, I would make something like this:


local current = term.current()
local redirect = {}

textColor = colors.white

redirect.setTextColor = function (c)
  textColor = c
  current.setTextColor(c)
end

setmetatable(redirect, {__index = current})

term.redirect(redirect)
Emma #5
Posted 17 August 2014 - 12:55 AM
You forgot the first argument for window.new, read on the wiki ;)/>. Also, I would highly suggest not to use the window API because it is very unoptimized and lags a lot. For your use case, I would make something like this:


local current = term.current()
local redirect = {}

textColor = colors.white

redirect.setTextColor = function (c)
  textColor = c
  current.setTextColor(c)
end

setmetatable(redirect, {__index = current})

term.redirect(redirect)

Ok thanks, and btw I found the real source of the cause of the error, one of the admins on the server is doing some weird stuff with disk.setLabel and overwriting it and yeah. But thanks anyways!
Emma #6
Posted 17 August 2014 - 01:07 AM
So I made the fix, and now I'm getting something weird, that shouldn't happen :P/>
bios:220:Attempt to call nil
Upon loading of the api, now I looked at the line at I'm not understanding it

function printError( ... )
    if term.isColour() then
        term.setTextColour( colours.red )  --Line 220
    end
    print( ... )
    term.setTextColour( colours.white )
end
MKlegoman357 #7
Posted 17 August 2014 - 11:47 AM
As you can see, term.setTextColour is equal to nil, you must've overwritten (or forgot to overwrite) it somewhere.

EDIT: could you post your current code?
Edited on 17 August 2014 - 09:52 AM
Emma #8
Posted 17 August 2014 - 04:05 PM
Ypf7a31G << My current code
MKlegoman357 #9
Posted 17 August 2014 - 09:51 PM

local terminal = {}

...

local oSB=terminal.setBackgroundColor
local oST=terminal.setTextColor

Do you see the problem there?
MKlegoman357 #10
Posted 17 August 2014 - 09:56 PM
Also, you would want to add getTextColor and getBackgroundColor functions into the term table, because you won't be able to do "term.getTextColor()".