This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ChromeCoder's profile picture

error: bios:337: [string "guess"] :59: ')' expected

Started by ChromeCoder, 27 May 2013 - 06:37 AM
ChromeCoder #1
Posted 27 May 2013 - 08:37 AM
Line 59: print ("The number was" numb )
Lyqyd #2
Posted 27 May 2013 - 02:30 PM
Split into new topic.

Use the concatenation operator (`..`) between your string and your variable, like so: print("The number was"..numb)

For future reference, always post your entire program.
nutcase84 #3
Posted 27 May 2013 - 03:10 PM
Split into new topic.

Use the concatenation operator (`..`) between your string and your variable, like so: print("The number was"..numb)

For future reference, always post your entire program.

Or use ',' for print.
Bubba #4
Posted 27 May 2013 - 04:09 PM
Or use ',' for print.

Don't confuse people. That is not concatenation but rather a handy feature included with the print function.
ChromeCoder #5
Posted 28 May 2013 - 08:37 AM
Split into new topic.

Use the concatenation operator (`..`) between your string and your variable, like so: print("The number was"..numb)

For future reference, always post your entire program.

Thanks for the help, I'll make sure I post my entire program next time. :)/>
ChromeCoder #6
Posted 28 May 2013 - 09:13 AM
Title: error: bios:337: [string "guess"] :53: 'then' expected

Line 53: textutils.slowPrint ("Player 3 Won")

Whole code : http://pastebin.com/Yay6vdgW

I'm only a new starter so I have no idea what's wrong. Any help will be appreciated, thank you.
Cranium #7
Posted 28 May 2013 - 10:26 AM
Whenever you start a line with 'if', you need to finish that statement with a 'then' before adding your conditions. I would also recommend using elseif. Here's an example:

if someVariable == 0 then
    --some code
elseif someOtherVariable == 1 then
    -- some other code
else
    --completely different code
end
You see I start with 'if', then after i declare my condition, I add a 'then'. If I need enother different condition, I add an 'elseif'. If none of the other conditions are met, I use an 'else'. Of course, make sure you are using an 'end' for each statement. In the example above, this is one statement, even though there are several different conditions.
ChromeCoder #8
Posted 28 May 2013 - 11:14 AM
Whenever you start a line with 'if', you need to finish that statement with a 'then' before adding your conditions. I would also recommend using elseif. Here's an example:

if someVariable == 0 then
	--some code
elseif someOtherVariable == 1 then
	-- some other code
else
	--completely different code
end
You see I start with 'if', then after i declare my condition, I add a 'then'. If I need enother different condition, I add an 'elseif'. If none of the other conditions are met, I use an 'else'. Of course, make sure you are using an 'end' for each statement. In the example above, this is one statement, even though there are several different conditions.

Thanks for the help, I will try to remember for next time. :D/>
Pyro_ #9
Posted 28 May 2013 - 11:29 AM
Hey, unrelated to your problem, but I noticed something in your code that will come back to haunt you later if you fall in to the habit.

Code block like this:

while true do
if something == 0 then
-- Some code
break
else
-- Some more code
break
end

Having a while(true) statement with multiple breaks to get out of it is called code forking. It may seem harmless now, but later on when you start working on larger programs, or you come back in a couple of weeks and read your code again and try and understand it, you're going to give yourself a very big headache trying to wrap your head around it.

In all professional code classes (not taught by some high school teacher who learned it from a book he pirated online) they frown on this as though satan himself devised it. They hate it almost as much as the use of goto constructs, and will cause them to fail you on whatever you were coding if you don't refactor it before you turn it in.

Just keep in mind to try not to fall into the habit of using it that way.
ChromeCoder #10
Posted 28 May 2013 - 11:48 AM
Line 52: end

Whole code: http://pastebin.com/zW98a7mm

Sorry if I have been requesting a lot of help, its just because I'm a complete noob and I'm adding on stuff to the guessing game from the wiki without any training other than the textutils.slowPrint and print command (I'm not sure what their called)
theoriginalbit #11
Posted 28 May 2013 - 11:50 AM
Line 44 - 52 you have way too many ends, Lua thinks you're attempting to end the program block and then is seeing more code, so is getting confused. Remove the two 'end's that are in between the textutils.slowPrint functions. Also I suggest you have a read of the PIL to better help get an understanding of Lua. http://www.lua.org/manual/5.2/
ChromeCoder #12
Posted 28 May 2013 - 12:29 PM
Line 44 - 52 you have way too many ends, Lua thinks you're attempting to end the program block and then is seeing more code, so is getting confused. Remove the two 'end's that are in between the textutils.slowPrint functions. Also I suggest you have a read of the PIL to better help get an understanding of Lua. http://www.lua.org/manual/5.2/

Thanks for all the help, I'll make sure I have a little read before I make any other programs. :)/>
Lyqyd #13
Posted 29 May 2013 - 01:49 PM
Threads merged. Please stick to one topic when posting additional questions about the same piece of code.