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

String to number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Touch
Member
Join Date: Apr 2010
Location: Ukraine
Old 04-06-2010 , 12:03   String to number
Reply With Quote #1

Hello!
Prompt please how to change a string in the number?
Example:
Code:
new cyber [65];
cyber = 5,
cyber = cyber-1;
How can this be done?
This code produces an error error 033: array must be indexed (variable "cyber")

What to tell? Many thanks in advance!
Sorry for my bad English.

Last edited by Touch; 04-06-2010 at 12:07.
Touch is offline
Send a message via Skype™ to Touch
psychonic

BAFFLED
Join Date: May 2008
Old 04-06-2010 , 12:17   Re: String to number
Reply With Quote #2

Quote:
Originally Posted by Touch View Post
Hello!
Prompt please how to change a string in the number?
Example:
Code:
new cyber [65];
cyber = 5,
cyber = cyber-1;
How can this be done?
This code produces an error error 033: array must be indexed (variable "cyber")

What to tell? Many thanks in advance!
Sorry for my bad English.
PHP Code:
new String:szCyber[65] = "5";
new 
iCyber StringToInt(szCyber);
iCyber iCyber-1;
PrintToChatAll("Cyber = %d"iCyber); 
That will print "Cyber = 4".
psychonic is offline
Pawn 3-pg
Senior Member
Join Date: Jul 2009
Old 04-06-2010 , 12:25   Re: String to number
Reply With Quote #3

Quote:
Originally Posted by Touch View Post
Hello!
Prompt please how to change a string in the number?
Example:
Code:
new cyber [65];
cyber = 5,
cyber = cyber-1;
How can this be done?
This code produces an error error 033: array must be indexed (variable "cyber")

What to tell? Many thanks in advance!
Sorry for my bad English.
To convert an integer to a string and back:
PHP Code:
new String:string_var[65];
new 
int_var;
int_var 5;
IntToString(int_varstring_varstrlen(string_var)); // string_var now equals "5"

int_var StringToInt(string_var) - 1//int_var now equals 4
IntToString(int_varstring_varstrlen(string_var)); //string_var now equals "4" 
Pawn 3-pg is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 04-06-2010 , 22:40   Re: String to number
Reply With Quote #4

How it could be done at low level, for those who are interested: http://www.student.cs.uwaterloo.ca/~...8c-source.html
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
Touch
Member
Join Date: Apr 2010
Location: Ukraine
Old 04-07-2010 , 10:10   Re: String to number
Reply With Quote #5

Quote:
Originally Posted by psychonic View Post
PHP Code:
new String:szCyber[65] = "5";
new 
iCyber StringToInt(szCyber);
iCyber iCyber-1;
PrintToChatAll("Cyber = %d"iCyber); 
That will print "Cyber = 4".
array must be indexed (variable "iCyber")

Last edited by Touch; 04-07-2010 at 10:47.
Touch is offline
Send a message via Skype™ to Touch
psychonic

BAFFLED
Join Date: May 2008
Old 04-07-2010 , 10:27   Re: String to number
Reply With Quote #6

Quote:
Originally Posted by Touch View Post
array must be indexed (variable "iCuber")
My example compiles fine. Show your code.
psychonic is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 04-07-2010 , 12:05   Re: String to number
Reply With Quote #7

> Last edited by Touch; Today at 09:47.
I think he meant the code from the quotations
__________________
Leonardo is offline
Touch
Member
Join Date: Apr 2010
Location: Ukraine
Old 04-07-2010 , 13:04   Re: String to number
Reply With Quote #8

PHP Code:
new client GetClientOfUserId(GetEventInt(event"userid"));
decl String:steamid[64];
GetClientAuthString(clientsteamidsizeof(steamid));
new 
String:player[65];
new 
String:player_query[512];
Format(player_querysizeof(player_query), "SELECT COUNT(*) FROM css_server WHERE kills>0 and steamid='%s'"steamid)
new 
Handle:player_result SQL_Query(db,player_query)
if (
SQL_FetchRow(player_result))
{
SQL_FetchString(player_result0playersizeof(player))

Var player contains a number such as 5, I need to increase this number in 1 to become 6. How?
Thanks!
Touch is offline
Send a message via Skype™ to Touch
Pawn 3-pg
Senior Member
Join Date: Jul 2009
Old 04-07-2010 , 14:04   Re: String to number
Reply With Quote #9

Quote:
Originally Posted by Touch View Post
Var player contains a number such as 5, I need to increase this number in 1 to become 6. How?
Thanks!
PHP Code:
IntToString(StringToInt(player) + 1playerstrlen(player)); 
Pawn 3-pg is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-07-2010 , 14:04   Re: String to number
Reply With Quote #10

Your best bet is to fetch an int from the database instead of a string.

If you did want to perform math functions on a string in future, you'd need to convert the string to an int, do whatever you needed to do, then convert back. Obviously this method is slow, and you're better off using an int from the start!
Scone 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 10:46.


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