173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 21 December 2015 - 02:55 PM
so, during the making of my OS, while waiting for things, i come across yet ANOTHER problem. This time i have no idea why it is happening. It won't create or write to the file "UserS".
This is the code which is executing it
local fileU = fs.open("UserS","a")
fileU.writeLine("test")
fileU.close()
Also, it won't write to the file when it had already been created. Also, it wont do it in write mode either. And no, no other program is using the file as the program that runs this is the only one on the computer. And no it doesn't give me an error :/
1852 posts
Location
Sweden
Posted 21 December 2015 - 03:23 PM
This may sound stupid, but have you tried turning it off and on again? :P/>
Anyway, it may have happened that you've opened the file before and have forgotten to close it, because that can cause some errors.
I'd also suggest you try something like this
local file = fs.open( "Users", fs.exists( "Users" ) and "a" or "w" ) --# If the file exists then open it in append mode, otherwise open it in write mode
file.write( "test" )
file.close()
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 21 December 2015 - 03:36 PM
This may sound stupid, but have you tried turning it off and on again? :P/>
yes i have, that was actually one of the first things i did as that solves 90% of all technical problems :D/> but i shall try the alternative open thing u showed me :)/>
Edit: works! Ta! But one question, how does
and "a" or "w"
work? Like why does it work like that?
Edited on 21 December 2015 - 02:41 PM
1852 posts
Location
Sweden
Posted 21 December 2015 - 04:06 PM
Edit: works! Ta! But one question, how does
and "a" or "w"
work? Like why does it work like that?
When opening a file in append mode it doesn't clear everything in the file, it adds to the existing data, and when using write mode it basically opens the file like it's empty so to say.
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 21 December 2015 - 04:08 PM
no i'm talking about like the and/or statements :P/>
3057 posts
Location
United States of America
Posted 21 December 2015 - 04:14 PM
Ternary Operators are very fun. I use them way too much.
1852 posts
Location
Sweden
Posted 21 December 2015 - 06:20 PM
KingOfGamesYami have already linked you the awesomeness, it's a neater way todo things and it can save you a lot of lines.
So let's say we had an if statement like this when we wanted to set a value to a variable
local number = 0
while true do
--# Here's the if statement
if number == 10 then
number = 0
else
number = number + 1
end
print( number )
sleep( 1 )
end
We could use ternary operators to crunch those 4 lines into 1 line
local number = 0
while true do
number = number < 10 and number + 1 or 0 --# Here it checks if the number is smaller than then, if it is then add one to the number, if not, set it to 0
print( number )
sleep( 1 )
end
Edited on 21 December 2015 - 05:20 PM
173 posts
Location
The hall of 1000 monkeys and only 1 typewriter
Posted 21 December 2015 - 06:23 PM
okie! i get it now :3 thx
1080 posts
Location
In the Matrix
Posted 22 December 2015 - 12:45 AM
okie! i get it now :3 thx
I'm just gonna put this out there, other languages use the ? and : for theirs.
bool condition = (user == "Awesome") ? true : false;