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

Code error 033 "array muse be indexed"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hay
Junior Member
Join Date: Jun 2018
Old 06-08-2018 , 11:54   Code error 033 "array muse be indexed"
Reply With Quote #1

Hello, I tried to type a command that "spam" the chat here's the command :

public Action:Command_Spam(client,args)
{
char x[256];
GetCmdArgString(x, sizeof(x));

char y[100];
StringToInt(y);
GetCmdArgString( y, sizeof(y))


for (int i = 0; i <= y; i++) {
PrintToChatAll(x);
}

}

And Its says array must be indexed(variable "y")
please explain and give an example how to fix, thank you.
Hay is offline
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 06-08-2018 , 11:59   Re: Code error 033 "array muse be indexed"
Reply With Quote #2

StringToInt(y);
GetCmdArgString( y, sizeof(y))

to

GetCmdArgString( y, sizeof(y))

int spam = StringToInt(y);

and

for (int i = 0; i <= y; i++) {

to

for (int i = 0; i <= sizeof(y); i++) {

Last edited by Kellan123; 06-08-2018 at 11:59.
Kellan123 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 06-08-2018 , 12:15   Re: Code error 033 "array muse be indexed"
Reply With Quote #3

please use for code one of the following tags

[HTML][/HTML] or [PHP][/PHP] or [CODE][/CODE]
__________________
coding & free software
shanapu is offline
Hay
Junior Member
Join Date: Jun 2018
Old 06-08-2018 , 12:30   Re: Code error 033 "array muse be indexed"
Reply With Quote #4

The command now is like you told :
public Action:Command_Spam(client,args)
{
char x[256];
GetCmdArgString(x, sizeof(x));

char y[100];
GetCmdArgString( y, sizeof(y))
int spam = StringToInt(y);


for (int i = 0; i <= sizeof(y); i++) {
PrintToChatAll(x);
}

}
but its just print to comment prints the command like that: http://prntscr.com/jslyfb
instead of print it just twice
Hay is offline
Hay
Junior Member
Join Date: Jun 2018
Old 06-08-2018 , 12:33   Re: Code error 033 "array muse be indexed"
Reply With Quote #5

Quote:
Originally Posted by shanapu View Post
please use for code one of the following tags

[HTML][/HTML] or [PHP][/PHP] or [CODE][/CODE]
I think I didn't understand what you say but I am talking on sourcepawn code language
Hay is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 06-08-2018 , 13:10   Re: Code error 033 "array muse be indexed"
Reply With Quote #6

example - you write: [CODE] //here goes my code [/CODE]

It will be shown in thread like:
Code:
	//here goes my code
So your code snippet is easier to read for all of us.
__________________
coding & free software
shanapu is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 06-08-2018 , 13:40   Re: Code error 033 "array muse be indexed"
Reply With Quote #7

PHP Code:
public Action Command_Spam(int clientint args)
{
    
char x[256];
    
GetCmdArg(1xsizeof(x));
    
    
char y[100];
    
GetCmdArg(2ysizeof(y));

    
int count StringToInt(y);
    
    for (
int i 0counti++) {
        
PrintToChatAll(x);
    }

If you want the text to be multiple words, you need to use double quotes:
Code:
!spam "Hello world" 3
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami 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 08:24.


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