Jump to content




Strange Problem


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

#1 civilwargeeky

  • Members
  • 393 posts

Posted 14 October 2012 - 03:20 AM

So I really don't know why this is happening. All of my code works fine, except for one part that should work anyway. (My problem is toward the end)
edit: Made my description of problem clearer
 --Just a simple function
function clearall()
term.clear()
term.setCursorPos(1,1)
end

test = 0
diskside = ""

--Just checks to see if there is a disk
check = fs.exists("disk")
if check ~= true then
test = 1
end

--The part that actually  moves the programs
while test ~= 1 do
clearall()
print("What operation?")
print("download/upload")
local choice = io.read()
if choice == "download" then
test = 1
end
if choice == "upload" then
test = 1
end
clearall()

if choice == "download" then
local ondisk = fs.list("disk")
for i=1, #ondisk do
local current = fs.combine("disk",ondisk[i])
fs.delete(ondisk[i])
fs.copy(current,ondisk[i])
end
else

if choice == "upload" then
local oncomp = fs.list("")
for i=1, #oncomp do
local current = fs.combine("disk",oncomp[i])
if (oncomp[i] ~= "rom") and
   (oncomp[i] ~= "disk") then
fs.delete(current)
fs.copy(oncomp[i],current)
end
end
end

end

end

if check == true then
textutils.slowPrint("Working...")
sleep(1)
print("")
print("Done")

--The part I'm having trouble with: with this code, it is not ejecting the disk
--Note: the table "side" is defined by a program that runs at startup and gives all the different sides as strings.
-- Also, when this runs, choice is supposed to either equal "upload" or "download" or else it wouldn't have broken the while
--Now, the strange thing is, if I take out the if choice == "upload" then, and the end that follows
--then it does what its supposed to do, but like this, it dosen't do anything
if choice == "upload" then
for i=#side, 1, -1 do
diskcheck = disk.isPresent(side[i])
if diskcheck == true then
diskside = side[i]
end
end
disk.eject(diskside)
end

else
print("No disk")
end


#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 14 October 2012 - 03:30 AM

Where do you define 'choice'. What does the error say?

#3 civilwargeeky

  • Members
  • 393 posts

Posted 14 October 2012 - 03:33 AM

Its not an error, it just seems like it skips the code.
choice is defined towards the top.
local choice = io.read()


#4 civilwargeeky

  • Members
  • 393 posts

Posted 14 October 2012 - 03:52 AM

Well actually nevermind.

I just tried taking out the local from "local choice" and now it works.
What exactly does local mean anyway?

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 14 October 2012 - 03:58 AM

View Postcivilwargeeky, on 14 October 2012 - 03:33 AM, said:

Its not an error, it just seems like it skips the code.
choice is defined towards the top.
local choice = io.read()

Oh right, didn't see that lol. I can't read codes that aren't indented :)/>

#6 Fatal_Exception

  • New Members
  • 105 posts

Posted 14 October 2012 - 06:46 AM

http://lua-users.org...i/ScopeTutorial

#7 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 14 October 2012 - 07:23 AM

Change this:

local choice = io.read()

To:

local choice = read()

I'm pretty sure that Lua in CC won't take io.read().



View Postcivilwargeeky, on 14 October 2012 - 03:52 AM, said:

What exactly does local mean anyway?

I think it means that the variable will only be there within the length the program is open. A global variable stays around unless you reset the computer. That's at least what I heard.

#8 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 14 October 2012 - 07:26 AM

you sould also combine if and else statements
elseif <expression> then

#9 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 14 October 2012 - 10:32 AM

View Postbrett122798, on 14 October 2012 - 07:23 AM, said:

Change this:

local choice = io.read()

To:

local choice = read()

I'm pretty sure that Lua in CC won't take io.read().

It does

#10 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 14 October 2012 - 05:25 PM

View PostsIdEkIcK_, on 14 October 2012 - 10:32 AM, said:

View Postbrett122798, on 14 October 2012 - 07:23 AM, said:

Change this:

local choice = io.read()

To:

local choice = read()

I'm pretty sure that Lua in CC won't take io.read().

It does
really? last time i checked io.read wasnt compatible with term
unless the devs changed it, idk

#11 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 October 2012 - 06:48 PM

View PostPixelToast, on 14 October 2012 - 05:25 PM, said:

View PostsIdEkIcK_, on 14 October 2012 - 10:32 AM, said:

View Postbrett122798, on 14 October 2012 - 07:23 AM, said:

Change this:

local choice = io.read()

To:

local choice = read()

I'm pretty sure that Lua in CC won't take io.read().

It does
really? last time i checked io.read wasnt compatible with term
unless the devs changed it, idk

io.read() uses read(), and has for probably most of the life of the mod. It works just fine.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users