This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
bios:267: error
Started by crimsonknight3, 24 March 2012 - 07:28 PMPosted 24 March 2012 - 08:28 PM
Ive been trying to learn lua so ive been getting help to write a simple building building program. However after sorting out the kinks im getting the bios:267: Attempt to write to global error and i dont understand what the error is for
Posted 24 March 2012 - 08:33 PM
post your code
Posted 24 March 2012 - 08:44 PM
Here it is. Now im getting an attempt to call nil error
--place Building material in slot 1, place glass in slot 2, place building material in slot 3
Print('starting building')
function turtle.up()
while not turtle.up() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placeDown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placeDown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placeDown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
-- Ten
function turtle.turnright()
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(2) > 0 then
turtle.placedown(2)
break
else
print('Need more Glass!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(2) > 0 then
turtle.placedown(2)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(2) > 0 then
turtle.placedown(2)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(2) > 0 then
turtle.placedown(2)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
function turtle.forward()
while not turtle.forward() do end
end
function turtle.placeDown()
while true do
if turtle.getItemCount(1) > 0 then
turtle.placedown(1)
break
else
print('Need more materials!')
os.pullEvent()
end
end
end
--Twenty
Posted 24 March 2012 - 08:54 PM
Line 2: There is no function called "Print(text)", but there is one called "print(text)".
Rest: You should use "turtle.someAction()", not "function turtle.someAction() something() turtle.someAction() something() end".
Rest: You should use "turtle.someAction()", not "function turtle.someAction() something() turtle.someAction() something() end".
Posted 24 March 2012 - 09:08 PM
This is the advice i got which makes sense :(/>/>
Also, after sorting the print bit i still get the bios:267: attempt to write to global
And then you use these functions instead of the default ones. There's nothing stopping a turtle from turning around on it's axis, so you can use the standard functions for turning. The last thing you need to make sure of is that the turtle has materials left in it's inventory. Simply call [b]turtle.getItemCount([i]slotnum[/i])[/b] for the slot that contains the material you want to place before it is placed. Put this in a wrapper function
You can make a similar functions for placing blocks up and down. And that's it. Just make a list of orders for moving and placing out of these function and the turtle will follow it until completion.
Also, after sorting the print bit i still get the bios:267: attempt to write to global
Posted 24 March 2012 - 09:49 PM
Fixed and compacted :(/>/>:
function fwd()
ok = false
while not ok do
ok = turtle.forward()
print("...")
end
end
function pd()
if turtle.getItemCount(1) > 0 then
turtle.placeDown()
else
print("No materials.")
end
end
for i=1, 20 do
fwd()
pd()
end
Posted 26 March 2012 - 03:29 PM
Will give it a test now and see how i get on :o/>/> though i understand the rest, could you explain the i=1, 20 do part?
Posted 26 March 2012 - 03:38 PM
Okay i've got the code below, and i just get a java lang array out of bounds exception when trying to run.
[edit] tried removing the turtle.select() from your original code and i still get the java array error. Could it be because im using notepad++ and saving it as its lua sorce file which is build.lua?
[edit] tried removing the turtle.select() from your original code and i still get the java array error. Could it be because im using notepad++ and saving it as its lua sorce file which is build.lua?
function fwd()
ok = false
while not ok do
ok = turtle.forward()
print("...")
end
end
turtle.select()
function pd()
if turtle.getItemCount(1) > 0
then turtle.placeDown()
else print("No materials.")
end
end
for i=1, 20 do
fwd()
pd()
end
Posted 26 March 2012 - 03:53 PM
turtle.select(1)
turtle.select(9)
Need's an argument.
turtle.select(9)
Need's an argument.
Posted 26 March 2012 - 06:00 PM
The
for i=1, 20
part is a "for" loop. It loops 20 times, each time increasing the value of the "i" variable.Posted 26 March 2012 - 08:52 PM
Ahh now i understand :o/>/> and turtle.select was my mistake haha OMG i have movement!!! hahaha >.> Thank you so much for the help :o/>/> I've learnt to understand some errors and understand practical application :)/>/> Now to expand and complete the building :)/>/> Will post it when im done (tomorrow or the next day)
Posted 26 March 2012 - 09:26 PM
Is there a way of condensing this?
Im doing a building which has indented corners at each 4 corners… Like a 'w' kinda shape. I was looking at the 'for' command but as the turtle has to go left forward right forward left forward right forward left, i couldn't see a way to do the left/right/left etc
Im doing a building which has indented corners at each 4 corners… Like a 'w' kinda shape. I was looking at the 'for' command but as the turtle has to go left forward right forward left forward right forward left, i couldn't see a way to do the left/right/left etc
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
Posted 26 March 2012 - 09:36 PM
Is there a way of condensing this?
Im doing a building which has indented corners at each 4 corners… Like a 'w' kinda shape. I was looking at the 'for' command but as the turtle has to go left forward right forward left forward right forward left, i couldn't see a way to do the left/right/left etcfunction placeLeft() turtle.turnLeft() turtle.forward() turtle.placeDown() end function placeRight() turtle.turnRight() turtle.forward() turtle.placeDown() end placeLeft() placeRight() placeLeft() placeRight() turtle.turnLeft()
Posted 26 March 2012 - 10:59 PM
You can use a boolean variable in a loop. If the variable == true then you go right, else you go left. And after that you set the variable to the opposite.
Like this:
Or you can just do this:
Like this:
for i=1, 10 do
if b then
turtle.turnLeft()
else
turtle.turnRight()
end
turtle.forward()
turtle.placeDown()
b = not b
end
You can also set how many times you want to turn (left + right). :o/>/>Or you can just do this:
for i=1, 10 do
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.foward()
turtle.placeDown()
But if you are coding a big program, the first way makes the program shorter.Posted 26 March 2012 - 11:03 PM
Wow thanks :o/>/> Will implement this tomorrow. Got it correctly placing a wall 4 high and started on a ceiling. Running out of slots for resources haha might have made it a tiddle too big >.> Is just a house for my gf to try on her mc and tease her into learning a little lua >.> Thank you for all your help :o/>/>
Posted 26 March 2012 - 11:06 PM
Use buildcraft pipes/redpower tubes :o/>/>
Posted 27 March 2012 - 09:08 AM
Use buildcraft pipes/redpower tubes :o/>/>
How? If the turtle is moving you won't be able to get items into it fast enough? I do use both redpower and buildcraft. (yes making her a house as a blueprint would be easier but using a turtle you can make the same building out of whatever materials you fancy :o/>/> )
also i had another question about lua. If your using if, then, else end, is it possible to have else do 2 things? If so would you do 2 separate else's?
I would like this to automatically switch to a new slot when it runs out: (related to this, for the corners if i did for i=1, 2 do, how could i integrate the same as if tutrtle.getItemCount() that way i wont have to count the exact amount of blocks the turtle has placed before i do turtle.select to change the slot) i decided to use the i=1, 2 do as i understand it better but also because i'll end up with MORE code doing it the first way, as i will be placing windows in which means chopping up bits of code to insert windows among the main building material. Im coding the entire building to begin with, then ill go BACK over the code and cut it up to insert extra bits of code set to a different slot. Will simply be 8 slots building material, 1 slot window panes or glass blocks :)/>/>
function pd()
if turtle.getItemCount(1) > 0
then turtle.placeDown()
else print("No materials.")
end
end
for i=1, 16 do
fwd()
pd()
end
Posted 27 March 2012 - 10:05 AM
For the i=1, 10 do, i get an attempt to call nil after the first turnright forward placedown turnleft error. Will try your other suggestion.
Tried the other suggestion and works a treat. Sorry to keep pounding out questions, every time i do a little coding and experimenting it brings up more questions.
For this, is it possible to make the turtle wait if the item count isn't higher than 18? Then carry on when the item count in the selected slot is equal to 64? Similar to the question above about having multiple things happen if the if is false.
Tried the other suggestion and works a treat. Sorry to keep pounding out questions, every time i do a little coding and experimenting it brings up more questions.
For this, is it possible to make the turtle wait if the item count isn't higher than 18? Then carry on when the item count in the selected slot is equal to 64? Similar to the question above about having multiple things happen if the if is false.
[color=#000000]function pd()
if turtle.getItemCount(6) > 18
then turtle.placeDown()
else print("No materials.")
end
end[/color]
Posted 27 March 2012 - 03:08 PM
To wait for items, use:
You can connect redpower tubes so the turtle builds, comes back, takes items and continues to build.
You can make it switch slot by using:
You can't use
But you can use this:
while turtle.getItemCount(slot) < 18 do
sleep(1)
end
This code makes it wait until there are 18 or more items in the slot.You can connect redpower tubes so the turtle builds, comes back, takes items and continues to build.
You can make it switch slot by using:
currentSlot = 1
function pd()
if turtle.getItemCount(currentSlot) > 0 then
turtle.placeDown()
else
if currentSlot < 9 then
currentSlot = currentSlot + 1
print("Selecting slot #"..currentSlot..".")
turtle.select(currentSlot)
else
print("No materials.")
end
end
for i=1, 100 do
pd()
turtle.forward()
end
This code makes the turtle place 100 blocks in a straight line :o/>/> and when there are no items in slot 1, it uses slot 2.You can't use
if something then
print("Something")
else
print("Something else")
else
print("This stops the program from working.")
end
That gives an error (no end).But you can use this:
if something then
print("Something")
elseif somethingElse then
print("Something else.")
else
print("...")
end
or
if something then
print("Something")
else
if somethingElse then
print("Something else!")
end -- You can use else here
print("...") --This will always print if something is false.
end