Raised This Month: $ Target: $400
 0% 

Text & Files


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 12-20-2005 , 11:10   Text & Files
Reply With Quote #1

I want to check a line from a file to see if the map name matches it and return the string from it. This current code has been crashing me. Can you spot the problem?

Code:
check(Map[], xFile[], xlen) {         new BaseDir[64], File[64]     get_basedir(BaseDir, 63)     format(File, 63, "%s/configs/check.cfg", BaseDir)         if(file_exists(File))     {         new Text[64], Line, len = 0         while(read_file(File, Line, Text, 63, len))         {             if((Text[0] == ';') || !len)                 continue                 parse(Text, 63, xFile, xlen)             if(equali(Text, Map, 63))             {                   break             } else {                 format(xFile, len, "")             }         }     }     return xFile }
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-20-2005 , 11:18  
Reply With Quote #2

I don't think you can return a string. Actually, you don't need to return it anyway since that particular variable was passed by reference. Whatever changes to it you make in your function will be available to the calling function.
Brad is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 12-20-2005 , 11:20  
Reply With Quote #3

You can return a bool, you can return a float.. Why not a string?

Code:
public test(id) {     new Map[64]     get_mapname(Map, 63)         new File[64]     check(Map, File, 63)         client_print(id, print_chat, "%s", File) }


Edit: Hmmm, a global variable. Ahh a workaround! Thanks.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-20-2005 , 12:27  
Reply With Quote #4

You know how you grab the map name by doing something like this:

Code:
new mapName[32]; get_mapname(mapName, 31);
You're passing the local variable "mapName" by reference. The same thing applies with your own functions. It's not a global variable at all.

Oh, you can't return a string because it's composed of multiple cells whereas everything else you mentioned is only a single cell.
Brad is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 12-20-2005 , 12:38  
Reply With Quote #5

Quote:
Originally Posted by Cheap_Suit
You can return a bool, you can return a float.. Why not a string?


Edit: Hmmm, a global variable. Ahh a workaround! Thanks.
Cheap_Suit I'm dissappointed in you. you dont need a global variable.

when you make a function with a string it will change it.

Example:
Code:
//In main function     new szString[46] , len     len = TestStringFunc( szString , 45 ) //Your Func public TestStringFunc( p_szStr , p_iLen ) {     new iLen = format(p_szStr , p_iLen , "Testing String")     return iLen }

And then in the main function szString will be "Testing String" and len will be the string length of it.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 12-20-2005 , 12:42  
Reply With Quote #6

In PAWN, you can return arrays (and thus strings, as strings in PAWN are ^0 delimited arrays) through some process, but I forget it.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 12-20-2005 , 14:13  
Reply With Quote #7

Heres what I have right now but still it crashes my cs.
Code:
check_cfgfile(Map[], rFile[], rLen) {       new BaseDir[64]     get_basedir(BaseDir, 63)         new File[64]     format(File, 63, "%s/configs/xxxx.cfg", BaseDir)         new ReturnS     if(file_exists(File))     {         new Text[64], TgaFile[64], Line, len = 0         while(read_file(File, Line, Text, 63, len))         {             if((Text[0] == ';') || !len)                 continue                             parse(Text, 63, TgaFile, 63)             if(equali(Text, Map, 63))             {                 ReturnS = format(rFile , rLen , TgaFile)                   break             }             else             {                 ReturnS = format(rFile , rLen , "")             }         }     }     return ReturnS }

The function that calls it
Code:
public test(id) {     new Map[64]     get_mapname(Map, 63)         new TgaFile[64], File     File = check_precache(Map, TgaFile, 63)     client_print(id, print_chat, "%s", File) }

What I have in the cfg file
Code:
de_dust test_
de_dust2 test2_
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 12-21-2005 , 03:04  
Reply With Quote #8

Okay. I just need info on this:

Crashes my listen server
Code:
while(read_file(File, Line, Text, 63, len))

This doesn't
Code:
for(Line = 0; read_file(File, Line, Text, 32, len); Line++)
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 12-21-2005 , 19:52  
Reply With Quote #9

The first one will continually read the same line over and over again, because the read_file function returns the next line (or 0 if end of file), but you never fetch its return value.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 12-21-2005 , 22:29  
Reply With Quote #10

Code:
while(read_file( File , Line++ , Text, 63, len))

Also
With your code
Code:
 public test(id) {     new Map[64]     get_mapname(Map, 63)           new TgaFile[64], File     File = check_precache(Map, TgaFile, 63)     client_print(id, print_chat, "%s", File) }

it should be
Code:
 public test(id) {     new Map[64]     get_mapname(Map, 63)           new TgaFile[64], File     File = check_precache(Map, TgaFile, 63)     client_print(id, print_chat, "%s", TgaFile) }
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
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 16:13.


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