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

[Lua][Error]Edit:118: attempt to call string[Solved]

Started by BlackMenthol, 09 February 2013 - 12:55 AM
BlackMenthol #1
Posted 09 February 2013 - 01:55 AM
Hi. Sorry for my english, just in case.
I wrote a script for my bee analyzer to separate pure bee from hybrid ones, print the result on a screen and save the data on a txt file.
this is it: http://pastebin.com/YaFh5vfP

Probably is not the best script (i'm still learning) but it runs fine and does what is supposed to do, but everytime I terminate it and try to type "edit startup" to make some modification i got an error message:
"Edit:118: attemp to call a string". It's not a big deal actually, i can solve the problem rebooting my turtle and editing before running the program, but I was wondering the reason of this behaviour. It seems to give the error only after actually analyzing the bees (from line 70 to line 79). Oh, for everyone who doesn't know how the bee analyzer works, analyze() returns a table with every info about the analyzed bee (the "a" peripheral is the bee analyzer).

I checked the edit program script and line 118 is in this function:

local function tryWrite( sLine, regex, colour )
local match = string.match( sLine, regex )
if match then
if type(colour) == "number" then <————- line 118
term.setTextColour( colour )
else
term.setTextColour( colour(match) )
end
term.write( match )
term.setTextColour( textColour )
return string.sub( sLine, string.len(match) + 1 )
end
return nil
end

Again is not the biggest deal, but can someone help me figure it out?
Am I using some no-no name for my variables or tables?

thanks :P/>/>
Lyqyd #2
Posted 09 February 2013 - 04:54 AM
Split into new topic.

You're overriding the global "type" from a function (which gives the type of its parameter) to a string in your program. Change all instances of "type" that aren't in tables to use "beeType", or use correct local scoping.
BlackMenthol #3
Posted 09 February 2013 - 11:17 PM
Split into new topic.

You're overriding the global "type" from a function (which gives the type of its parameter) to a string in your program. Change all instances of "type" that aren't in tables to use "beeType", or use correct local scoping.

Oh it worked.

thanks for your time :)/>