Jump to content




Trying to make a woodchopper program but Im very new to programming


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

#1 TilionDC

  • Members
  • 9 posts

Posted 16 February 2014 - 08:11 PM

Okey So i tried making a woodchopping program but i think im in over my head.
This is a bit too complicated for starting just today...
I have a syntax error close to the "=" in the if statement on line 23 only i cant figure out what is wrong with it :/

Anyways here is the code so far. And I apologize if its messy this is my very first program and i tried to comment it but it seems im not too good with that either.

Spoiler
Here is the pastebin link(the program will be updated there though when i figure out more. so the spoiler might actually be more useful for the post.)
http://pastebin.com/NpGfzVyj

#2 CometWolf

  • Members
  • 1,283 posts

Posted 17 February 2014 - 03:21 AM

The line 23 "x-1" dosen't mean anything. You calculate a number but don't do anything with it. So it's expecting a = sign. Im guessing what you want is to decrease x by 1. Which would be done like this
x = x-1
You'll probably get the same errors on the other lines where you're doing it similarily.

#3 TilionDC

  • Members
  • 9 posts

Posted 17 February 2014 - 09:29 AM

View PostCometWolf, on 17 February 2014 - 03:21 AM, said:

The line 23 "x-1" dosen't mean anything. You calculate a number but don't do anything with it. So it's expecting a = sign. Im guessing what you want is to decrease x by 1. Which would be done like this
x = x-1
You'll probably get the same errors on the other lines where you're doing it similarily.
Okey thanks i totally forgot that. I also got to fix some other problems i had now but the parser still found some misstakes

Spoiler
So i got a problem with missing an end in line 127 after the while. only I cant find any missing end and i dubblechecked. What could else be wrong?

Also i tried parsing the drop function at line 150 but it says there is a syntax error with = at line 155. What could be wrong cause i cant see any problem.

#4 CometWolf

  • Members
  • 1,283 posts

Posted 17 February 2014 - 11:07 AM

Assuming your indentation is correct, this is non-sensical
							    end
							    elseif x < 0 then
You don't need to close an if followed by an elseif. this begins at line 107 by the way.

Line 150 is way off base. You can't pass an argument to a variable, let alone one you try to define at the same time.
			    local invCount(i) = turtle.getItemCount(i+1)


#5 TilionDC

  • Members
  • 9 posts

Posted 17 February 2014 - 04:35 PM

so instead of doing


for i = 0, 10 do
    local invCount(i) = turtle.getItemCount(i+1)
end

I could do

for i = 0, 10 do
    local j = i
    local invCount(j) = turtle.getItemCount(j +1)
end

Or would I need to make an array of invCount and then get the turtle.getItemCount the same way i did before? Do you have any examples if im still incorrect?

#6 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 17 February 2014 - 05:49 PM

local invCount = {}
for i = 1,11 do
  invCount[i] = turtle.getItemCount(i)
end

This will store the number of items in slots 1-11 in your turtle inventory into a table named invCount, such that:

invCount[1] = count of items in slot 1
invCount[2] = count of items in slot 2
... and so on.

If a slot is empty, it will return a 0 for the count.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 February 2014 - 09:32 PM

To be clear, "invCount()" (using rounded brackets) assumes "invCount" is a function and tries to call that function. "invCount(i)" would try to call that function and pass it "i" as a parameter.

"invCount[i]" (using square brackets) treats "invCount" as a table, and refers to the index in that table with the key name/number of "i".

A variable must already point to a function before you can attempt to call it, or to a table if you wish to index it. That first line in surferpup's example sets "itemCount" to point to a new, empty table.

#8 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 17 February 2014 - 10:04 PM

Bomb Bloke is correct. No matter how it is done, attempting to use invCount(i) = someVariable will never work, as you are attempting to assign the outcome of a function ( a no-no). My example accomplished what I saw as your intent -- which was to use a table.

Edited by surferpup, 17 February 2014 - 10:04 PM.


#9 TilionDC

  • Members
  • 9 posts

Posted 21 February 2014 - 08:52 AM

Okey so i redid my woodchopping program from scratch because it was crap. Im still having problems with the arrays though.

So this is my chest dropping function. Its not working very well
function chest()
turtle.turnLeft()
turtle.turnLeft()
local dropCount = {}
for i = 1, 13 do
  if i == 1 then
   turtle.select(1)
   local getCount = turtle.getItemCount()
   local keepOne = getCount - 1
   turtle.drop(keepOne)
  else
   dropCount[i] = turtle.select(i)
   turtle.drop()
  end
end
turtle.turnLeft()
turtle.turnLeft()
turtle.select(1)
end
For some reason its expecting a number.

What im trying to do is create an array that will check every slot from 1 - 13 and drop all items except for 1 item in slot 1.

#10 CometWolf

  • Members
  • 1,283 posts

Posted 21 February 2014 - 09:09 AM

Not entirely sure what dropCount is supposed to be, but turtle.select() dosen't return any values.
   dropCount[i] = turtle.select(i)

Or well, it returns true... but it's not like it could ever fail.

Anyways, since you didn't point out what line expects a number, im gonna take a guess and say it's this one
   local getCount = turtle.getItemCount()
Because getItemCount does indeed expect a number...

Edited by CometWolf, 21 February 2014 - 09:26 AM.


#11 TilionDC

  • Members
  • 9 posts

Posted 21 February 2014 - 09:30 AM

Oh i figured it out. I forgot to put a number in the turtle.getItemCount() variable.
Now it works. I still have one problem though i cant figure out what bugging it.

http://pastebin.com/Eeir6xdA

If you run the program with no sapling in its inventory at the start and you have saplings in a chest under it. and the tree is already grown in front of it. it will say "Turtle blocked".

It runs the detect function but it doesnt go foward in the "if compare == true then" section. Do you guys know what could be wrong? is it maybe that the block doesn't update?=

View PostCometWolf, on 21 February 2014 - 09:09 AM, said:

Not entirely sure what dropCount is supposed to be, but turtle.select() dosen't return any values.
   dropCount[i] = turtle.select(i)

Or well, it returns true... but it's not like it could ever fail.

Anyways, since you didn't point out what line expects a number, im gonna take a guess and say it's this one
   local getCount = turtle.getItemCount()
Because getItemCount does indeed expect a number...

Oh i guess you beat me to it.. Thanks anyways. Do you think you know what could be wrong?

#12 CometWolf

  • Members
  • 1,283 posts

Posted 21 February 2014 - 11:47 AM

Missing fuel? idk...
Post a picture, please.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users