Raised This Month: $32 Target: $400
 8% 

array must be indexed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
echocage
Member
Join Date: Oct 2021
Old 06-28-2022 , 15:19   array must be indexed
Reply With Quote #1

Hi! Idk wtf is array indexing, cuz authid is not array - it`s string
Attached Thumbnails
Click image for larger version

Name:	Screenshot_7.png
Views:	67
Size:	2.0 KB
ID:	195414   Click image for larger version

Name:	Screenshot_6.png
Views:	74
Size:	7.1 KB
ID:	195415  
echocage is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 06-28-2022 , 17:02   Re: array must be indexed
Reply With Quote #2

This is not how you compare strings in sourcepawn

Should be

PHP Code:
if (!StrEqual(auth"BOT")) 
Also share code and not prints next time, cause is a nightmare to read and reproduce.
__________________

Last edited by Marttt; 06-29-2022 at 11:06. Reason: fixed wrong quote, thanks @azalty
Marttt is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 06-29-2022 , 11:03   Re: array must be indexed
Reply With Quote #3

As Marttt said,
PHP Code:
if (!StrEqual(auth"BOT")) 
(prefer using double quotes for strings, and single quotes for a single character, else you might encounter some bugs)

You can however check a single character like this:
PHP Code:
if (auth[0] == 'B'
(the single quotes are mandatory here)

Similarly, please use strcopy() or Format() or FormatEx() to write into strings, don't directly assign them.
__________________
GitHub | Discord: @azalty | Steam
azalty is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 06-29-2022 , 11:35   Re: array must be indexed
Reply With Quote #4

If you want to use the "faster" method, you can use strcmp instead of StrEqual.

PHP Code:
if (strcmp(auth"BOT") == 0
https://forums.alliedmods.net/showthread.php?t=321089
Quote:
strcmp instead of StrEqual. The latter is simply a wrapper to the former and slower by creating an extra call.
Maxximou5 is offline
Reply


Thread Tools
Display Modes

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 22:26.


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