Raised This Month: $ Target: $400
 0% 

Quick stupid question about global arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Plaffy46
Junior Member
Join Date: Mar 2014
Old 12-02-2014 , 07:48   Quick stupid question about global arrays
Reply With Quote #1

So, I ran into a pretty weird problem with these 2 lines (declared just after the includes as global variables).
Code:
new iNumSlots = 3;
new gIsGenuineKillstreaked[MaxClients][iNumSlots];
My own spcomp.exe literally crashes (while it works fine with everything else) when trying to compile this.

Spider compiler gives me these errors :
plugin.sp(7) : error 008: must be a constant expression; assumed zero
plugin.sp(7) : error 009: invalid array size (negative, zero or out of bounds)

What is the actual syntax for declaring 2-dimensional arrays, I tried using handles and stuff, it keeps reporting some weird errors.
I'm pretty sure it's something really stupid, but I was so tired these last days.

Last edited by Plaffy46; 12-02-2014 at 07:52.
Plaffy46 is offline
lingzhidiyu
Senior Member
Join Date: Mar 2014
Old 12-02-2014 , 08:35   Re: Quick stupid question about global arrays
Reply With Quote #2

new gIsGenuineKillstreaked[MAXPLAYERS+1][iNumSlots];
lingzhidiyu is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 12-02-2014 , 08:40   Re: Quick stupid question about global arrays
Reply With Quote #3

MaxClients and iNumSlot are variables and not constant.
h3bus is offline
Plaffy46
Junior Member
Join Date: Mar 2014
Old 12-02-2014 , 08:43   Re: Quick stupid question about global arrays
Reply With Quote #4

Well, I knew this was stupid ;_;. Thanks for the help!
Plaffy46 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-02-2014 , 09:53   Re: Quick stupid question about global arrays
Reply With Quote #5

SourcePawn does have the const keyword, btw.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-02-2014 , 11:20   Re: Quick stupid question about global arrays
Reply With Quote #6

You better use #define NUM_SLOT if you already know his value at the compile time. I doubt that it will change during the run-time since you already define your 2D array size with it and could create a out of bound if you refer to your NumSlot in your loops (if it change). If you want to create dynamic array than it a different story, you will have to look into the ADT_ARRAY from sourcemod docs.

Last edited by Mathias.; 12-02-2014 at 11:20.
Mathias. is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-02-2014 , 12:05   Re: Quick stupid question about global arrays
Reply With Quote #7

Quote:
Originally Posted by Black-Rabbit View Post
You better use #define NUM_SLOT if you already know his value at the compile time. I doubt that it will change during the run-time since you already define your 2D array size with it and could create a out of bound if you refer to your NumSlot in your loops (if it change). If you want to create dynamic array than it a different story, you will have to look into the ADT_ARRAY from sourcemod docs.
Fun fact: a define and a const aren't the same thing. One is a literal replacement of some text everywhere it's used and the other is a type-safe value. Well, as type safe as you can get in Pawn.

Also, I thought the precompiler was eventually going away, meaning that #define would stop working. I can't find a reference to that now, though. If anything, it probably wouldn't be until SM 2.0 and there are apparently plans for at least 1.8 and 1.9 before that happens.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-02-2014 at 12:10.
Powerlord is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-02-2014 , 13:28   Re: Quick stupid question about global arrays
Reply With Quote #8

precompiler are useful in allot of situation, no way it is going away.
Mathias. is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-02-2014 , 15:43   Re: Quick stupid question about global arrays
Reply With Quote #9

Quote:
Originally Posted by Black-Rabbit View Post
precompiler are useful in allot of situation, no way it is going away.
like not needing a variable where you need to loop the elements in an specific array.
Mitchell is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 12-02-2014 , 20:36   Re: Quick stupid question about global arrays
Reply With Quote #10

I don't know where we going with this, the only thing I meant is it preferable to create a precompiler variable instead of a global constant (should never use a global constant in any situations, it doesn't make sense)

EDIT: actually nvm, do what you want. Not like it matter, I'm just trying to hard.

Last edited by Mathias.; 12-02-2014 at 20:37.
Mathias. 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 02:53.


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