AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   how i can this -> new x[1][2] = {-1, ...}; (https://forums.alliedmods.net/showthread.php?t=293628)

client21 02-05-2017 10:21

how i can this -> new x[1][2] = {-1, ...};
 
new x[1] = {-1, ...}; // woohoo
new x[1][2] = {-1, ...}; // doh

R1KO 02-05-2017 10:23

Re: how i can this -> new x[1][2] = {-1, ...};
 
PHP Code:

new x[1][2] = {{-1, -1}}; 


client21 02-05-2017 10:37

Re: how i can this -> new x[1][2] = {-1, ...};
 
Yes, but:
new x[MAXPLAYERS + 1][2] = {{-1, -1}}; // doh

I must use cycle :\

Fyren 02-05-2017 12:19

Re: how i can this -> new x[1][2] = {-1, ...};
 
You can't initialize a multi-dimensional array like that. The best you can do is loop and set the values.

Kolapsicle 02-05-2017 12:24

Re: how i can this -> new x[1][2] = {-1, ...};
 
Is this what you are trying to do? (see spoiler)



Edit: I noticed you want the first dimension to be the size of maxplayers, as far as I know you would need to type out each dimension manually. It would be easier loop and set each value after the variable is created.

headline 02-05-2017 13:25

Re: how i can this -> new x[1][2] = {-1, ...};
 
PHP Code:

int x[MAXPLAYERS 1][2] = {{-1, -1}, ...}; 


Kolapsicle 02-05-2017 13:46

Re: how i can this -> new x[1][2] = {-1, ...};
 
Quote:

Originally Posted by Headline (Post 2493147)
PHP Code:

int x[MAXPLAYERS 1][2] = {{-1, -1}, ...}; 


I'd thought that might work, but I kept getting invalid expression errors when I tried it earlier. Have you successfully compiled a plugin using x?

headline 02-05-2017 13:48

Re: how i can this -> new x[1][2] = {-1, ...};
 
Quote:

Originally Posted by Kolapsicle (Post 2493158)
I'd thought that might work, but I kept getting invalid expression errors when I tried it earlier. Have you successfully compiled a plugin using x?

Yes. Try the latest 1.9 build

EDIT: Declared globally it's working, but locally it isn't

Kolapsicle 02-05-2017 14:02

Re: how i can this -> new x[1][2] = {-1, ...};
 
I still receive the compile error on the latest build 1.9.0:6044

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

int myArray[MAXPLAYERS 1][2] = { { -1, -}, ... }; // error 029: invalid expression, assumed zero

public void OnPluginStart()
{
    for (
int i 0sizeof(myArray); i++)
    {
        for (
int j 0sizeof(myArray[]); j++)
        {
            
PrintToConsole(0"myArray[%i][%i] = %i"ijmyArray[i][j]);
        }
    }



headline 02-05-2017 14:05

Re: how i can this -> new x[1][2] = {-1, ...};
 
Quote:

Originally Posted by Kolapsicle (Post 2493168)
I still receive the compile error on the latest build 1.9.0:6044

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

int myArray[MAXPLAYERS 1][2] = { { -1, -}, ... }; // error 029: invalid expression, assumed zero

public void OnPluginStart()
{
    for (
int i 0sizeof(myArray); i++)
    {
        for (
int j 0sizeof(myArray[]); j++)
        {
            
PrintToConsole(0"myArray[%i][%i] = %i"ijmyArray[i][j]);
        }
    }



I never tried actually indexing it, but that's weird that it doesn't give you an invalid expressions if you just declare it globally and then not use it. If you remove the entire OnPluginStart fwd it'll compile fine (which is why I thought it'd work)


All times are GMT -4. The time now is 14:34.

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