Raised This Month: $ Target: $400
 0% 

[help] cellarray.inc


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lightokun
Member
Join Date: Oct 2009
Old 11-15-2010 , 08:57   [help] cellarray.inc
Reply With Quote #1

Hello again.
Now i need help with cellarray.inc.

I want to store data (like id, key=> value) in array and easy access to it.
But i wasted a lot of time trying to do it myself.

I need to create array for each player like this to retrieve data ("key" and "value")
Code:
player_id => array(
        string_key => string_value,
        another_string_key => another_string_value
),
another_player_id =>
        string_key => string_value,
        another_string_key => another_string_value
So, anybody can explain or write a code how to create dynamic array with 32 cells which contains data like "key"=>"value" n times?

Basically i want to store for each player id their settings on connect in array like: nvg color, language, hat and etc. data which is loading from DB and i don't want to create a lot of arrays for this (data can be dynamic, like some player have "nvg" key, another don't)
__________________

Last edited by Lightokun; 11-15-2010 at 09:03.
Lightokun is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-15-2010 , 12:50   Re: [help] cellarray.inc
Reply With Quote #2

You need to look at celltrie.inc for this.
CellArrays only use integer keys like normal arrays, but CellTries use string keys.
The problem with CellTries is that you can't iterate through all of the keys, so a combination of both would be needed.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-15-2010 , 13:15   Re: [help] cellarray.inc
Reply With Quote #3

Quote:
The problem with CellTries is that you can't iterate through all of the keys, so a combination of both would be needed.
CellTravTrie exists for that.
__________________
Arkshine is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-15-2010 , 19:21   Re: [help] cellarray.inc
Reply With Quote #4

It looks like, to me, that he needs an array of Tries (one Trie for each player).

Depending on your actual implementation it's possible that you could just use an Enum/data structure and an array (probably best if your list of keys is not too many).

Something like this:

PHP Code:
enum KEYS {
    
KEY1[32],
    
KEY2[32]
}

new 
my_array[33][KEYS]

client_print(idprint_chatmy_array[id][KEY1]) 
Correct me if I'm wrong on the data structure.

If he uses Tries I don't think he would need to traverse it from his explaination.
__________________

Last edited by fysiks; 11-15-2010 at 19:31.
fysiks is offline
Lightokun
Member
Join Date: Oct 2009
Old 11-16-2010 , 00:44   Re: [help] cellarray.inc
Reply With Quote #5

Ok, i'll try both methods later and post the result. Thanks for help.
__________________
Lightokun is offline
Lightokun
Member
Join Date: Oct 2009
Old 11-16-2010 , 03:32   Re: [help] cellarray.inc
Reply With Quote #6

Solved!
Thanks to all.

Some code example:
Code:
public parse_cfg(id,settings[]) {
    ...
    for(i=0; i<=max; i++) {
        re = regex_match(tmp[i], SETTINGS_PATTERN, num, error, 127)
        if (re >= REGEX_OK) {
            regex_substr(re, 1, str2, 63)
            regex_substr(re, 2, str3, 63)
            regex_free(re)
            
            TravTrieSetString(PlayerData, str2, str3)
        }
    }
    
    TravTrieSetCellEx(PlayerArray, id, PlayerData)
}

public ep_get_settings_param(id, settings_name[], search[]) {    
    new TravTrie:array
    static value[64]
    TravTrieGetCellEx(PlayerArray,id,array)
    TravTrieGetString(array,search,value,63)
    log_amx("value: %s",value)
}
__________________

Last edited by Lightokun; 11-16-2010 at 04:32.
Lightokun is offline
Reply


Thread Tools
Display Modes

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 11:21.


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