Raised This Month: $ Target: $400
 0% 

Solved How to empty a variable/string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 02-28-2018 , 06:48   How to empty a variable/string
Reply With Quote #1

Lets say i have this:

PHP Code:
new g_n_Coins[33]
new 
g_s_Text[33][10
g_n_Coins is used to store numbers.
g_s_Text is used to store Text.

At client_disconnect i want to EMPTY both.

Whats the best way to do it?
PHP Code:
public client_disconnect(id)
{
    
g_n_Coins[id] = 0
    g_s_Text
[id] = ""

or

PHP Code:
public client_disconnect(id)
{
    
g_n_Coins[id] = EOS
    g_s_Text
[id] = EOS


Last edited by Syturi0; 02-28-2018 at 07:31.
Syturi0 is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 02-28-2018 , 06:51   Re: How to empty a variable
Reply With Quote #2

2nd can't be compiled.

Use this
Code:
public client_disconnect(id) {     g_n_Coins[id] = 0;     g_s_Text[id][0] = EOS }
KiLLeR. is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 02-28-2018 , 06:52   Re: How to empty a variable
Reply With Quote #3

Quote:
Originally Posted by KiLLeR. View Post
2nd can't be compiled.

Use this
Code:
public client_disconnect(id) {     g_n_Coins[id] = 0;     g_s_Text[id][0] = EOS }
You are right.
Ty for the fast reply.
Syturi0 is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 02-28-2018 , 07:01   Re: How to empty a variable
Reply With Quote #4

Btw, can i use this:

PHP Code:
#define EMPTY_STRING "EOS"
public client_disconnect(id)
{
     
g_s_Text[id][0] = EMPTY_STRING

Will it work?
Syturi0 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-28-2018 , 07:28   Re: How to empty a variable
Reply With Quote #5

Without quotes around EOS, yes.
Honestly I'd go with
PHP Code:
stock const EMPTY_STRING[1] = { EOS };
// To use it
g_s_Text[id] = EMPTY_STRING
the thing is that with this you don't have to index the first element ([0]) like in your example. Looks cleaner.

In 1.8.3 you can probably just use NULL_STRING (it's already defined) instead of this EMPTY_STRING.
__________________

Last edited by klippy; 02-28-2018 at 07:29.
klippy is offline
Syturi0
Veteran Member
Join Date: Aug 2014
Location: Your mom house -Portugal
Old 02-28-2018 , 07:31   Re: How to empty a variable
Reply With Quote #6

Quote:
Originally Posted by KliPPy View Post
Without quotes around EOS, yes.
Honestly I'd go with
PHP Code:
stock const EMPTY_STRING[1] = { EOS };
// To use it
g_s_Text[id] = EMPTY_STRING
the thing is that with this you don't have to index the first element ([0]) like in your example. Looks cleaner.

In 1.8.3 you can probably just use NULL_STRING (it's already defined) instead of this EMPTY_STRING.
Thanks.
Solved.
Syturi0 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 20:32.


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