Raised This Month: $ Target: $400
 0% 

Solved Something about dynamic arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdelwahab
Member
Join Date: Aug 2019
Old 04-12-2024 , 22:29   Something about dynamic arrays
Reply With Quote #1

Hello,
so here is the thing, i know what it does but i don't understand how it does it if someone can explain it would be much appreciated, Thanks!
PHP Code:
new Array:GlobalArray;
public 
plugin_init() {
    new 
string[][] =
    {
        
"String 1",
        
"String 2",
        
"String 3",
        
"String 4"
    
}
    new Array:
StringHolder ArrayCreate(321);
    for(new 
i=0sizeof(string); i++)
        
ArrayPushString(StringHolderstring[i]);
    
// we pass an array :/
    
ArrayPushCell(GlobalArrayStringHolder);

    
arraytest()
}
public 
plugin_precache() GlobalArray =  ArrayCreate(11);
arraytest(){
    new  Array:
AnotherArray;AnotherArray ArrayGetCell(GlobalArray0);
    if(
AnotherArray != Invalid_Array){
        new 
szString[32];
        for(new 
0ArraySize(AnotherArray); i++){
            
ArrayGetString(AnotherArrayiszStringcharsmax(szString));
            
server_print(szString);
        }
    }


Last edited by HamletEagle; 04-13-2024 at 06:55. Reason: Restore to previous version.
abdelwahab is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 04-12-2024 , 23:31   Re: Something about dynamic arrays
Reply With Quote #2

Basic 2D arrays have a set size that cannot change, while dynamic arrays can adjust their size during runtime. Basic 2D arrays are best when you know the size beforehand and it won't change. Dynamic arrays are more flexible for changing sizes as needed.
Natives are explained and given examples
https://forums.alliedmods.net/showthread.php?t=249602
https://www.amxmodx.org/api/cellarray/__functions
__________________
bigdaddy424 is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-13-2024 , 00:25   Re: Something about dynamic arrays
Reply With Quote #3

Its not that thing i was talking about these lines
PHP Code:
ArrayPushCell(GlobalArrayStringHolder);
new Array:
AnotherArray;AnotherArray ArrayGetCell(GlobalArray0);
ArrayGetString(AnotherArrayiszStringcharsmax(szString)); 
what does it mean when i did push the array
abdelwahab is offline
Old 04-13-2024, 00:29
fysiks
This message has been deleted by fysiks. Reason: misunderstood the question
abdelwahab
Member
Join Date: Aug 2019
Old 04-13-2024 , 00:41   Re: Something about dynamic arrays
Reply With Quote #4

I've read the tutorial long time ago and i know how to make dynamic arrays and use them, the thing that is confusing me when i push an dyn array that has strings into an dyn array ( 1 cell ) what happens,
and when i want to know the strings i put into that dyn array
i use this
PHP Code:
new Array:AnotherArray;AnotherArray ArrayGetCell(GlobalArray0); 
Srrry i'm not good with explaining
usage example ?
for example i created skins menu with ini file and there is 6 type each skin has 1...5 skins
[SKIN 1]
Skins = myskin1, ....ect
[SKIN 2]...
when u select u get random skins from the total skins.
what i don't really understand is that how that works cause i know how to do it i've seen the way in zp50_zombie_class system
abdelwahab is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-13-2024 , 02:44   Re: Something about dynamic arrays
Reply With Quote #5

Nvm i understood it.
abdelwahab is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-13-2024 , 06:57   Re: Something about dynamic arrays
Reply With Quote #6

Quote:
Originally Posted by abdelwahab View Post
Nvm i understood it.
Please do not delete your posts. Also, if you figure out the solution, post it so that others can benefit from it in the future. It is selfish to come to an open source community, ask questions and then delete the topic or not post the solution.
__________________
HamletEagle is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-13-2024 , 10:29   Re: Something about dynamic arrays
Reply With Quote #7

Well yea, thats the thing i think my post is useless and if u can delete it i just didn't know that u can pass an dyn array into dyn array
abdelwahab is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-13-2024 , 10:32   Re: Something about dynamic arrays
Reply With Quote #8

Other people may be in the same boat as you, and find your post. Problem solved.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-13-2024 , 16:50   Re: Something about dynamic arrays
Reply With Quote #9

I suspect that the important thing to know about dynamic arrays is that the array handle is just a reference to the actually data and it can be stored like you would do with any other variable. This is why, you can store many of these array handles into a dynamic array making a pseudo-2D dynamic array.
__________________
fysiks is offline
abdelwahab
Member
Join Date: Aug 2019
Old 04-14-2024 , 03:15   Re: Something about dynamic arrays
Reply With Quote #10

Thanks, that's exactly what i needed to hear!
abdelwahab 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 05:39.


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