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

[SOLVED]Help with 2D arrays with nex syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Adel
Junior Member
Join Date: May 2016
Location: France
Old 07-07-2016 , 16:47   [SOLVED]Help with 2D arrays with nex syntax
Reply With Quote #1

Hello,

First, i searched on the forum and google for an answer but didn't get a solution.

My problem is the following:

I'm translating a plugin from old syntax to new syntax but i can't fix an error:

Code:
error 159: brackets after variable name indicate a fixed-size array, but size could not be determined - either specify sizes, an array initializer, or use dynamic syntax (such as 'char[] x')
I saw that i could this for instructions:

Code:
new String:temp[32]  become char[] temp = new char[32]
BUT nothing for functions, so how this could be fixed? (the 2nd parameter is the problem):

Code:
SomeFunc(int client, char buffer[][16], int target, char[] param1, char[] param2 = "")
{
    // Some stuffs
}
i tried these:

Code:
char[] buffer[16]
char[][16] buffer
but i have more errors:

Code:
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/string.inc(97) : error 181: function argument named 'caseSensitive' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/string.inc(111) : error 181: function argument named 'caseSensitive' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/dbi.inc(442) : error 181: function argument named 'persistent' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/helpers.inc(155) : error 181: function argument named 'immunity' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/sdktools_sound.inc(425) : error 181: function argument named 'updatePos' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/sdktools_sound.inc(464) : error 181: function argument named 'updatePos' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/sdktools_sound.inc(563) : error 181: function argument named 'updatePos' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/sdktools_sound.inc(648) : error 181: function argument named 'updatePos' differs from prototype
/home/adel/srv_css/cstrike/addons/sourcemod/scripting/include/sdktools_sound.inc(684) : error 181: function argument named 'updatePos' differs from prototype
Anyone has a solution please?

(PS: it's the first time i use html tags, so if there is a pb, i'm sorry ;) )

Last edited by Adel; 07-08-2016 at 08:30. Reason: Problem Solved
Adel is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 07-07-2016 , 17:04   Re: Help with 2D arrays with nex syntax
Reply With Quote #2

new String:tempString[32];
became
char tempString[32];

String:anotherString[];
became
char[] anotherString;

Why do you define the length on the second dimension?
char[][] buffer

I'm more curious on the include errors that you posted, do you have everything up-to-date?

Last edited by Mitchell; 07-07-2016 at 17:07.
Mitchell is offline
Adel
Junior Member
Join Date: May 2016
Location: France
Old 07-07-2016 , 17:15   Re: Help with 2D arrays with nex syntax
Reply With Quote #3

Hi mitchell, thx for your reply,

In fact i have a sp file and all its includes, the 2D array size is a choice of the plugin's author, i just try to translate.

With sm 1.6 branch, it compiled fine, but i had to update my server and then lot of errors appeared and as i wanted to modify a part of code, i decided to translate it all :/
Adel is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-07-2016 , 17:32   Re: Help with 2D arrays with nex syntax
Reply With Quote #4

Building on what Mitchell said, you can't specify just a single dimension in new style syntax. You have to either specify both or neither.

I may regret posting this part, but...

There are two types of arrays in Pawn: static (size is fixed during compile time) and dynamic (size is set at runtime).

In old style SourcePawn, they have identical syntax:

Code:
new Float:myFixedArray[MAXPLAYERS+1];
// Inside a method...
new Float:myDynamicArray[MaxClients+1];
However, they're different in new style syntax.

Code:
float myFixedArray[MAXPLAYERS+1];
// Inside a method...
float[] myDynamicArray = new float[MaxClients+1];
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Adel
Junior Member
Join Date: May 2016
Location: France
Old 07-07-2016 , 17:50   Re: Help with 2D arrays with nex syntax
Reply With Quote #5

By removing the size, all is fine (i hope there will be no pb during tests ^^).

The function is now:

Code:
SomeFunc(int client, char[][] buffer, int target, char[] param1, char[] param2 = "") {     // Some stuffs }
But after read mitchell's and powerlord's replies, i don't understand when a size could be given in 2D arrays, unless there is no need to fix a size in a function prototype? :/
It existed in old syntax but doesn't exist on new syntax?

Thank you guys for your help, the error doesn't appear in the console while compiling, i just need an answer to the questions just above .
Adel is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-07-2016 , 19:20   Re: Help with 2D arrays with nex syntax
Reply With Quote #6

Quote:
Originally Posted by Adel View Post
By removing the size, all is fine (i hope there will be no pb during tests ^^).

The function is now:

Code:
SomeFunc(int client, char[][] buffer, int target, char[] param1, char[] param2 = "") {     // Some stuffs }
But after read mitchell's and powerlord's replies, i don't understand when a size could be given in 2D arrays, unless there is no need to fix a size in a function prototype? :/
It existed in old syntax but doesn't exist on new syntax?

Thank you guys for your help, the error doesn't appear in the console while compiling, i just need an answer to the questions just above .
Function prototypes usually use dynamic arrays. When new style syntax came out it actually caused problems with the VoteHandler callback, which you can see now has two signatures instead of just one. The reason being that it had 2D arrays where one dimension was static and one was dynamic, but new-style syntax doesn't support that.

Side note: If you want to see a callback that takes fixed-size arrays, see sdktools_sound's NormalSHook although the new-api site seems to strip that from the documentation.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Adel
Junior Member
Join Date: May 2016
Location: France
Old 07-08-2016 , 08:24   Re: Help with 2D arrays with nex syntax
Reply With Quote #7

Oh ok, THANK YOU very much for these explanations, i close the thread as my problem is solved ;)
Adel is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 07-09-2016 , 01:01   Re: [SOLVED]Help with 2D arrays with nex syntax
Reply With Quote #8

Update your compiler, you need to search a little bit more ;u. char[][12] s_somevar works perfectly on 1.8.

Last edited by fakuivan; 07-09-2016 at 01:09.
fakuivan is offline
Adel
Junior Member
Join Date: May 2016
Location: France
Old 07-09-2016 , 09:16   Re: [SOLVED]Help with 2D arrays with nex syntax
Reply With Quote #9

Fakuivan, i use sourcemod 1.8 dev 5916, so my compiler is not the pb (even if there is a dev 5919, i don't think that a lot of things changed).
But thank you anyway .
Adel 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 15:23.


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