AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Using Files to write data/values(old and new file commands) (https://forums.alliedmods.net/showthread.php?t=46218)

The Specialist 12-11-2006 16:13

Re: Using Files to write data/values(old and new file commands)
 
wow. Your awsome schnitzlmaker! thank you so much ! ++karma . :up:

new question . when i write using the enums, i want the map name and origins together, so that i can load only origins of the map there on , into the menu . how can i tell which map name has which origins and only load them ?

pRED* 05-10-2007 04:57

Re: Using Files to write data/values(old and new file commands)
 
What open mode should I use to find and delete a specified line?

On mode "a+"/"w+" it create a file if there no exist
Mode "w+" overwrite a file if one exist*/

Those two lines seem to contradict each other. Would I be right to say the first line should be "a+"/"r+" creates a file if it doesn't exist?

And r+ probably the right mode for me to use?

Nice tutorial btw, great help for my new plugin

schnitzelmaker 05-10-2007 10:07

Re: Using Files to write data/values(old and new file commands)
 
You need to create 2 Files and copy from 1 file to another without the line you want.
See here:http://forums.alliedmods.net/showthread.php?t=49539

pRED* 05-10-2007 18:11

Re: Using Files to write data/values(old and new file commands)
 
What about overwriting a line?

Can I open the file in w+ mode and read lines till I find what I want, then overwrite it with slightly different values?

schnitzelmaker 05-11-2007 03:04

Re: Using Files to write data/values(old and new file commands)
 
Overwrite yes,but you cant delete a line from a file (And dont open in "w+" mode, this delete file /*Mode "w+" overwrite a file if one exist*/,use "a+")
But you can overwrite it with empty statement

djmd378 05-12-2007 01:51

Re: Using Files to write data/values(old and new file commands)
 
i tried useing fseek to read the end of the file first but no luck. It always reads from the first line. Can someone show me an example of how I would read from bottem to top of a file?

teame06 05-12-2007 01:53

Re: Using Files to write data/values(old and new file commands)
 
Code:
fget(file, ...) // For first line /* Set Position to last line in the file */ fseek(file, 0, SEEK_END); fget(file, ...);

P.S. This belong in the scripting section and not the tutorial section.

vitorrossi 11-07-2012 22:18

Re: Using Files to write data/values(old and new file commands)
 
Instead of

PHP Code:

new fsize file_size(filename,1)
for (new 
line=0;line<=fsize;line++) 

I had to use

PHP Code:

new fsize file_size(filename,1) - 1
for (new line=0;line<=fsize;line++) 


Quote:

Originally Posted by hleV (Post 1834789)
Wasn't - 1 enough?
Technically, since the line starts with 0 and not 1, only the loop condition should be changed:
PHP Code:

for (new lineline fsizeline++) 

as the last line available should be filesize(filename, 1) - 1.

You are right, I meant to type -1

hleV 11-08-2012 14:39

Re: Using Files to write data/values(old and new file commands)
 
Wasn't - 1 enough?
Technically, since the line starts with 0 and not 1, only the loop condition should be changed:
PHP Code:

for (new lineline fsizeline++) 

as the last line available should be filesize(filename, 1) - 1.


All times are GMT -4. The time now is 14:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.