Jump to content




[Error][Lua] = Expected but not really..


  • You cannot reply to this topic
12 replies to this topic

#1 TechManDylan

  • Members
  • 9 posts

Posted 28 March 2013 - 04:00 PM

Posted Image
Code
if turtle.getFuelLevel() < 1000 then
		turtle.select(16)
		turtle.refuel(64)
end
function refillMaterials()  
   slot = 1
  repeat
   if turtle.getItemCount(slot) < 1 then
   slot = slot + 1
   turtle.select(slot)
   end
  until
   slot == 17
   slot = slot - 16
   noMaterials()
end
function noMaterials()
term.clear
term.setCursorPos(1,1)
print("Out of materials please bring me more")
	print("press any key to continue...")
	event1, param1 = os.pullEvent()
refillMaterials()
end
function placeBlock( times )
   for i = 1, times do
  turtle.placeDown()
		turtle.forward()
	end
end
function Corner()
	turtle.turnRight()
	turtle.forward()
	turtle.turnLeft()
placeBlock(2)
turtle.turnRight()
	turtle.forward()
	turtle.turnLeft()
placeBlock(1)
turtle.turnRight()
turtle.forward()
placeBlock(2)
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
function buildLayer()
  placeBlock(5)
  Corner()
  placeBlock(5)
  Corner()
  placeBlock(5)
  Corner()
  placeBlock(5)
  Corner()
end
function BuildCylinder( height )
   for i = 1, height do
  buildLayer()
  refillMaterials()
  turtle.up()
	end
end
print("How tall should the cylinder be?")
local height = tonumber(read())
turtle.select(1)
BuildCylinder(height)
Ok so it's saying = expected for line 21 but it's gibberish I don't need a equals there what's the matter with this I think I have just been staring at it to long can anyone tell me whats wrong?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 28 March 2013 - 04:03 PM

On the line after "function noMaterials()", there should be () after term.clear.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 28 March 2013 - 06:11 PM

View PostKingdaro, on 28 March 2013 - 04:03 PM, said:

On the line after "function noMaterials()", there should be () after term.clear.
so yes really, it was expecting an = sign :P

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 28 March 2013 - 06:51 PM

Mhm. Lua looks for variable definitions before function calls.

#5 TechManDylan

  • Members
  • 9 posts

Posted 29 March 2013 - 02:42 AM

Makes much more sense now I had been working on it all day and was getting a bit loopy :S anywho thanks alot it's coming along quite nicely I'm trying to make a whole bunch of basic functions for building shapes then im gonna assign them to multiple turtles and build a fortress of sorts on my Feed the Beast server lol :D

#6 TechManDylan

  • Members
  • 9 posts

Posted 29 March 2013 - 05:55 AM

hmm now I have go to another one that's stumping me

Code
Spoiler
and it's telling me
Posted Image

#7 Doyle3694

  • Members
  • 815 posts

Posted 29 March 2013 - 05:58 AM

"times" is not a defined variable

#8 LuaEclipser

  • Banned
  • 220 posts
  • LocationCleveland, Ohio

Posted 29 March 2013 - 06:04 AM

you must define "times"
if you dont define it, just do the number

#9 TechManDylan

  • Members
  • 9 posts

Posted 29 March 2013 - 06:14 AM

oh I feel like an idiot now it Notepad++ was saving it as a .txt instead of blank and the turtle didn't have the new code lol now it's working like a charm now all I need is to fix my function refillMaterials() and I can start on my randomly generated castle :D

#10 TechManDylan

  • Members
  • 9 posts

Posted 29 March 2013 - 08:21 AM

Hmm why doesnt this work
function refillMaterials()  
Curslot = 1
if turtle.getItemCount(Curslot) < 1 then
  if Curslot == 16 then
   Curslot = Curslot - 15
   noMaterials()
  else
   Curslot = Curslot + 1
   turtle.select(Curslot)
  end
end
end
it doesnt give me any erros but it ingores but im calling everytime a place a block
function placeBlock(times)
    for blocks = 1, times do
   refillMaterials()
   turtle.placeDown()
   turtle.forward()
end
end
any insight?

#11 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 29 March 2013 - 08:29 AM

I am not sure if I understand whats wrong 100% but, it will never ever go to a slot higher than 2. Each time you call the function you reset Curslot to 1. So when slot 1 is empty it selects slot two, then when you place again it selects slot 2 again. And thus slot two may be empty and it will not place anything.

#12 TechManDylan

  • Members
  • 9 posts

Posted 29 March 2013 - 08:57 AM

hmm that helps so maybe Curslot should be a global varible so it stays constant?
Edit: Yep that fixed it but the entire turtle has to be full otherwise it wont place a block when called the swap to next slot i figure something better out later

#13 Mailmanq!

  • Members
  • 123 posts
  • LocationI am omnipresent... DUH

Posted 02 April 2013 - 11:10 AM

Edit: Failure to read properly





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users