CLEO Help File.Write writes in binary?

CLEO related
Status
Not open for further replies.

Mennims

Active member
Joined
Mar 18, 2014
Messages
41
Reaction score
0
Me again (man I feel like I'm spamming the forums  :urtheman:) but I'm trying to write some data using File.Write, but when I try open up the file it seems to be in binary or compiled format. Why can I not write it in plain text? Or how can I read the written file to see the results? Because I currently don't have a full understanding of File.Write so I'm trying to learn
 

Mennims

Active member
Joined
Mar 18, 2014
Messages
41
Reaction score
0
I can't figure out how it works! It says you can replace the mode with a string like I have here
Code:
0A9A:   open_file "CLEO\path.path" mode "rt+" store_to 0@
But it crashes. In fact even if I use their example without the string and some weird number it still crashes! Does the file have to exist or will it crash? Do you have to create the file with some other code? Really how do you use it. I went over that page tonnes of times. I want to open a file for writing, and if it doesn't exist, FUCKING MAKE IT, and if it does, I want it to write in plain text :angry:
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
227
Location
( ͡° ͜ʖ ͡°)
WHILE 8A9A: 30@ = openfile "CLEO\C\C-Console.log" mode "at"  // IF and SET
    WAIT 0
END
0AD9: write_formatted_text "This is text is written into the last line.%c" in_file 30@ 0xA
0AD9: write_formatted_text "This one too HJEHEHEHE.%c" in_file 30@ 0xA
0A9B: closefile 30@
 

Mennims

Active member
Joined
Mar 18, 2014
Messages
41
Reaction score
0
Opcode, thanks for the help, but I'm still lost, what does your script do? What I want to achieve is, I wan't a text file to be created, then I wan't data to constantly be written to it, but apparently "at" is append file, how would I create a file if it doesn't exist then allow it to be freely written to in plain text? What's the difference between "rt+" = read/write text file and "rt" = read text file. Does it allow it to be opened as read only? And what does close file do? What if I don't put it in? Oh and if I use "ab" sometimes I can get my script to crash.
 

Mennims

Active member
Joined
Mar 18, 2014
Messages
41
Reaction score
0
Oh and what does openfile do? It creates the file aswell? I've been messing around with the code and I can't seem to get it to write what I want without it crashing
 

Mennims

Active member
Joined
Mar 18, 2014
Messages
41
Reaction score
0
Ok well I found the problem, I got it working, now all I need to know is how do I create a file, I mean is there a function to do that? Or must I do the "at" method first then open it as "rt+" because I would like it to be in rt+.
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
IF 8AAB: "cleo\file.txt" //checks if file exists already
THEN
    0@ = file.Open("cleo\file.txt", "at+") //"at+" = append text file (create it if it doesn't exist)
    file.Close(0@)
END


0@ = file.Open("cleo\file.txt", "at") //"at" = append text file
This means any text will be added at the end of the file, rt+ will overwrite the text from file.

0AD9: write_formatted_text "BLA BLA %c" in_file 0@ text 0xA

0xA = /a = new line
 
Status
Not open for further replies.
Top