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

Solved Question on string arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-21-2020 , 21:09   Question on string arrays
Reply With Quote #1

I'm in the process of upgrading my code to the new declarations. I changed it to the 'new version' below and got unintended results. Can you tell me what the code should look like with new declarations?

Old version (works fine):
PHP Code:
public EventInventoryApplication(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
String:strItemsindex[5][65];
    new 
strItem[5];
    
strItem[0] = StringToInt(strItemsindex[0]);
    
strItem[1] = StringToInt(strItemsindex[1]);
    
strItem[2] = StringToInt(strItemsindex[2]);
    
strItem[3] = StringToInt(strItemsindex[3]);
    
strItem[4] = StringToInt(strItemsindex[4]); 
New version (doesn't work):
PHP Code:
public Action EventInventoryApplication(Handle event, const char[] namebool dontBroadcast)
{
    
char strItemsindex[5][65];
    
char strItem[5];
    
strItem[0] = StringToInt(strItemsindex[0]);
    
strItem[1] = StringToInt(strItemsindex[1]);
    
strItem[2] = StringToInt(strItemsindex[2]);
    
strItem[3] = StringToInt(strItemsindex[3]);
    
strItem[4] = StringToInt(strItemsindex[4]); 

Last edited by PC Gamer; 12-21-2020 at 22:11.
PC Gamer is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-21-2020 , 21:32   Re: Question on string arrays
Reply With Quote #2

from
PHP Code:
char strItem[5]; 
to
PHP Code:
int strItem[5]; 
older version new String:string == char
older version new string == int
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 12-21-2020 at 21:35.
GsiX is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-21-2020 , 22:12   Re: Question on string arrays
Reply With Quote #3

Thanks GsiX! That fixed my problem.
PC Gamer is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 12-22-2020 , 03:39   Re: Question on string arrays
Reply With Quote #4

You should always check which type specific function returns.

In this case:
int StringToInt(const char[] str, int nBase)
__________________
MAGNAT2645 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 15:35.


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