Raised This Month: $ Target: $400
 0% 

Declaration of arrays? (syntax)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-25-2011 , 13:01   Declaration of arrays? (syntax)
Reply With Quote #1

PHP Code:
// variant 1
new bool:g_bArray1[128] = { true, ... };
// all corrent, no errors while compiling

// variant 2 (in analogy)
new bool:g_bArray2[16][8] = { { true, ... }, ... };
// got error 'invalid expression' 
is there any ways to make second variant w/o setting values by cycles?
My bad if it's already asked before.

Last edited by Leonardo; 03-25-2011 at 13:55.
Leonardo is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 03-25-2011 , 13:38   Re: Declaration of arrays? (syntax)
Reply With Quote #2

From what I remember, no it is not possible to declare 2D arrays like that. A loop in OnPluginStart will suffice instead.

EDIT: whelp, semicolon:
new bool:g_bArray2[16][8]; = { { true, ... }, ... };
Wazz is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-25-2011 , 13:53   Re: Declaration of arrays? (syntax)
Reply With Quote #3

Quote:
Originally Posted by Wazz View Post
EDIT: whelp, semicolon:
new bool:g_bArray2[16][8]; = { { true, ... }, ... };
it's just an Ooops
Leonardo is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-25-2011 , 14:02   Re: Declaration of arrays? (syntax)
Reply With Quote #4

You can use {{true, true, true, true},...} I believe, but not two repeaters
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 03-25-2011 , 20:10   Re: Declaration of arrays? (syntax)
Reply With Quote #5

PHP Code:
new bool:test[3][3] = {{truefalsetrue}, {truetruefalse}, {falsetruetrue}}; 
works fine for me, unless i didnt get what you want
AtomicStryker is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-25-2011 , 22:34   Re: Declaration of arrays? (syntax)
Reply With Quote #6

Quote:
Originally Posted by AtomicStryker View Post
PHP Code:
new bool:test[3][3] = {{truefalsetrue}, {truetruefalse}, {falsetruetrue}}; 
works fine for me, unless i didnt get what you want
The issue lies in using the repeater (, ...).
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-26-2011 , 02:30   Re: Declaration of arrays? (syntax)
Reply With Quote #7

PHP Code:
new g_iArray[MAXPLAYERS+1][TF2ItemSlot_MaxSlots]; 
and I should set each element of array?
there 2 dynamic variables, so...
Leonardo is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-27-2011 , 08:44   Re: Declaration of arrays? (syntax)
Reply With Quote #8

They're not dynamic. You can't create arrays using variables, only constants.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 03-27-2011 , 09:05   Re: Declaration of arrays? (syntax)
Reply With Quote #9

oh
I meant
constans can be changed
Leonardo is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 03-27-2011 , 10:21   Re: Declaration of arrays? (syntax)
Reply With Quote #10

Not during runtime.

I don't see your issue, though.
Looping all elements stays the same if it's a number or a constant's representation.
for(new i = 0; i < CONSTANT; i++)
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 17:58.


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