Raised This Month: $ Target: $400
 0% 

Need help parsing a large number of variables from a string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
BAILOPAN
Join Date: Jan 2004
Old 07-10-2004 , 04:12  
Reply With Quote #2

parse() is a pretty bad function, I'd recommend not using it for anything personally... for 0.20 I've replaced it with a nicer function called strbreak().

The problem with parse is that it's not reentrant or loop-able, and your system of using like 30 skillx[2] variables is not the brightest idea either

Here is a suggestion, just make sure to reserve some extra memory for this plugin

Code:
#define MAX_SKILLS 41 //reserve 64K of memory #pragma dynamic 16384 new playerid[32] new playername[32] new ip[32] new xp[32] new skills[MAX_SKILLS][2] new pdata[512], i new temp1[512], temp2[512] get_vaultdata(pkey, pdata, 511) str_break(pdata, playerid, temp1, 32, 511) str_break(temp1, xp, temp2, 7, 511) new s = strlen(temp2) new j = 1, k = 0 for (i=0; i<s; i++) {    //check for space or quote    if (temp2[i] == 32 || temp2[i] == 34)       j++    else       skills[j][k++] = temp2[i] } stock str_break(const String[], Left[], Right[], lMax, rMax) {     new bool:quote_flag = false     new bool:done_flag = false     new left_pos = 0     new right_pos = 0     new i     new hold[] = "'^"x"         copy(Left, lMax, "")     copy(Right, rMax, "")         for (i=0; i<=strlen(String)-1; i++) {         if (equali(String[i], "^"", 1)) {             quote_flag = true         } else if ((equali(String[i], "^"", 1)) && (quote_flag)) {             quote_flag = false         }         if ((equali(String[i], " ", 1)) && (!quote_flag) && (!done_flag)) {             done_flag = true             i++         }         if (!done_flag && !equali(String[i], "^"", 1)) {             if (left_pos < lMax) {                 setc(Left[left_pos], 1, String[i])                 if (equali(Left[left_pos], "'", 1)) {                     setc(Left[left_pos], 1, hold[1])                 }                 left_pos++             }         } else {             if (right_pos < rMax && !equali(String[i], "^"", 1)) {                 setc(Right[right_pos], 1, String[i])                 if (equali(Right[right_pos], "'", 1)) {                     setc(Right[right_pos], 1, hold[1])                 }                 right_pos++             }         }     }     Left[left_pos] = 0     Right[right_pos] = 0         return true }

I have no clue if this will work, but the idea is to make smart character parsing instead of relying on outside functions

One of the advantages to having C style strings
__________________
egg
BAILOPAN is offline
 



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:53.


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