AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if the first line in file (https://forums.alliedmods.net/showthread.php?t=92165)

Mlk27 05-11-2009 04:19

Check if the first line in file
 
Sorry I can't figure this out. How do I check if the first line in a file starts with comments?

Code:
new spawnscredit = 0 while (file && !feof(file)) {     fgets(file, buffer, charsmax(buffer))     trim(buffer)     if(!spawnscredit && (buffer[0] == '/' && buffer[1] == '/')) //     {         spawnscredit = 1         set_task(10.0, "print_spawnscredit", _, buffer, charsmax(buffer))     }         // ..     }

Arkshine 05-11-2009 05:31

Re: Check if the first line in file
 
Your code does what you want.

Mlk27 05-11-2009 07:04

Re: Check if the first line in file
 
Doesn't work when the first comments are in other lines, eg

file.txt
de_dust2
dust3
// de_dust2

Arkshine 05-11-2009 08:33

Re: Check if the first line in file
 
So reverse the checks.

Hunter-Digital 05-11-2009 11:11

Re: Check if the first line in file
 
PHP Code:

new spawnscredit 0line 0
 
while (file && !feof(file))
{
    
fgets(filebuffercharsmax(buffer))
    
trim(buffer)
    
line++
 
    if(
line == && (buffer[0] == '/' && buffer[1] == '/')) //
    
{
        
spawnscredit 1
 
        set_task
(10.0"print_spawnscredit"_buffercharsmax(buffer))
    }
 
    
// ..
 



or...

PHP Code:

new bool:spawnscredit false
 
while (file && !feof(file))
{
    
fgets(filebuffercharsmax(buffer))
    
trim(buffer)
 
    if(!
spawnscredit && (buffer[0] == '/' && buffer[1] == '/')) //
        
set_task(10.0"print_spawnscredit"_buffercharsmax(buffer))
 
    
spawnscredit true
 
    
// ..


in wich I guess "spawnscredit" is for that check... if not use above or use this one with different name

Arkshine 05-11-2009 12:17

Re: Check if the first line in file
 
No need to create another var. In its code the comment check should be done before spawnscredit check.

Mlk27 05-11-2009 18:07

Re: Check if the first line in file
 
owh. i get it now :grrr:


Code:
new creditcheck = 0 while (file && !feof(file)) {     fgets(file, linedata, charsmax(linedata))     trim(linedata)     if(!creditcheck)     {         creditcheck = 1                 if(linedata[0] == '/' && linedata[1] == '/')             set_task(10.0, "print_spawnscredit", _, linedata, charsmax(linedata))     } }

kk thanks


All times are GMT -4. The time now is 01:34.

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