Raised This Month: $51 Target: $400
 12% 

Using Files to write data/values(old and new file commands)


Post New Thread Reply   
 
Thread Tools Display Modes
The Specialist
BANNED
Join Date: Nov 2006
Old 12-11-2006 , 16:13   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #11

wow. Your awsome schnitzlmaker! thank you so much ! ++karma .

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 ?

Last edited by The Specialist; 12-11-2006 at 19:42.
The Specialist is offline
Send a message via AIM to The Specialist
pRED*
Join Date: Dec 2006
Old 05-10-2007 , 04:57   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #12

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
pRED* is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 05-10-2007 , 10:07   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #13

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
__________________
schnitzelmaker is offline
pRED*
Join Date: Dec 2006
Old 05-10-2007 , 18:11   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #14

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?
pRED* is offline
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 05-11-2007 , 03:04   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #15

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
__________________

Last edited by schnitzelmaker; 05-11-2007 at 03:13.
schnitzelmaker is offline
djmd378
Senior Member
Join Date: Sep 2004
Old 05-12-2007 , 01:51   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #16

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?
__________________
djmd378 is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 05-12-2007 , 01:53   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #17

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.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 11-07-2012 , 22:18   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #18

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 View Post
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

Last edited by vitorrossi; 11-08-2012 at 16:16.
vitorrossi is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 11-08-2012 , 14:39   Re: Using Files to write data/values(old and new file commands)
Reply With Quote #19

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.
hleV is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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