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

[ERROR] startup:23: attempt to call string

Started by ComputerCraftFan11, 01 April 2012 - 12:16 AM
ComputerCraftFan11 #1
Posted 01 April 2012 - 02:16 AM

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = "blank";
function blank()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function run(runn31er)
runn31er()
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
	running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw()
term.clear()
drawButtons()
run(running)
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw()
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw()
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw()
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw()
elseif key == 28 then
  pressed = true;
  reDraw()
  sleep(0.0001)
  pressed = false;
end
end

I'm getting a attempt to call string error at line 23 (shown below)

function run(runn31er)
runn31er()
end
I don't have a function called runn31er() but it's supposed to run what you want it to run. For example:


function derp()
print("Hi")
end

run(derp)

Will print "Hi"
cant_delete_account #2
Posted 01 April 2012 - 02:32 AM
Nope, you're getting an error at write(title), there is no string called 'title'.
Advert #3
Posted 01 April 2012 - 02:34 AM
Also, running is set to a string defined as "blank".
You also don't need to do what you're doing, you can simply do this:


iReturnAFunction("stuff")() -- will call the result of iReturnAFunction
tbl[1]() -- will call element 1 of the table
ComputerCraftFan11 #4
Posted 01 April 2012 - 02:56 AM
Also, running is set to a string defined as "blank".
You also don't need to do what you're doing, you can simply do this:


iReturnAFunction("stuff")() -- will call the result of iReturnAFunction
tbl[1]() -- will call element 1 of the table

Startup:23: attempt to cal nil

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = "blank";
function blank()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function run(runn31er)
iReturnAFunction(running)() -- will call the result of iReturnAFunction
tbl[1]() -- will call element 1 of the table
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
    running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw()
term.clear()
drawButtons()
run(running)
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw()
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw()
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw()
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw()
elseif key == 28 then
  pressed = true;
  reDraw()
  sleep(0.0001)
  pressed = false;
end
end
Nope, you're getting an error at write(title), there is no string called 'title'.

Title is defined as one of the perimeters in the function.

like this:


function a(title)
  write(title)
end

a("fart")

will write "fart"
Advert #5
Posted 01 April 2012 - 03:10 AM
That was an example; you need to substitute your stuff in.
ComputerCraftFan11 #6
Posted 01 April 2012 - 03:15 AM
That was an example; you need to substitute your stuff in.

I changed it to

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = "blank";
function blank()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
    running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw()
term.clear()
drawButtons()
running()
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw()
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw()
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw()
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw()
elseif key == 28 then
  pressed = true;
  reDraw()
  sleep(0.0001)
  pressed = false;
end
end

And im getting the same error.

I'm just gonna change it to shell.run…
Advert #7
Posted 01 April 2012 - 03:25 AM
That was an example; you need to substitute your stuff in.

I changed it to

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = "blank";
function blank()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
	running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw()
term.clear()
drawButtons()
running()
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw()
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw()
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw()
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw()
elseif key == 28 then
  pressed = true;
  reDraw()
  sleep(0.0001)
  pressed = false;
end
end

And im getting the same error.

I'm just gonna change it to shell.run…

You still haven't fixed that running is a string.
ComputerCraftFan11 #8
Posted 01 April 2012 - 03:31 AM
That was an example; you need to substitute your stuff in.

I changed it to

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = "blank";
function blank()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
	running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw()
term.clear()
drawButtons()
running()
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw()
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw()
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw()
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw()
elseif key == 28 then
  pressed = true;
  reDraw()
  sleep(0.0001)
  pressed = false;
end
end

And im getting the same error.

I'm just gonna change it to shell.run…

You still haven't fixed that running is a string.

I'm not getting a error now but now its not running the function start()

(If i ran a function with quotes it didnt work)

local x, y = term.getSize()
local currentX = 1;
local currentY = 1;
local Cursor = ">";
local pressed = false;
local running = running;
if not fs.exists("windows") then
fs.makeDir("windows")
fs.makeDir("windows/programs")
end
function running()
end
function start()
newLine(1, x-10, "----------+")
newLine(11, x-9, "|")
newLine(11, x-8, "|")
newLine(11, x-7, "|")
newLine(11, x-6, "|")
newLine(11, x-5, "|")
newLine(11, x-4, "|")
newLine(11, x-3, "|")
end
function newButton(x1, y1, title, do22)
term.setCursorPos(x1+1, y1)
write(title)
if pressed == true then
  if currentX == x1 then
   if currentY == y1 then
    running = do22
   end
  end
end
end
function newLine(x1, y1, title)
term.setCursorPos(x1, y1)
if title == "stretch" then
  print("--------------------------------------------------")
else
  write(title)
end
end
function drawButtons()
newLine(1, y-1, "stretch")
newButton(1, y, "Start", start)
end

function reDraw(derp)
term.clear()
drawButtons()
derp()
term.setCursorPos(currentX, currentY)
write(Cursor)
end
while true do
reDraw(running)
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then --up
  currentY = currentY -1
  reDraw(running)
elseif key == 31 or key == 208 then --down
  currentY = currentY +1
  reDraw(running)
elseif key == 203 or key == 30 then --left
  currentX = currentX -1
  reDraw(running)
elseif key == 205 or key == 32 then --right
  currentX = currentX +1
  reDraw(running)
elseif key == 28 then
  pressed = true;
  reDraw(running)
  sleep(0.0001)
  pressed = false;
end
end
Hawk777 #9
Posted 01 April 2012 - 07:01 AM
That’s because you never [em]tell[/em] it to run the function “start”. The name isn’t magic. Put this at the end of your code:


start()

if you want to run the function.
ComputerCraftFan11 #10
Posted 01 April 2012 - 07:41 AM
That’s because you never [em]tell[/em] it to run the function “start”. The name isn’t magic. Put this at the end of your code:


start()

if you want to run the function.

Well I fixed the code, made start (the start menu) work, and add just about everything to make it look exactly like Windows OS

I also added:

if running == "start" then
  start()
else
 shell.run(running)
end