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

explodestring trouble


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JOSHBOX
Junior Member
Join Date: Sep 2010
Old 11-10-2010 , 20:41   explodestring trouble
Reply With Quote #1

Hi,

I am trying to rewrite a large portion of one of my plugins so that it will read certain details from a file on plugin start, rather than having me recompile the entire plugin for minor changes. I looked into keyvalues but it seems at this point that a 2 dimensional string array would be my best bet since it is read very very frequently.

I have read for hours on the subject and I cannot figure out how to get my string from the explodestring buffer to my primary array. As you can see below, I tried a simple array=buffer; statement but I believe that is invalid for arrays. Can anyone point me in the right direction?

PHP Code:

while(!IsEndOfFile(hFile))
{
    
ReadFileLine(hFilestrLinesizeof(strLine));
    new 
String:strBreak[2][32];
    
ExplodeString(strLine";"strBreaksizeof(strBreak), sizeof(strBreak[]));
        
    
parray[fLines][0][]=strBreak[0][]
    
parray[fLines][1][]=strBreak[1][]

    
fLines++;

JOSHBOX is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-11-2010 , 20:20   Re: explodestring trouble
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=90772
__________________
Silvers is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 11-11-2010 , 20:20   Re: explodestring trouble
Reply With Quote #3

Why not explode directly to your "primary" array? Also, see strcopy.
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-11-2010 , 20:26   Re: explodestring trouble
Reply With Quote #4

You can assign same-sized arrays to each other.
Fyren is offline
JOSHBOX
Junior Member
Join Date: Sep 2010
Old 11-11-2010 , 20:53   Re: explodestring trouble
Reply With Quote #5

Quote:
Originally Posted by meng View Post
Why not explode directly to your "primary" array? Also, see strcopy.
I would like to explode directly to my primary array but the explodestring function description calls for a 2D array. Do you know of a way around this?
JOSHBOX is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 11-11-2010 , 22:20   Re: explodestring trouble
Reply With Quote #6

Maybe...
PHP Code:
ExplodeString(strLine";"parray[fLines], sizeof(parray[]), sizeof(parray[][])); 
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
JOSHBOX
Junior Member
Join Date: Sep 2010
Old 11-24-2010 , 16:41   Re: explodestring trouble
Reply With Quote #7

I think I may be going about this in the wrong way. What I am trying to do is, read two separate items per line from a text file, at the end of the file I want to have accomplished two things:

1) Count the amount of lines I just read in the file (I tried this by incrementing fLines in my example)
2) Store both items (on each line) so that they can be referenced individually, but always as a set (These will contain a STEAMID and a string, I tried to accomplish this with a 3D array but it is turning out to be more complex that I think it needs to be)

I looked into keyvalues as an alternative but I only have a few items that need to be stored, and they will be accessed very frequently, so I believe storing this information as strings would be faster for this purpose.

Can anyone advise me on a better approach to accomplish my goals?
JOSHBOX is offline
JOSHBOX
Junior Member
Join Date: Sep 2010
Old 11-30-2010 , 18:04   Re: explodestring trouble
Reply With Quote #8

Sorry, I'm not trying to bump here, but I am still stuck on this. If anyone could advise me on a better approach than this overly complicated 3d array. Like I mentioned before, this data will be accessed many times per minute using a three-expression for loop.
JOSHBOX is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 11-30-2010 , 18:33   Re: explodestring trouble
Reply With Quote #9

Have a look at keyvalues again. Use keyvalue format in files. When loading, parse them into an enum structure with arrays (enum structure example: http://forums.alliedmods.net/showthr...96#post1023296).

Then you can loop through and read/write to arrays without having to worry about performance.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 11-30-2010 , 23:20   Re: explodestring trouble
Reply With Quote #10

What he said!!! ^ ^ ^
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
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 15:57.


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