AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   read file (https://forums.alliedmods.net/showthread.php?t=61697)

iCap 10-07-2007 14:24

read file
 
how do you read from a secondary file?

purple_pixie 10-08-2007 11:54

Re: read file
 
How do you mean?

As in read two files at once? Or just read from a file?

If you mean how to read in general:


PHP Code:

new line,file[128],text[128],length
copy
(file,sizeof file -1,"file to read.txt")
while ( ( 
line read_file(file,line,text,sizeof text -,length) ) )
{
    
log_amx(text)


The "while" line might confuse you ...

First, the loop itself:
The code in {} after the while () will be executed again and again until the expression after while ( in () ) is no longer true.

And secondly the condition:
( line = x ) has the value of x, and sets line to x.

e.g.
PHP Code:

if ( ( line ) )
{
    
log_amx("hello")


would set line to 0, but not log anything (since 0 is false).
(without the extra pair of parentheses, you would get a "possibly unintended assignment" warning.

PHP Code:

if ( ( line ) )
{
    
log_amx("hello")


would set line to 1 and log hello (because 1 is true)

M249-M4A1 10-08-2007 12:17

Re: read file
 
You should understand a while loop because most reading techniques use a while loop until the end of the file (eof) has been met


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

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