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

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
client21
Senior Member
Join Date: Apr 2013
Old 02-05-2017 , 10:21   how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #1

new x[1] = {-1, ...}; // woohoo
new x[1][2] = {-1, ...}; // doh
client21 is offline
R1KO
Member
Join Date: Sep 2013
Old 02-05-2017 , 10:23   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #2

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

Last edited by R1KO; 02-05-2017 at 10:23.
R1KO is offline
Send a message via Skype™ to R1KO
client21
Senior Member
Join Date: Apr 2013
Old 02-05-2017 , 10:37   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #3

Yes, but:
new x[MAXPLAYERS + 1][2] = {{-1, -1}}; // doh

I must use cycle :\
client21 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 02-05-2017 , 12:19   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #4

You can't initialize a multi-dimensional array like that. The best you can do is loop and set the values.
Fyren is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-05-2017 , 12:24   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #5

Is this what you are trying to do? (see spoiler)

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.

Last edited by Kolapsicle; 02-05-2017 at 12:45.
Kolapsicle is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-05-2017 , 13:25   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #6

PHP Code:
int x[MAXPLAYERS 1][2] = {{-1, -1}, ...}; 
headline is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-05-2017 , 13:46   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #7

Quote:
Originally Posted by Headline View Post
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?
Kolapsicle is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-05-2017 , 13:48   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #8

Quote:
Originally Posted by Kolapsicle View Post
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

Last edited by headline; 02-05-2017 at 13:57.
headline is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-05-2017 , 14:02   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #9

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]);
        }
    }


Last edited by Kolapsicle; 02-05-2017 at 14:03.
Kolapsicle is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 02-05-2017 , 14:05   Re: how i can this -> new x[1][2] = {-1, ...};
Reply With Quote #10

Quote:
Originally Posted by Kolapsicle View Post
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)

Last edited by headline; 02-05-2017 at 14:08.
headline 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 07:34.


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