160 posts
Location
Netherlands
Posted 22 April 2012 - 04:16 AM
Whats wrong with this code?
Especially this part:
elseif key == 28 then
links()
end
end
-- Links
function links()
if currentY == 14 then
shell.run("login")
elseif currentY == 15 then
shell.run("register")
elseif currentY == 16 then
os.shutdown()
end
Im trying to make it able to open programs but I can't get it to work :/
Full code:
Spoiler
local Author = "Snakybo inc."
local Version = "1.0"
local currentX = 31
local currentY = 14
-- Functions
function drawCursor()
term.clear()
term.setCursorPos(1, 1)
draw()
term.setCursorPos(currentX, currentY)
write("<")
end
function draw()
shell.run("Layout")
print " ---------------------------------------"
print " | #### ## # # # # #### ### #### |"
print " | # # # # # # # # # # # # |"
print " | #### # # # # # ## ### # # #### |"
print " | # # ## ##### # # # # # # |"
print " | #### # # # # # # #### ### #### |"
print " ---------------------------------------"
print ""
print " ----------"
print " | Login |"
print " | Register |"
print " | Shutdown |"
print " ----------"
end
-- Cursor
while true do
drawCursor()
local a, key = os.pullEvent("key")
if key == 17 or key == 200 then
if currentY > 14 then
currentY = currentY -1
end
elseif key == 23 or key == 208 then
if currentY < 16 then
currentY = currentY +1
end
elseif key == 28 then
links()
end
end
-- Links
function links()
if currentY == 14 then
shell.run("login")
elseif currentY == 15 then
shell.run("register")
elseif currentY == 16 then
os.shutdown()
end
end
161 posts
Posted 22 April 2012 - 04:44 AM
You never define "Y". You probably meant "currentY" instead.
160 posts
Location
Netherlands
Posted 22 April 2012 - 05:01 AM
Oh fixed that lol, but it still won't work, I get: Startup:47: attempt to call nil
161 posts
Posted 22 April 2012 - 05:04 AM
I guess you're trying to shut down? The correct function is "os.shutdown()", not "shutdown()".
160 posts
Location
Netherlands
Posted 22 April 2012 - 05:22 AM
Yea I know, still have to make that function but first wanted to get the enter work, and just tested it with os.shutdown() and still the same error.
1111 posts
Location
Portland OR
Posted 22 April 2012 - 05:42 AM
You need to move the function links to where it is above the function that is calling it. Lua has not loaded the function as it has not gone that far down the script.
160 posts
Location
Netherlands
Posted 22 April 2012 - 11:27 AM
Okay, I tried 2 different ways to fix it but still the same error.
1.
elseif key == 28 then
links(currentY)
end
function links(currentY)
if currentY == 14 then
shell.run("login")
elseif currentY == 15 then
shell.run("register")
elseif currentY == 16 then
os.shutdown()
end
end
2.
elseif key == 28 then
if currentY == 14 then
links(14)
elseif currentY == 15 then
links(15)
elseif currentY == 16 then
links(16)
end
end
function links(number)
if number == 14 then
shell.run("login")
elseif number == 15 then
shell.run("register")
elseif number == 16 then
os.shutdown()
end
end
1111 posts
Location
Portland OR
Posted 22 April 2012 - 11:34 AM
Here is the corrected script. Your script never passes the while loop so never loading the function links.
Spoiler
local Author = "Snakybo inc."
local Version = "1.0"
local currentX = 31
local currentY = 14
-- Functions
function drawCursor()
term.clear()
term.setCursorPos(1, 1)
draw()
term.setCursorPos(currentX, currentY)
write("<")
end
function draw()
shell.run("Layout")
print " ---------------------------------------"
print " | #### ## # # # # #### ### #### |"
print " | # # # # # # # # # # # # |"
print " | #### # # # # # ## ### # # #### |"
print " | # # ## ##### # # # # # # |"
print " | #### # # # # # # #### ### #### |"
print " ---------------------------------------"
print ""
print " ----------"
print " | Login |"
print " | Register |"
print " | Shutdown |"
print " ----------"
end
-- Links
function links()
if currentY == 14 then
shell.run("login")
elseif currentY == 15 then
shell.run("register")
elseif currentY == 16 then
os.shutdown()
end
end
-- Cursor
while true do
drawCursor()
local a, key = os.pullEvent("key")
if key == 17 or key == 200 then
if currentY > 14 then
currentY = currentY -1
end
elseif key == 23 or key == 208 then
if currentY < 16 then
currentY = currentY +1
end
elseif key == 28 then
links()
end
end
160 posts
Location
Netherlands
Posted 22 April 2012 - 11:58 AM
Thanks, but it only works for Shutdown, if I try Login or Register it doesn't do anything
1111 posts
Location
Portland OR
Posted 22 April 2012 - 01:13 PM
Does it give any errors? Make sure the programs login and register are available to that computer.
shell.run() needs the absolute path so if they are in a folder called lets say programs then it would need to be.
shell.run("/programs/login")
I got an error saying those programs were not available which I expected since I don't have them.
I made a couple fake programs with those names, just printed stuff on the screen. They worked great. The computer probably cant find the programs.
Edited on 22 April 2012 - 11:18 AM
160 posts
Location
Netherlands
Posted 22 April 2012 - 02:41 PM
Yea I know that, I have the startup, layout, login and register files all saved on disk/os/, and if I want to run it I first need to do "cd disk" since i'm making an installer soon to.
And the shell.run("layout") works fine to, so that can't be the problem and it doesn't give any errors.
Also I tried changing the command it has to run with shell.run("clear") and that didn't work either
1111 posts
Location
Portland OR
Posted 22 April 2012 - 10:17 PM
if there are on the disk I believe you need to do shell.run("disk/login") not 100% as I don't use disk all that much.
You could try not using the Y axis and use a selection var instead. But it really should work as is, I have no problems.
With Selection Var
Spoiler
local Author = "Snakybo inc."
local Version = "1.0"
local currentX = 31
local currentY = 14
local selection = 1
-- Functions
function drawCursor()
term.clear()
term.setCursorPos(1, 1)
draw()
term.setCursorPos(currentX, currentY)
write("<")
end
function draw()
shell.run("Layout")
print " ---------------------------------------"
print " | #### ## # # # # #### ### #### |"
print " | # # # # # # # # # # # # |"
print " | #### # # # # # ## ### # # #### |"
print " | # # ## ##### # # # # # # |"
print " | #### # # # # # # #### ### #### |"
print " ---------------------------------------"
print ""
print " ----------"
print " | Login |"
print " | Register |"
print " | Shutdown |"
print " ----------"
end
-- Links
function links()
if selection == 1 then
shell.run("login")
elseif selection == 2 then
shell.run("register")
elseif selection == 3 then
os.shutdown()
end
end
-- Cursor
while true do
drawCursor()
local a, key = os.pullEvent("key")
if key == 17 or key == 200 then
if selection - 1 >= 1 then
currentY = currentY - 1
selection = selection - 1
end
elseif key == 23 or key == 208 then
if selection + 1 <= 3 then
currentY = currentY +1
selection = selection + 1
end
elseif key == 28 then
links()
end
end
193 posts
Posted 23 April 2012 - 08:33 AM
Why not print off currentY?
Print that off before you check it