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

Startup:39 Attempt To Index ? (A Nil Value) When That Value Is Initialized

Started by makerimages, 06 August 2013 - 01:03 AM
makerimages #1
Posted 06 August 2013 - 03:03 AM
Hi, I wrote a small api for my soon-to-be-revealed OS, this handles dialogueboxes, the api code is:


--Developed by Makerimages
--the internal dialogue box instance
local dialogueBox=nil;
os.loadAPI("/apis/gameutils")
local w,h=term.getSize();
local backGround=gameutils.loadSprite("/graphics/dialogueBack.nfp",math.ceil(w/2),math.ceil(h/2));

--[[ Creates a new, blank dialogue box with the set title and text.

]]--
function createDialogueBox(title,text)

dialogueBox=
{
  title=title;
  text=text;
}
end
--[[
Creates a new, blank dialogue box that has a loading bar;
]]--
function createDialogueBoxWithLoadBar(title, text)

  dialogueBox=
  {
   title=title;
   text=text;
   loadingBar=gameutils.gameutils.loadAnimation("/graphics/LoadingBar.nfa",math.ceil(w/2-3),math.ceil(h/2));
	 }

end
function drawDialogueBox(dialogueBoxToDraw)

  gameutils.initializeBuffer()
  gameutils.writeToBuffer(backGround)
  gameutils.drawBuffer()
  term.setTextColor(colors.lightGray)
  term.setCursorPos(math.ceil(w/2),math.ceil(h/2-5));
  print(dialogueBoxToDraw.title);
  term.setCursorPos(math.ceil(w/2),math.ceil(h/2-3));
  print(dialogueBoxToDraw.text)
end
the startup code is

--Developed by Makerimages
os.loadAPI("/apis/gameutils");--Load the animation api by NitrogenFingers
os.loadAPI("/apis/dialoguehandler")
term.setTextColor(colors.lightGray)
local topBar=gameutils.loadSprite("/graphics/TopBar.nfp",1,1);--top bar
local w, h=term.getSize();
local loadBar=gameutils.loadAnimation("/graphics/LoadingBar.nfa",math.ceil(w/2-3),math.ceil(h/2));--loading bar
local backGround=gameutils.loadSprite("/graphics/b.nfp",1,1)--background
local dBox=dialoguehandler.createDialogueBox("Booting","OS One is booting...")
local addAccountButton=
{
text="+ Add an account";
x=math.ceil(w/2-5);
y=math.ceil(h/2);
w=16;
h=1;
}
loadBar.currentFrame=1;
gameutils.initializeBuffer();
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);
gameutils.writeToBuffer(loadBar);
gameutils.drawBuffer();
while loadBar.currentFrame<=10 do
loadBar:next();
sleep(0.15)
gameutils.writeToBuffer(loadBar);
gameutils.drawBuffer();
dBox.drawDialogueBox(self);
end
if fs.exists("userData/user1.uData") then
shell.run("/OSCore/loginScreen.lua")
else
gameutils.clearBuffer()
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);
while true do
gameutils.drawBuffer();
term.setCursorPos(1,math.ceil(h/2-5))
print("OS One has identified that you do not have an admininstrative user Account set up yet. Please do so now.")
term.setCursorPos(addAccountButton.x, addAccountButton.y)
write("|")write(addAccountButton.text)write("|")
  event, button, x, y = os.pullEvent("mouse_click")
   if x >= addAccountButton.x and x <= addAccountButton.x + addAccountButton.w - 1 and
	y >= addAccountButton.y and y < addAccountButton.y + addAccountButton.h then
   os.reboot()
  end
sleep(0.15)
end
end

the line that causes the error startup:39 attempt to index ? (a nil value)
is

dBox.drawDialogueBox(self);
makerimages #2
Posted 06 August 2013 - 03:24 AM
update: go tt the box to draw, but now it says the sme error with new line nrs when it tries to print the title and text

startup:

--Developed by Makerimages
os.loadAPI("/apis/gameutils");--Load the animation api by NitrogenFingers
os.loadAPI("/apis/dialoguehandler")
term.setTextColor(colors.lightGray)
local topBar=gameutils.loadSprite("/graphics/TopBar.nfp",1,1);--top bar
local w, h=term.getSize();
local loadBar=gameutils.loadAnimation("/graphics/LoadingBar.nfa",math.ceil(w/2-3),math.ceil(h/2));--loading bar
local backGround=gameutils.loadSprite("/graphics/b.nfp",1,1)--background
local dBox=dialoguehandler.createDialogueBox("Booting","OS One is booting...")
local addAccountButton=
{
text="+ Add an account";
x=math.ceil(w/2-5);
y=math.ceil(h/2);
w=16;
h=1;
}
loadBar.currentFrame=1;
gameutils.initializeBuffer();
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);
gameutils.writeToBuffer(loadBar);
gameutils.drawBuffer();
while loadBar.currentFrame<=10 do
loadBar:next();
sleep(0.15)
gameutils.writeToBuffer(loadBar);
gameutils.drawBuffer();
dialoguehandler.drawDialogueBox(dBox);
end
if fs.exists("userData/user1.uData") then
shell.run("/OSCore/loginScreen.lua")
else
gameutils.clearBuffer()
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);
while true do
gameutils.drawBuffer();
term.setCursorPos(1,math.ceil(h/2-5))
print("OS One has identified that you do not have an admininstrative user Account set up yet. Please do so now.")
term.setCursorPos(addAccountButton.x, addAccountButton.y)
write("|")write(addAccountButton.text)write("|")
  event, button, x, y = os.pullEvent("mouse_click")
   if x >= addAccountButton.x and x <= addAccountButton.x + addAccountButton.w - 1 and
    y >= addAccountButton.y and y < addAccountButton.y + addAccountButton.h then
   os.reboot()
  end
sleep(0.15)
end
end

api is the same
Zudo #3
Posted 06 August 2013 - 03:41 AM
Where do you get the error in the new code?
immibis #4
Posted 06 August 2013 - 03:46 AM

local dBox=dialoguehandler.createDialogueBox("Booting","OS One is booting...")

function createDialogueBox(title,text)
  dialogueBox=
  {
    title=title;
    text=text;
  }
end
Notice how createDialogueBox doesn't return anything.
makerimages #5
Posted 06 August 2013 - 04:00 AM
oh crap, what should it return? dialogueBox?
immibis #6
Posted 06 August 2013 - 05:21 PM
If that's what you want it to return.
GamerNebulae #7
Posted 06 August 2013 - 07:04 PM
Question: why are there ';' at the end of some lines? I know it means the end of a line in C#, but what is the function of that in CraftOS?
makerimages #8
Posted 07 August 2013 - 01:23 AM
none, its just a habit from coding java as my main programming language.

ahem, more issues.

api

--Developed by Makerimages
--the internal dialogue box instance
local dialogueBox=nil;
os.loadAPI("/apis/gameutils")
local w,h=term.getSize();
local backGround=gameutils.loadSprite("/graphics/dialogueBack.nfp",math.ceil(w/2-13),math.ceil(h/2-5));

--[[ Creates a new, blank dialogue box with the set title and text.

]]--
function createDialogueBox(title,text)

dialogueBox=
{
  title=title;
  text=text;
}
return dialogueBox
end
--[[
Creates a new, blank dialogue box that has a loading bar;
]]--
function createDialogueBoxWithLoadBar(title, text)

  dialogueBox=
  {
   title=title;
   text=text;
   loadingBar=gameutils.loadAnimation("/graphics/LoadingBar.nfa",math.ceil(w/2-3),math.ceil(h/2));
	 }
	 dialogueBox.loadingBar.currentFrame=1;
	 return dialogueBox
end
function drawDialogueBox(dialogueBoxToDraw)

  gameutils.initializeBuffer()
  gameutils.writeToBuffer(backGround)
  --gameutils.drawBuffer()
  term.setTextColor(colors.gray)
  term.setCursorPos(math.ceil(w/2-2),math.ceil(h/2-5));
  print(dialogueBoxToDraw.title);
  term.setBackgroundColor(colors.white);
  term.setCursorPos(math.ceil(w/2-11),math.ceil(h/2-3));
  print(dialogueBoxToDraw.text)
  if not dialogueBoxToDraw.loadingBar==nil then
   gameutils.writeToBuffer(dialogueBox.loadingBar)
   end
  while dialogueBoxToDraw.loadingBar.currentFrame<=10 do
   dialogueBoxToDraw.loadingBar:next()
   sleep(0.15)
   gameutils.writeToBuffer(dialogueBoxToDraw.loadingBar)
   gameutils.writeToBuffer(backGround)
   gameutils.drawBuffer();
   term.setTextColor(colors.gray)
   term.setCursorPos(math.ceil(w/2-2),math.ceil(h/2-5));
   print(dialogueBoxToDraw.title);
	 term.setBackgroundColor(colors.white);
   term.setCursorPos(math.ceil(w/2-11),math.ceil(h/2-3));
   print(dialogueBoxToDraw.text)
  end
shell.run(dialogueBoxToDraw.endFunction)

end

function addLoadingBarEndFunctionGoTo(dialogueBoxToAddTo,functionTo)
dialogueBoxToAddTo.endFunction=functionTo;
return dialogueBoxToAddTo
end

startup

--Developed by Makerimages
os.loadAPI("/apis/gameutils");--Load the animation api by NitrogenFingers
os.loadAPI("/apis/dialoguehandler")
term.setTextColor(colors.lightGray)
local topBar=gameutils.loadSprite("/graphics/TopBar.nfp",1,1);--top bar
local w, h=term.getSize();
local backGround=gameutils.loadSprite("/graphics/b.nfp",1,1)--background
local dBox=dialoguehandler.createDialogueBoxWithLoadBar("Booting","OS One is booting...")
local addAccountButton=
{
text="+ Add an account";
x=math.ceil(w/2-5);
y=math.ceil(h/2);
w=16;
h=1;
}

gameutils.initializeBuffer();
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);

gameutils.drawBuffer();
dialoguehandler.addLoadingBarEndFunctionGoTo(dBox,"id");
dialoguehandler.drawDialogueBox(dBox);
--[[
if fs.exists("userDd
ata/user1.uData") then
shell.run("/OSCore/loginScreen.lua")
else
gameutils.clearBuffer()
gameutils.writeToBuffer(backGround)
gameutils.writeToBuffer(topBar);
while true do
gameutils.drawBuffer();
term.setCursorPos(1,math.ceil(h/2-5))
print("OS One has identified that you do not have an admininstrative user Account set up yet. Please do so now.")
term.setCursorPos(addAccountButton.x, addAccountButton.y)
write("|")write(addAccountButton.text)write("|")
  event, button, x, y = os.pullEvent("mouse_click")
   if x >= addAccountButton.x and x <= addAccountButton.x + addAccountButton.w - 1 and
    y >= addAccountButton.y and y < addAccountButton.y + addAccountButton.h then
   os.reboot()
  end
sleep(0.15)
end
end
]]--

trying to move the running of code when loading bar is at frame 10 into the api, problems that I have:

When the box is drawn I get an error at line 69 of the api

shell.run(dialogueBoxToDraw.endFunction)
saying that it is trying to index ? (a nil value)

I dont see the loading bar in the box
makerimages #9
Posted 08 August 2013 - 03:42 AM
Any1?
immibis #10
Posted 08 August 2013 - 03:59 AM
APIs can't access shell.
makerimages #11
Posted 08 August 2013 - 04:03 AM
any way to work around that?