Jump to content




Having some Lua Trouble


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

#1 Scratch

  • New Members
  • 4 posts

Posted 25 October 2012 - 11:10 PM

okay, So i'm trying to get a program to copy a file from a disk and paste it on the rom

Only difference is, I copy it 50 times.

i have 2 integers,

numLoop = 1
numStop = 50

I then make a string of the file copy destination

stringTempFile = "tempfile"..tostring(numLoop)..

the file is then copied to the rom
fs.copy("/disk/file", stringTempFile)

I get the response error of startup:41: Expected string, string
(sometimes when playing around with the code I get a "got string, nil" response)

Entirely the code is
numLoop = 1
numStop = 50
repeat
--stringLoop = tostring(numLoop
stringTempFile = "tempfile"..tostring(numloop)
fs.copy("/disk/file", stringTempFile)
print("Coping File "..numLoop" of "..numStop..)
numLoop = numLoop + 1
sleep(0.3)
until numLoop == numStop


#2 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 25 October 2012 - 11:28 PM

It would be much easier I think to use a for loop...
But can you explain more detailed about what you want to happen?

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 25 October 2012 - 11:31 PM

Post the full code of the 'startup' program. seeming as the error is on line 41 of startup

#4 Scratch

  • New Members
  • 4 posts

Posted 25 October 2012 - 11:55 PM

View Postjag_e_nummer_ett, on 25 October 2012 - 11:28 PM, said:

It would be much easier I think to use a for loop...
But can you explain more detailed about what you want to happen?

Okay, so I have the one file 'file' on my disk
the program copies the file over to the Rom as tempfile1,
ever pass of the loop will copy over the file again as tempfile2, tempfile3, tempfile4 and so on

View PostsIdEkIcK_, on 25 October 2012 - 11:31 PM, said:

Post the full code of the 'startup' program. seeming as the error is on line 41 of startup

I'm running the game on a different computer Without a internet connection, which sucks
Line 41 is fs.copy("/disk/file", stringTempFile)

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 26 October 2012 - 12:17 AM

For whatever reason, stringTempFile might not exist when you're using fs.copy on line 41.

I think it's because, on line 40, you wrote "tostring(numloop)" when it should be "tostring(numLoop)".

Honestly, though, you should just use a for loop and make the process much less complicated.

numStop = 50
for numLoop=1, numStop do
	stringTempFile = "tempfile"..tostring(numLoop)
	fs.copy("/disk/file", stringTempFile)
	print("Coping File "..numLoop.." of "..numStop)
	sleep(0.3)
end


#6 ChunLing

  • Members
  • 2,027 posts

Posted 26 October 2012 - 12:32 AM

What's with the extra concatenation operators on the ends of your strings?

#7 Scratch

  • New Members
  • 4 posts

Posted 26 October 2012 - 05:12 AM

Okay, after a few hours of being disconnected and unable to check the forums

I managed to some how fix it. (Mind the awful format, I'm a messy programmer)

numLoop = 1
numStop = 50
sleep(0.5)
repeat --Loop Start
 --print(numLoop) --Debug
 stringLoop = tostring(numLoop)
 print("Copying File  "..numLoop.." of "..numStop)
 stringTempFile = "tempfile"..numLoop..
 print(stringTempFile) --Debug
 fs.copy("/disk/file", stringTempFile)
 --print("Copied")
 numLoop = numLoop + 1
 --print(numLoop)
 --write("Copying File"..numLoop.." of "..numStop)
 sleep(0.01)
 until numLoop == numStop + 1 --Loop End

It works, only there are two strange things happening":
I get a concatenation error appearing if " print(stringTempFile) --Debug " is commented out AND
all outputs of stringTempFile have a extra 1 printed on the end of it (but numLoop is fine)

Might try out Kingdaro's suggestion later

#8 ChunLing

  • Members
  • 2,027 posts

Posted 26 October 2012 - 06:41 AM

print() automatically calls a tostring() conversion in certain cases. In this case, stringTempFile contains a string concatenated with a number concatenated with...nothing. print() is able to turn that into a string, but you can remove it if you also remove the end concatenation, probably. That should also remove the mysterious "1" you're getting.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users