This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Gumball's profile picture

GUIPaste

Started by Gumball, 25 May 2016 - 05:04 PM
Gumball #1
Posted 25 May 2016 - 07:04 PM
I'm making a program that downloads pastebins automatically, it looks good, and the data of what to download is a file. The trouble is, it doesn't write to a file properly? I have no idea why;
Pastebin is at: SkB9qExc
Required API at: pastebin get EPNh0HCv GUI
Test download file: Rxnhp2x5 (install as "pasteData")

Thanks!

-Bird
Edited on 25 May 2016 - 05:05 PM
TYKUHN2 #2
Posted 25 May 2016 - 08:09 PM
What do you mean "doesn't write properly"?
Gumball #3
Posted 25 May 2016 - 08:18 PM
What do you mean "doesn't write properly"?

It errors when trying to write a downloaded file. When I call file.close() it says "Attempt to index, nil value"
KingofGamesYami #4
Posted 25 May 2016 - 08:31 PM
That would mean the file wasn't opened, and was probably opened earlier but not closed. Try rebooting.
TYKUHN2 #5
Posted 25 May 2016 - 08:43 PM
You understand scoping right? Your "get" function uses file in the global scope, so does your main "stack". So when you opened "file" and get set "file" to equal what download contained, and when you tried to close "file" you were calling the close value of the string download contained.

Long story short: Use different variables or the Local keyword.
Gumball #6
Posted 25 May 2016 - 09:48 PM
You understand scoping right? Your "get" function uses file in the global scope, so does your main "stack". So when you opened "file" and get set "file" to equal what download contained, and when you tried to close "file" you were calling the close value of the string download contained.

Long story short: Use different variables or the Local keyword.


Oh wow. Thank you! :)/> You'll get credited when this gets released.
Edited on 25 May 2016 - 07:48 PM