Raised This Month: $ Target: $400
 0% 

DataPacks(?) and Dynamic Arrays how to store some data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 03-02-2017 , 10:00   DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #1

From file i want to extract some data which are saved in scheme as below:

PHP Code:
    1
    
{
        
12341.5
        3
5171.5
        1
1535.0
    
}
    
2
    
{
        
31250.0
    
}
    
3
    
{
        
632131.5
        7
553321.5
    
}
    
4
    
{
        
641210.0
    

Now i want to keep it in Dynamic Arrays.

Numbers of data, and entries in data this always will be randomly. so how to save this?
Maybe some datapacks?

Last edited by grs4; 03-02-2017 at 10:01.
grs4 is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 03-02-2017 , 12:03   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #2

So.. if someone will have common problem, here is a solution.


PHP Code:

new Array:g_Array;

public 
plugin_init()
{
   
g_Array ArrayCreate(150); 50 is max data

before loading our data:

PHP Code:
new Array:aTempArray ArrayCreate(15); //5 is max entries in every data 
at entry load

PHP Code:
new DataPack:entryInfo CreateDataPack();
WritePackCell(entryInfovalueA);
WritePackCell(entryInfovalueB);
WritePackCell(entryInfovalueC);
WritePackCell(entryInfovalueD);
WritePackFloat(entryInfovalueE);
                
ArrayPushCell(aTempArraywaveRoundInfo); 
at new data load

PHP Code:
ArrayPushCell(g_ArrayaTempArray);
aTempArray ArrayCreate(15); 
And if you want to load all data from arrays

PHP Code:

public readConfig()
{
    new 
size1 ArraySize(g_Array);
    for(new 
0size1i++)
    {
        new Array:array = 
ArrayGetCell(g_Arrayi);
        new 
size2 ArraySize(array);
        
        
log_amx("Data %d"i+1);
        
        for(new 
0size2j++)
        {
            new 
DataPack:pack DataPack:ArrayGetCell(array, j);
            
ResetPack(pack);
            
log_amx("entry: %d / %d"j+1pack);
            for(new 
05k++)
            {
                if(
!= 4)
                {
                    
log_amx("%d: %d"k+1ReadPackCell(pack));
                }
                else
                {
                    
log_amx("%d: %0.2f"k+1ReadPackFloat(pack));
                }
            }
            
DestroyDataPack(pack);
        }
    }

result:

PHP Code:

L 03
/02/2017 18:04:02: [lw.amxxData 1
L 03
/02/2017 18:04:02: [lw.amxxentry1
L 03
/02/2017 18:04:02: [lw.amxx11
L 03
/02/2017 18:04:02: [lw.amxx25
L 03
/02/2017 18:04:02: [lw.amxx32
L 03
/02/2017 18:04:02: [lw.amxx41
L 03
/02/2017 18:04:02: [lw.amxx52.50
L 03
/02/2017 18:04:02: [lw.amxxData 2
L 03
/02/2017 18:04:02: [lw.amxxentry2
L 03
/02/2017 18:04:02: [lw.amxx15
L 03
/02/2017 18:04:02: [lw.amxx25
L 03
/02/2017 18:04:02: [lw.amxx32
L 03
/02/2017 18:04:02: [lw.amxx41
L 03
/02/2017 18:04:02: [lw.amxx52.50
L 03
/02/2017 18:04:02: [lw.amxxentry3
L 03
/02/2017 18:04:02: [lw.amxx11
L 03
/02/2017 18:04:02: [lw.amxx21
L 03
/02/2017 18:04:02: [lw.amxx32
L 03
/02/2017 18:04:02: [lw.amxx44
L 03
/02/2017 18:04:02: [lw.amxx50.00 
And also remember to delete all at plugin end, if you dont do this, server will be crashed at every map change. (Because datapacks are in memory)

PHP Code:
public plugin_end()
{
    new 
size1 ArraySize(g_Array);
    
    for(new 
0size1i++)
    {
        new Array:array = 
ArrayGetCell(g_Arrayi);
        new 
size2 ArraySize(array);
        
        for(new 
0size2j++)
        {
            new 
DataPack:pack DataPack:ArrayGetCell(array, j);
            
DestroyDataPack(pack);
        }
        
ArrayDestroy(array);
    }
    
    
ArrayDestroy(g_Array);

For me, is very bad, that I Have to know size of DataPack, there is no something like "DataPackSize" and "DataPackGetType" (<- This should return a type of data in current position.

Last edited by grs4; 03-02-2017 at 13:37.
grs4 is offline
yas17sin
Veteran Member
Join Date: Oct 2016
Location: Morocco/Sale
Old 03-02-2017 , 12:21   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #3

this should be in Code Snippets :/.
__________________
FINISHED WORKING ON : Attack On Titan Mod (100% Done).

FB Acc : FaceBook Account.

pic: http://prntscr.com/fszkke not good quality
yas17sin is offline
Send a message via ICQ to yas17sin
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-03-2017 , 03:20   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #4

Using another Array to handle an array (since you have a fixed number of values, 5) seems more suit than using datapack here.
__________________
Arkshine is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 03-03-2017 , 03:48   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #5

With datapacks are more troubles than i knew it can be.

All datapacks which i'm creating has always 5 values
when i want to read a value from postion no. 1

log
PHP Code:

L 03
/03/2017 09:41:16Datapack operation is invalid.
L 03/03/2017 09:41:16: [AMXXDisplaying debug trace (plugin "lw.amxx"version "1.0")
L 03/03/2017 09:41:16: [AMXXRun time error 10native error (native "ReadPackCell")
L 03/03/2017 09:41:16: [AMXX]    [0lw.sma::getValueFromPack (line 120)
L 03/03/2017 09:41:16: [AMXX]    [1lw.sma::test2 (lin 
PHP Code:
stock any:getValueFromPack(&DataPack:packeDataInfo:info)
{
    
SetPackPosition(pack_:info);
    
//log_amxx firstly returns: 11 0 0 0
    // then: 11 1 9 0
   // so, why it did not set pack postion to "1" as "_:info" ?
    
log_amx("%d %d %d %d"pack_:infoGetPackPosition(pack), IsPackEnded(pack));
    return 
info == DATA_VALUE_FLOAT ReadPackFloat(pack) : ReadPackCell(pack);

Also, as you told I changed from DataPacks to Arrays. Now everything works great. But i'm interesting in this problem, what is causing it. Why i changed postion to "9" when it should set to "1"

Last edited by grs4; 03-03-2017 at 03:55.
grs4 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-03-2017 , 05:47   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #6

Because you don't read the documentation. You misunderstand SetPackPosition(), it expects a value from GetPackPosition(), not an arbitrary index. It might be confusing, we should probably do like SourceMod (they have the same api) and adding a tag for position to both natives.
__________________
Arkshine is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 03-03-2017 , 06:19   Re: DataPacks(?) and Dynamic Arrays how to store some data
Reply With Quote #7

read I read.
Apperantly I did not undestood. Thanks a lot for help
grs4 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 02:31.


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