Jump to content




Unexpected Symbol error

lua turtle help

16 replies to this topic

#1 TehNoiseBomb

  • Members
  • 9 posts

Posted 13 April 2016 - 11:06 PM

So, I have finally completed a farming program that should be easy to expand and edit as needed, until I tried running it and now have a syntax error I don't know how to fix. Yes, I looked at other threads and couldn't narrow down what my issue is being caused by, now onward then...

The error code I am getting is as follows:
farm9x9:12: bios:14: [string "refuel"]:8: unexpected symbol

Here is the pastebin of the farm9x9 (main) file in question: http://pastebin.com/mQkvff7G
Here is the pastebin of the refuel file: http://pastebin.com/z3dmLu3L

I've tried changing the way that I have the fuel level passed into the "function" file with no change, so help please?

Raw Code:
Spoiler

Edit: added link to refuel pastebin (my bad)

Edited by TehNoiseBomb, 13 April 2016 - 11:58 PM.


#2 Bomb Bloke

    Hobbyist Coder

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

Posted 13 April 2016 - 11:46 PM

The file in question is "refuel", not the one you're displaying here. Check around line eight within that script.

#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 13 April 2016 - 11:49 PM

Like BB said, the error is in your refuel file. That's kinda why assert gave you that error. Loadfile returned nil, and the error message. Assert saw that loadfile returned an error message, and promptly displayed it on screen.

#4 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 12:00 AM

View PostBomb Bloke, on 13 April 2016 - 11:46 PM, said:

The file in question is "refuel", not the one you're displaying here. Check around line eight within that script.

Fixed the post, http://pastebin.com/z3dmLu3L

View PostDragon53535, on 13 April 2016 - 11:49 PM, said:

Like BB said, the error is in your refuel file. That's kinda why assert gave you that error. Loadfile returned nil, and the error message. Assert saw that loadfile returned an error message, and promptly displayed it on screen.

I remember reading that and forgot about it, thanks for refreshing my memory on it.

#5 Bomb Bloke

    Hobbyist Coder

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

Posted 14 April 2016 - 12:07 AM

Mind you, I can see a "refuel" script elsewhere in your pastebin account, but I can't see how it'd generate this error. Beats me as to whether it matches the one you're actually using...?

(Edit: Ah, I got ninja'd, and it apparently is.)

One problem I can see with it is that refuel attempts to loadfile refuel. That'll spark an infinite loop which'll probably lead to the system shutting down. I'm not entirely sure why you're doing this, either; I see you're trying to assign what refuel() returns to fuelLevel at some point, but refuel() doesn't actually return anything, so....

You can also pack down this sort of thing:

local inputs = {...}
local crop, seed, fullyGrown, sleepTime --variables passed in (inputs)

.
.
.

for k, v in pairs(inputs) do
 if k == 1 then crop = v end
 if k == 2 then seed = v end
 if k == 3 then fullyGrown = v end
 if k == 4 then sleepTime = v end
end

... like so:

local crop, seed, fullyGrown, sleepTime = ...

Edited by Bomb Bloke, 14 April 2016 - 12:08 AM.


#6 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 12:12 AM

View PostBomb Bloke, on 14 April 2016 - 12:07 AM, said:

Mind you, I can see a "refuel" script elsewhere in your pastebin account, but I can't see how it'd generate this error. Beats me as to whether it matches the one you're actually using...?

(Edit: Ah, I got ninja'd, and it apparently is.)

One problem I can see with it is that refuel attempts to loadfile refuel. That'll spark an infinite loop which'll probably lead to the system shutting down. I'm not entirely sure why you're doing this, either; I see you're trying to assign what refuel() returns to fuelLevel at some point, but refuel() doesn't actually return anything, so....

You can also pack down this sort of thing:

local inputs = {...}
local crop, seed, fullyGrown, sleepTime --variables passed in (inputs)

.
.
.

for k, v in pairs(inputs) do
if k == 1 then crop = v end
if k == 2 then seed = v end
if k == 3 then fullyGrown = v end
if k == 4 then sleepTime = v end
end

... like so:

local crop, seed, fullyGrown, sleepTime = ...

I saw your problem, i copy pasted the wrong file, oops. The correct one: http://pastebin.com/z3dmLu3L

I also did not know you could use:
local crop, seed, fullyGrown, sleepTime = ...
I'm a programmer but I haven't worked much with Lua so I'm still learning the syntax.

#7 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 April 2016 - 01:04 AM

Does the error still occur?

#8 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 01:06 AM

View PostDragon53535, on 14 April 2016 - 01:04 AM, said:

Does the error still occur?
If you mean the issue BB brought up, that was only a mistake on my part when putting the code up on pastebin. The issue is persisting.

#9 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 April 2016 - 01:46 AM

If it's the same file, then line 8 should have a problem. The only thing I notice on line 8 that could possibly cause an error if the lua interpreter is stupid is the comma in the comment.

#10 Bomb Bloke

    Hobbyist Coder

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

Posted 14 April 2016 - 02:00 AM

He's actually changed that file a couple of times now (eg, attempting to implement that suggestion I'd made above re the assignments from ...). Is it really still giving the same error, verbatim?

#11 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 02:33 AM

I fixed that error and another, now I am getting a
getSeed:17: attempt to index ? (a nil value)
. This is occuring in a loop through the turtle's inventory. For some reason I can't get it to break out of the loop like I expected it to do when I return seeds: (seed is the string unlocalized name passed into the function)
Spoiler

Edited by TehNoiseBomb, 14 April 2016 - 02:34 AM.


#12 Bomb Bloke

    Hobbyist Coder

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

Posted 14 April 2016 - 02:38 AM

Make sure turtle.getItemDetail() is returning a table before you attempt to treat it like one.

local curSlot = turtle.getItemDetail(i)
if curSlot and curSlot.name == seed then  --# if curSlot is non-nil, then index in for the "name" key and compare that to the "seed" variable...
 ...

Note that assigning the return value avoids calling "turtle.getItemDetail(i)" multiple times when once suffices.

#13 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 02:46 AM

View PostBomb Bloke, on 14 April 2016 - 02:38 AM, said:

Make sure turtle.getItemDetail() is returning a table before you attempt to treat it like one.

local curSlot = turtle.getItemDetail(i)
if curSlot and curSlot.name == seed then  --# if curSlot is non-nil, then index in for the "name" key and compare that to the "seed" variable...
...

That worked, now I just have to find a logic error somewhere, my program is working but seems to be looping after it prints the first "Fuel left... " line.

Quote

Note that assigning the return value avoids calling "turtle.getItemDetail(i)" multiple times when once suffices.

That was exactly what I was going for.

Thanks for the help by the way.

Edited by TehNoiseBomb, 14 April 2016 - 02:46 AM.


#14 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 02:58 AM

OK now I'm getting another error in getSeed the first time I call it from farm9x9:
local seedData = getSeed(seed) --Get the data about the seed in the turtle's inventory
farm9x9 code

ERROR: getSeed:18: index expected, got nil

for i = 1, 15 do
if turtle.getItemDetail(i) and turtle.getItemDetail(i).name == seed then
  seeds["slot"] = i --> line 18
  seeds["count"] = turtle.getItemDetail(i).count
  seeds["name"] = turtle.getItemDetail(i).name
  seeds["damage"] = turtle.getItemDetail(i).damage --This is included to preserve all the data from the selected item
  return seeds
end
end
getSeed code

It seems like the error is referring to the "index" as i because before this code runs, the table should be blank with that like being the first entry into it

#15 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 April 2016 - 04:12 AM

That doesn't look like it could cause that error, however like BB said, consolidate those turtle.getItemDetail calls into one. It will very much speed up your program as you don't have to run a function more than one time.

Show the rest of your code by the way.

for i = 1, 15 do
  local currSlot = turtle.getItemDetail(i) --#One function call, the ENTIRE table that's returned gets saved to this. Which means that we don't have to call getItemDetail more than once
  if currSlot and currSlot.name == seed then
	seeds.slot = i --#seeds.slot and seeds["slot"] are the same. You just can't use spaces and such.
	seeds.count = currSlot.count
	seeds.name = currSlot.name
	seeds.damage = currSlot.damage
	return seeds
  end
end

Edited by Dragon53535, 14 April 2016 - 04:14 AM.


#16 Bomb Bloke

    Hobbyist Coder

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

Posted 14 April 2016 - 04:56 AM

Heck, easier again to just return the perfectly good table turtle.getItemDetail() returned, directly:

for i = 1, 15 do
  local currSlot = turtle.getItemDetail(i)
  if currSlot and currSlot.name == seed then
        currSlot.slot = i
        return currSlot
  end
end

As for your latest error, that'd indicate that you never defined "seeds" to be a table - though the above code removes any such need initialise it at all.

#17 TehNoiseBomb

  • Members
  • 9 posts

Posted 14 April 2016 - 12:06 PM

View PostBomb Bloke, on 14 April 2016 - 04:56 AM, said:

Heck, easier again to just return the perfectly good table turtle.getItemDetail() returned, directly:

for i = 1, 15 do
  local currSlot = turtle.getItemDetail(i)
  if currSlot and currSlot.name == seed then
		currSlot.slot = i
		return currSlot
  end
end

As for your latest error, that'd indicate that you never defined "seeds" to be a table - though the above code removes any such need initialise it at all.

Seems like it's working now, thanks for all the help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users