103 posts
Posted 08 June 2014 - 03:32 AM
The API function:
function ComeBackCheck()
print ("come back? <y>/n ? ")
local comeback = read()
if comeback ~= "n" then
comeback = "y"
end
return comeback
end
So that's my code. When I call from my main program: comeback = ComeBackCheck() - it does two things I don't like:
#1: the reponse isn't on the same line; inside the program - it does… Why? Is this not possible?
#2: It doesn't work - and I'm not sure why….
comeback comes back as nil
7083 posts
Location
Tasmania (AU)
Posted 08 June 2014 - 03:50 AM
1) "print" performs a line break after whatever you pass it. Sounds like you want "write".
2) The way you're calling the function seems fishy, and may have something to do with the "nil" return value. Show the rest of the code.
By the by, since this doesn't seem to be catching your attention yet, questions about ComputerCraft coding should be posted in
Ask a Pro.
103 posts
Posted 08 June 2014 - 04:02 AM
Dammit, I did it again - I searched for APIs and functions - ended up here; and just saw the API sub-section…. (Sorry Lyqyd!)
I'm just gonna start over in the Ask a Pro.
8543 posts
Posted 08 June 2014 - 04:02 AM
This is at least the third question post by you I've had to move to the Ask a Pro section. You need to post questions in the Ask a Pro section. If you keep posting them elsewhere, I may have to add some restrictions to your account, which I'd rather not do.
103 posts
Posted 08 June 2014 - 04:11 AM
I again apologize - It was truly an honest mistake. :(/>
So trying this again: That is the entire code for the API (tAPI). The code in the program is simply:
local comeback = tAPI.ComeBackCheck()
EDIT: I figured out the nil part; my own bad programming - but back on the same line thing: I had thought print and write were the same thing; at least, that's what the wiki says.
Edited on 08 June 2014 - 02:21 AM
8543 posts
Posted 08 June 2014 - 04:23 AM
print calls write and just adds a newline character to the arguments, so using write instead of print will not move the read to the next line.
103 posts
Posted 08 June 2014 - 04:31 AM
Thanks. I got it fixed (I changed the code to return a true / false) - and sure enough; I was wrong about the print / write thing as you already know. It's all good now. Thanks (and again, sorry for the mishap)