Forum

> > CS2D > Scripts > create file
Forums overviewCS2D overview Scripts overviewLog in to reply

English create file

12 replies
To the start Previous 1 Next To the start

old Re: create file

TimeQuesT
User Off Offline

Quote
please describe better your problem. there are many ways to create one. Or do you mean in "lua" ?

old Re: create file

Banaan
User Off Offline

Quote
1
2
3
local file = io.open("my.file", "w")
file:write("This is my file")
file:close()

This would create a file and write This is my file to it. You should make sure you have write rights in the folder though.

old Re: create file

J4x
User Off Offline

Quote
Yeah it's about lua.

Well, there are several forms, but this is the one i use.
>Go to the folder where u like to create your lua, then press rigght click -> new -> text document.

> then change all the name to THE_NAME THAT YOU WANT.lua, it will ask you if you are shure to change the extention, just press yes. YAY! we have our lua file

EDIT: LOL, i was thinking you want to cretae a .lua file

old Re: create file

EnderCrypt
User Off Offline

Quote
What you are saying makes no sense... Im confiused
just, how do i make it create a file io.open gives nil when file doesent exist

old Re: create file

DannyDeth
User Off Offline

Quote
@Banaan & pheangsri:
The reason this code is not working is because you are not opening it with the right rights or the file does not exist.

Well that is what I remember. But yeah, give more details about the error message.

old Re: create file

Banaan
User Off Offline

Quote
That's what I said: rights. If a file does not exist, it will automatically be created (as long as you use a write mode).

The exact code below creates a file called my.file with This is my file as contents on my Ubuntu 10.10. So the problem must lie within your system configuration.

You should try using the assert function for an error report:
1
local file = assert(io.open("my.file", "w"))
Tell us which error it raises.

old Re: create file

DannyDeth
User Off Offline

Quote
@Banaan:
Hmmm, it must be PHP then. I started learning them right about the same time, so I might of confused some stuff around But yeah, I thought it was w+ that made a file if it was non-existent

old Re: create file

EnderCrypt
User Off Offline

Quote
LUA ERROR: sys/lua/fy_knife_arena_lua.lua:715: sys/lua/exp_data_backup/backup 1299318034.txt: No such file or directory

maybe its cause im missing a folder, i was tinking it would create it?

old Re: create file

DannyDeth
User Off Offline

Quote
You cannot create directories ( folders in Windows User Language )! Only files!

old Re: create file

EnderCrypt
User Off Offline

Quote
thx then i just create folder and done

edit: yeah working now, thx
edited 1×, last 05.03.11 12:03:20 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview