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

reading file into string array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-19-2009 , 11:47   reading file into string array
Reply With Quote #1

I used to know how to do this, can't seem to remember.

Text file would look something like this (keyvalues)

PHP Code:
Pwnt
{
    
"lol"
    "wtf"
    "bbq"
    "h4x"
    "amount"
    
{
        
"4"
    
}
}
LUL
{
    
"zomg"
    "wut button is fly up"
    "amount"
    
{
        
"2"
    
}

I need to read those into a string array so after load it would "look" like this:

PHP Code:
new String:pwnt[amount][] = {
    
"lol",
    
"wtf",
    
"bbq",
    
"h4x"
};
new 
String:LUL[amount][] = {
    
"zomg"
     "wut button is fly up"
}; 
Understand what I'm trying to ask?

Last edited by Dragonshadow; 09-19-2009 at 12:23.
Dragonshadow is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-19-2009 , 14:18   Re: reading file into string array
Reply With Quote #2

halp. I'm stuck in my plugin until I can get this done.
Dragonshadow is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-20-2009 , 07:39   Re: reading file into string array
Reply With Quote #3

bump
Dragonshadow is offline
Frus
Senior Member
Join Date: Aug 2009
Old 09-20-2009 , 07:41   Re: reading file into string array
Reply With Quote #4

There's a whole wiki page dedicated to keyvalues, I suggest reading it

http://wiki.alliedmods.net/KeyValues...d_Scripting%29
Frus is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-20-2009 , 07:51   Re: reading file into string array
Reply With Quote #5

I've already read the entire scripting section of the wiki. The only thing that even comes remotely close to it is

http://wiki.alliedmods.net/KeyValues...erative_Lookup

Though I have figured out its going to need to be like this instead:
PHP Code:
Pwnt
{
    
"phrases"
    
{
        
"lol"
        "wtf"
        "bbq"
        "h4x"
    
}
    
"amount"
    
{
        
"4"
    
}
}
LUL
{
    
"phrases"
    
{
        
"zomg"
        "wut button is fly up"
    
}
    
"amount"
    
{
        
"2"
    
}

</span></span>

Last edited by Dragonshadow; 09-20-2009 at 08:02.
Dragonshadow is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-20-2009 , 14:22   Re: reading file into string array
Reply With Quote #6

I don't use KeyValves for reading/writing data personally. I can offer you an alternative, although you've probably designed yours around KeyValves, which I can't really help you with.

http://forums.alliedmods.net/showthread.php?t=102924

If you want an alternative, although I'd doubt it would help you much.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Frus
Senior Member
Join Date: Aug 2009
Old 09-20-2009 , 15:37   Re: reading file into string array
Reply With Quote #7

Quote:
Originally Posted by Dragonshadow View Post
I've already read the entire scripting section of the wiki. The only thing that even comes remotely close to it is

http://wiki.alliedmods.net/KeyValues...erative_Lookup

Though I have figured out its going to need to be like this instead:
PHP Code:
Pwnt
{
    
"phrases"
    
{
        
"lol"
        "wtf"
        "bbq"
        "h4x"
    
}
    
"amount"
    
{
        
"4"
    
}
}
LUL
{
    
"phrases"
    
{
        
"zomg"
        "wut button is fly up"
    
}
    
"amount"
    
{
        
"2"
    
}

</span></span>
You're still missing a very key part of a keyvalues structure. If you are using keyvalues.

It is, the key. You've got lots of sections and values, but no keys. Also, your sections need to be in quotes.

Code:
"main"
{
    "pwnt"
    {
        "phrase1"  "lol"
        ....
        "amount"  "4"
    }
    ...
}
and
Code:
"main"
{
    "pwnt"
    {
        "phrase"  "lol,wtf,..."
        "amount"  "4"
    }
    ...
}
are 2 ways to make a valid keyvalue file for what you want (even though keyvalues probably isn't the best way to do what you want). The second one would require you to use ExplodeString() to get each string in the list into an array of strings.

Like I said, it's better when you read the wiki article instead of just skimming for a magic command.
Frus is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-20-2009 , 17:48   Re: reading file into string array
Reply With Quote #8

Quote:
Originally Posted by Frus View Post
Like I said, it's better when you read the wiki article instead of just skimming for a magic command.
There's laziness, and then there is 'too much hassle to be worth it'.

Magic Commands, your brains way of saying the current commands are too much work and are too confusing to be worth the effort. And chances are, if you're thinking that, another coder is gunna be saying the same thing.

Performing an action isn't simplified enough until it comes in a single, aptly named function that takes two arguments; where, and what.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 09-20-2009 , 17:57   Re: reading file into string array
Reply With Quote #9

Quote:
PHP Code:
new String:pwnt[amount][] = {
    
"lol",
    
"wtf",
    
"bbq",
    
"h4x"
};
new 
String:LUL[amount][] = {
    
"zomg"
     "wut button is fly up"
}; 

That's not possible.

It's possible to generate ADT arrays populated with that data. It will require keyvalues.inc functions to get the data and adt_array.inc functions to store it.
__________________
Greyscale is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-21-2009 , 08:48   Re: reading file into string array
Reply With Quote #10

Hmm, never messed with adt arrays.
Dragonshadow is offline
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 20:17.


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