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

Passing 2D array via natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 03:17   Passing 2D array via natives
Reply With Quote #1

Is there still no way to properly pass 2D arrays via a native ?
PHP Code:
new asString[8][64]

asString[0] = "String number one"
asString[1] = "String number two"
asString[2] = "String number three"

cn_send_via_native(asString
PHP Code:

public native_send_via_native(plugin_idnum_params)
{
???
???

__________________

Last edited by Depresie; 12-12-2017 at 03:53.
Depresie is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-12-2017 , 05:27   Re: Passing 2D array via natives
Reply With Quote #2

Search about [get|set]_array.
CrazY. is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 05:40   Re: Passing 2D array via natives
Reply With Quote #3

You didn't understand what i am trying to do

Also, is there anyway to get how many times a character appears in a string other than creating a for loop and checking each cell manually ?
__________________

Last edited by Depresie; 12-12-2017 at 05:42.
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-12-2017 , 06:57   Re: Passing 2D array via natives
Reply With Quote #4

Try with:
PHP Code:
native get_array_2d(paramdest[][], size) = get_array;
// To use it:
new myArray[8][64];
get_array_2d(1myArraysizeof(myArray) + sizeof(myArray) * sizeof(myArray[]));
// Or define something like this to not have to use that math every time and possibly make a mistake
#define 2D_ARRAY_LENGTH(%0) (sizeof(%0) + sizeof(%0) * sizeof(%0[])) 
It's quite hacky but should work.

Quote:
Originally Posted by Depresie View Post
Also, is there anyway to get how many times a character appears in a string other than creating a for loop and checking each cell manually ?
Should be a new thread. As far as I know, that's the only way. You can use Regex but that will just be slower.

Last edited by klippy; 12-12-2017 at 07:08.
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 08:11   Re: Passing 2D array via natives
Reply With Quote #5

Ahm, but how do i retrieve the data from the native ?

Also, this would be an overkill when sending 20 strings right ?

PHP Code:
public plugin_natives()
{
    
register_native("get_array_2d""native_array_2d")
}

public 
native_array_2d(plugin_idnum_params)
{
    ??


__________________
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-12-2017 , 08:26   Re: Passing 2D array via natives
Reply With Quote #6

You didn't get my post.

PHP Code:
#define ARRAY_LENGTH_2D(%0) (sizeof(%0) + sizeof(%0) * sizeof(%0[]))
native get_array_2d(paramdest[][], size) = get_array;

public 
plugin_natives()
{
    
register_native("pass_2d_array""native_pass_2d_array");
}

// native pass_2d_array(2dArray[8][64]);
public native_pass_2d_array(pluginIdparamCount)
{
    new 
myArray[8][64];
    
get_array_2d(1myArrayARRAY_LENGTH_2D(myArray));

Be aware that you have to pass an array of [8][64] size or things will go bad. That's why you specify it in the native param.

Last edited by klippy; 12-12-2017 at 08:28.
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-12-2017 , 10:36   Re: Passing 2D array via natives
Reply With Quote #7

Quote:
Originally Posted by KliPPy View Post
Try with:
PHP Code:
native get_array_2d(paramdest[][], size) = get_array;
// To use it:
new myArray[8][64];
get_array_2d(1myArraysizeof(myArray) + sizeof(myArray) * sizeof(myArray[]));
// Or define something like this to not have to use that math every time and possibly make a mistake
#define 2D_ARRAY_LENGTH(%0) (sizeof(%0) + sizeof(%0) * sizeof(%0[])) 
Please no
__________________

Last edited by HamletEagle; 12-12-2017 at 10:36.
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-12-2017 , 10:53   Re: Passing 2D array via natives
Reply With Quote #8

Quote:
Originally Posted by HamletEagle View Post
Please no
Not encouraging the use of that ofc. Also please don't release a plugin using that. You can just use an Array: of strings anyway.

Last edited by klippy; 12-12-2017 at 10:55.
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-12-2017 , 11:00   Re: Passing 2D array via natives
Reply With Quote #9

Mhmm, i was thinking of creating a string, containing all the other strings
The beginning each string to be noted with &
Send it via native
Then loop through all chars and see how many strings there are ( how many & we find )
Then copy each string to a new 2d array

But i don't know how will that impact the performance
For example creating/sending an array of 1024/2048 chars, then loop through each char.. wouldn't it kill the server ?

What i'm trying to do for better understanding the impact on the performance

1. Create a native to allow the user to play a sequence of sounds on x interval
2. Create a native to allow the user to show a sequence of messages on x interval
3. Create a "new menu system" to play some sounds on opening/selection and modify some text inside it
__________________

Last edited by Depresie; 12-12-2017 at 11:07.
Depresie is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-12-2017 , 12:47   Re: Passing 2D array via natives
Reply With Quote #10

In your case you just should use CellArray; and send the Array handler via native.
__________________
My English is A0
E1_531G 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 13:51.


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