Jump to content




Syntax error elseif


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

#1 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 10:13 AM

i get an error :bios:338: [string: "startup"]:123: syntax error

here's a bit of code near line 123

...
elseif
  l==i and k==(cmd1) then
  (cmd1e)
elseif                     -- This is line 123
  l==i and k==(cmd2) then
  (cmd2e)
elseif
...
I have no idea what caused this error message.

#2 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 06 May 2013 - 10:20 AM

Can we see your whole code please?

#3 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 10:23 AM

sure

Spoiler

pastebin:


#4 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 10:46 AM

I posted the code! Am i getting to impatient??

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 May 2013 - 11:20 AM

This line and others like it:

(cmd1e)

This is the issue. What are you trying to do here?

#6 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 11:28 AM

I am trying to run an input
i have:
cmd1e=read()
I want somone to for example type turtle.suck() and it to run when the code reaches the (cmd1e)

#7 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 May 2013 - 11:30 AM

Right, well, that wasn't executed very well.

Instead, you will have the user type the functions without () or the turtle. at the beginning; e.g. "suck", "forward", "back", "right".

Then you would call it by replacing these lines:
(cmd1e)

With this:
turtle[cmd1e]()


#8 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 11:38 AM

ok, thanks!

#9 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 06 May 2013 - 11:40 AM

View PostKingdaro, on 06 May 2013 - 11:30 AM, said:

-snip-

Or a pcalled loadstring...
cmd1e = read()

-- some code here

local func, err = loadstring(cmd1e, "userinput") -- "userinput" will cause errors like "userinput:1: some message" if the given operation failed
if not func then
	-- this happens if the given operation was unloadable, eg. an if-end wasn't closed properly (compile error)
	-- err describes the error message returned by loadstring
	error(err)
end

setfenv(func, getfenv())
local ok, err = pcall(func) -- this will call the function that contains the given operation
if not ok then
	-- this happens when the given operation failed, eg. if it called turtle.Suck() (that's nil, of course) (runtime error)
	-- err describes the error message returned by pcall
	error(err)
end


#10 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 06 May 2013 - 03:45 PM

I would personally go with the much safer and less complicated solution.

#11 NanoBob

  • Members
  • 102 posts

Posted 06 May 2013 - 04:27 PM

I've put it in my program and it works, I will soon release my remote turtle V2.0 using this, thanks a lot.
http://www.computerc...trolled-turtle/





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users