Jump to content




Cursor problem


  • You cannot reply to this topic
12 replies to this topic

#1 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 03: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


#2 Hawk777

  • Members
  • 162 posts

Posted 22 April 2012 - 03:44 AM

You never define "Y". You probably meant "currentY" instead.

#3 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 04:01 AM

Oh fixed that lol, but it still won't work, I get: Startup:47: attempt to call nil

#4 Hawk777

  • Members
  • 162 posts

Posted 22 April 2012 - 04:04 AM

I guess you're trying to shut down? The correct function is "os.shutdown()", not "shutdown()".

#5 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 04: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.

#6 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 22 April 2012 - 04: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.

#7 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 10: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


#8 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 22 April 2012 - 10:34 AM

Here is the corrected script. Your script never passes the while loop so never loading the function links.

Spoiler


#9 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 10:58 AM

Thanks, but it only works for Shutdown, if I try Login or Register it doesn't do anything

#10 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 22 April 2012 - 12: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 by luanub, 22 April 2012 - 12:18 PM.


#11 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

Posted 22 April 2012 - 01: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

#12 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 22 April 2012 - 09: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


#13 libraryaddict

  • New Members
  • 195 posts

Posted 23 April 2012 - 07:33 AM

Why not print off currentY?
Print that off before you check it





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users