AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array must be indexed (https://forums.alliedmods.net/showthread.php?t=246499)

EpicKiller 08-18-2014 10:19

Array must be indexed
 
Hi there. I got the error mentioned above trying to compile my plugin. Here's my code. What am I doing wrong?
Spoiler

klippy 08-18-2014 10:29

Re: Array must be indexed
 
PHP Code:

if(name req_tag

In which programming language have you seen that? If I am right, you want to check if name variable contains cvar value(string)?
If so, the code should look like:
PHP Code:

new req_tag[12];
get_pcvar_string(tagreq_tagcharsmax(req_tag)); // this is how you retrieve cvar string value

if(containi(namereq_tag)) // or use contain() for case-sensitive check
{
        
// Do something



EpicKiller 08-18-2014 10:36

Re: Array must be indexed
 
Quote:

Originally Posted by KliPPy (Post 2185758)
PHP Code:

if(name req_tag

In which programming language have you seen that? If I am right, you want to check if name variable contains cvar value(string)?
If so, the code should look like:
PHP Code:

new req_tag[12];
get_pcvar_string(tagreq_tagcharsmax(req_tag)); // this is how you retrieve cvar string value

if(containi(namereq_tag)) // or use contain() for case-sensitive check
{
        
// Do something



I have never seen that, but I'm a begginer in this and I really couldn't think of another way of doing it. Thank you so much for teaching me that! That's what I'll do from now on.

Nextra 08-18-2014 11:00

Re: Array must be indexed
 
Quote:

Originally Posted by KliPPy (Post 2185758)
PHP Code:

new req_tag[12];
get_pcvar_string(tagreq_tagcharsmax(req_tag)); // this is how you retrieve cvar string value

if(containi(namereq_tag)) // or use contain() for case-sensitive check
{
        
// Do something




This is wrong. Containi returns the position at which req_tag was found inside name, which can be 0 if the name starts with the tag. The value for "not found" is -1 which you need to check for explicitly:

PHP Code:

if(containi(namereq_tag) != -1// "name" contains "req_tag"
{
        
// Do something



klippy 08-18-2014 11:24

Re: Array must be indexed
 
Ah, yes, thank you Nextra, i totally forgot about that. :) Sometimes I mix equali and containi return value for some reason.

EpicKiller 08-19-2014 06:00

Re: Array must be indexed
 
Oh. Well, I'll modify and retest it. Thanks, guys!


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

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