AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to format 2D Array? (https://forums.alliedmods.net/showthread.php?t=338933)

000 08-04-2022 06:43

How to format 2D Array?
 
Hi, I'd like to know how to format a 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.

Sillium 08-04-2022 10:06

Re: How to format 2D Array?
 
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.

000 08-04-2022 10:31

Re: How to format 2D Array?
 
Quote:

Originally Posted by Sillium (Post 2785570)
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

SpirT 08-15-2022 07:36

Re: How to format 2D Array?
 
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.

Grey83 08-15-2022 11:24

Re: How to format 2D Array?
 
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]);



000 08-21-2022 15:05

Re: How to format 2D Array?
 
Hi.

Quote:

Originally Posted by SpirT (Post 2786488)
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 (Post 2786507)
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.

Grey83 08-21-2022 16:23

Re: How to format 2D Array?
 
Quote:

Originally Posted by 000 (Post 2787124)
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.

000 08-22-2022 00:25

Re: How to format 2D Array?
 
Quote:

Originally Posted by Grey83 (Post 2787131)
No, not faster: with sizeof() size is determined at compile time and never calculated again.

Thanks!


All times are GMT -4. The time now is 09:22.

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