8 posts
Posted 12 January 2013 - 01:14 AM
Hello i have been in serious need of two things of whitch i have tried everything i know to find and could not if someone could help i would be very greatfull
1. I have been searching for a way to get ONLY the y coordanate of the cursor into a variable (getcursorpos isnt storing just 1) and i need it to
2.clear ONE line at a time im getting a cannot subtract error when i try to do term.clearLine()
If ANYONE can help with this i will be very happy
7508 posts
Location
Australia
Posted 12 January 2013 - 01:22 AM
local cursorX, cursorY = term.getCursorPos()
thats the only way
as for number 2… error message and code please…
8 posts
Posted 12 January 2013 - 01:32 AM
No longer getting the error but the line will not clear
function lock(x)
write("Pass:")
pass = read("*")
if pass == x then
else
term.clearLine()
print("Incorrect")
sleep(1)
lock(x)
end
end
what i need is for it to write the lock input on the same line every tim
7508 posts
Location
Australia
Posted 12 January 2013 - 01:37 AM
Try this:
function lock( x )
local sx, sy = term.getCursorPos()
while pass ~= x do -- loop until they get the right password
write("Pass:")
local pass = read( "*" )
if pass == x then
return true -- exit the function, we are done here
else
term.setCursorPos( 1, sy )
term.clearLine()
print( "Incorrect" )
sleep( 1 )
end
end
end
note i removed your recursive call to lock… if the password was entered wrong enough times you would get stack overflow and your program would crash…
8 posts
Posted 12 January 2013 - 01:42 AM
Thanks forgot about a stack overflow!! (Fail on my part ) been a while since i encountered one
8 posts
Posted 12 January 2013 - 01:44 AM
Now when i try to call it as an API it is giving me locktest:2: attempt to call table
7508 posts
Location
Australia
Posted 12 January 2013 - 01:49 AM
are you loading it as an api first?
8 posts
Posted 12 January 2013 - 01:50 AM
yes
os.loadAPI("lock")
lock("pass")
7508 posts
Location
Australia
Posted 12 January 2013 - 02:21 AM
os.loadAPI("lock")
lock.lock( "pass" )
2088 posts
Location
South Africa
Posted 12 January 2013 - 02:33 AM
yes
os.loadAPI("lock")
lock("pass")
When you load an API you call it like this:
apiName.apiFunction(apiArguments)
So in this case, if it's called 'lock', initialize the function the way TheOriginalBit