173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 22 February 2016 - 06:02 PM
so, i'm tying to make an interaction API for the advanced computer to make making thigns like buttons and centered text etc. a bit easier.
While creating a function for finding the center of the screen, i come across an issue.
I read up on the return statement to see if I was using it wrong and from what I could gather I was using it correctly.
Code:
function term.getCenter()
local hscreenX = screenX / 2
local hscreenY = screenY / 2
do return hscreenX, hscreenY end
end
screenX and screenY are called earlier with
screenX, screenY = term.getSize()
When I test this function out, it returns Y as nil.
Code in test program:
local x, y = term.getCenter()
print(tostring(x))
print(tostring(y))
3057 posts
Location
United States of America
Posted 22 February 2016 - 06:06 PM
I placed your code in a test file:
screenX, screenY = term.getSize()
function term.getCenter()
local hscreenX = screenX / 2
local hscreenY = screenY / 2
do return hscreenX, hscreenY end
end
local x, y = term.getCenter()
print(tostring(x))
print(tostring(y))
Exactly as you stated. I got two numbers.
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 22 February 2016 - 06:07 PM
Exactly as you stated. I got two numbers.
But i didn't :(/>
I was supposed to but i only got 1 number, which was the X axis. I never got the Y axis one
edit: When I run it on a normal computer I get 26 then nil
Edited on 22 February 2016 - 05:08 PM
3057 posts
Location
United States of America
Posted 22 February 2016 - 06:08 PM
So what in your code differs from the way mine is written?
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 22 February 2016 - 06:09 PM
the function and the program are in different programs. the function in .IAPI and the test program in test
3057 posts
Location
United States of America
Posted 22 February 2016 - 06:11 PM
My new setup is:
api file
screenX, screenY = term.getSize()
function term.getCenter()
local hscreenX = screenX / 2
local hscreenY = screenY / 2
do return hscreenX, hscreenY end
end
test file:
os.loadAPI( "api" )
local x, y = term.getCenter()
print(tostring(x))
print(tostring(y))
..still getting two numbers.
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 22 February 2016 - 06:12 PM
for some reason after renaming the function to term.getCentter() it worked…
why? XD
I now name it back and it works….
well this is interesting! case closed?
Edited on 22 February 2016 - 05:13 PM