Raised This Month: $344 Target: $400
 86%   Almost there!

Solved How to 2D Array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
000
Senior Member
Join Date: Jul 2022
Old 08-04-2022 , 06:43   How to 2D Array?
Reply With Quote #1

Hi, I'd like to know how to format with 2D array.

I tried:

PHP Code:
char 2DArray[3][6], 2DArray2[3][6], sValue[24], Formatted[24];

ExplodeString(sValue","2DArray36);
ExplodeString(sValue","2DArray236);

FormatEx(Formattedsizeof(Formatted), "%s %s"2DArray[0], 2DArray2[2]); 
Error:
error: 032: array index out of bounds (variable "2DArray")
error: 032: array index out of bounds (variable "2DArray2")

Best regards.

Last edited by 000; 08-27-2022 at 17:04. Reason: Changed title since the old one was misleading.
000 is offline
Sillium
AlliedModders Donor
Join Date: Sep 2008
Location: Germany
Old 08-04-2022 , 10:06   Re: How to format 2D Array?
Reply With Quote #2

If you find a solution for your problem you should post it instead of blanking your thread.
That way others doing the same mistake find it and can learn from it.
__________________
brb, dishes have developed their own language and are talking to the garbage about overthrowing me... i must correct this

www.unterwasserpyromanen.de

Last edited by Sillium; 08-04-2022 at 10:07.
Sillium is offline
000
Senior Member
Join Date: Jul 2022
Old 08-04-2022 , 10:31   Re: How to format 2D Array?
Reply With Quote #3

Quote:
Originally Posted by Sillium View Post
If you find a solution for your problem you should post it instead of blanking your thread.
That way others doing the same mistake find it and can learn from it.
typo

Last edited by 000; 08-04-2022 at 10:49.
000 is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 08-15-2022 , 07:36   Re: How to format 2D Array?
Reply With Quote #4

For the ones that are still trying to find a solution, sizeof(MyArray) will retrieve the maximum values that can be stored in the array and sizeof(MyArray[]) will give the maximum length of the value in the array.
__________________
SpirT is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-15-2022 , 11:24   Re: How to format 2D Array?
Reply With Quote #5

But you can't compile the plugin if you use variables with a name starting with a number.

This code will compiled:
PHP Code:
public void OnPluginStart()
{
    
char Array[3][6], Array2[3][6], sValue[24] = ""Formatted[24];

    
ExplodeString(sValue",", Array, sizeof(Array), sizeof(Array[]));
    
ExplodeString(sValue","Array2sizeof(Array2), sizeof(Array2[]));

    
FormatEx(Formattedsizeof(Formatted), "%s %s", Array[0], Array2[2]);

__________________
Grey83 is offline
000
Senior Member
Join Date: Jul 2022
Old 08-21-2022 , 15:05   Re: How to format 2D Array?
Reply With Quote #6

Hi.

Quote:
Originally Posted by SpirT View Post
For the ones that are still trying to find a solution, sizeof(MyArray) will retrieve the maximum values that can be stored in the array and sizeof(MyArray[]) will give the maximum length of the value in the array.
The problem was a typo in one of the arrays where I had entered a higher number in and thus having index out of bounds. But for this thread I had rewritten it (unknowningly that this time there was no typo).

Also: I didn't use sizeof() to spare some time. And I think without it it is faster as well...

Quote:
Originally Posted by Grey83 View Post
But you can't compile the plugin if you use variables with a name starting with a number.

This code will compiled:
PHP Code:
public void OnPluginStart()
{
    
char Array[3][6], Array2[3][6], sValue[24] = ""Formatted[24];

    
ExplodeString(sValue",", Array, sizeof(Array), sizeof(Array[]));
    
ExplodeString(sValue","Array2sizeof(Array2), sizeof(Array2[]));

    
FormatEx(Formattedsizeof(Formatted), "%s %s", Array[0], Array2[2]);

Yes, I didn't mind.

Also I want to say that the title might be misleading since it isn't about formatting but arrays.

I guess, I picked the title because I was thinking about formating.


Greets.

Last edited by 000; 08-22-2022 at 00:24.
000 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-21-2022 , 16:23   Re: How to format 2D Array?
Reply With Quote #7

Quote:
Originally Posted by 000 View Post
Also: I didn't use sizeof() to spare some time. And I think without it it is faster as well...
No, not faster: with sizeof() size is determined at compile time and never calculated again.
__________________
Grey83 is offline
000
Senior Member
Join Date: Jul 2022
Old 08-22-2022 , 00:25   Re: How to format 2D Array?
Reply With Quote #8

Quote:
Originally Posted by Grey83 View Post
No, not faster: with sizeof() size is determined at compile time and never calculated again.
Thanks!
000 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 02:01.


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