Raised This Month: $ Target: $400
 0% 

Stock for drop weapon. Need help >"<


Post New Thread Reply   
 
Thread Tools Display Modes
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-02-2009 , 14:52   Re: Stock for drop weapon. Need help >"<
Reply With Quote #11

I'd go #define for numbers (and floats).
Though I'd better go "new" instead of "const".
__________________
hleV is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-02-2009 , 15:04   Re: Stock for drop weapon. Need help >"<
Reply With Quote #12

Defines just make the code look worse and less readable

PHP Code:
const OFFSET_FAMAS_AMMO 380 
OFFSET_FAMAS_AMMO is a constant that holds the value 380.
__________________
joaquimandrade is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 05-02-2009 , 15:25   Re: Stock for drop weapon. Need help >"<
Reply With Quote #13

Quote:
Originally Posted by joaquimandrade View Post
Defines just make the code look worse and less readable
I'm talking about efficiency - is there a difference between both #define and const?
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-02-2009 , 15:29   Re: Stock for drop weapon. Need help >"<
Reply With Quote #14

Quote:
Originally Posted by Dores View Post
I'm talking about efficiency - is there a difference between both #define and const?
Efficiency? No. The only difference is that a global const will lay on memory during the plugin lifetime. What means nothing.

That's the same of when someone wants to know if a string matches another and instead of compare it all, just compare some characters. You save almost nothing to make the code look worst.

PHP Code:
(x[0] == 's' && x[3] == 'f')

equal(x,"stuff"
__________________

Last edited by joaquimandrade; 05-02-2009 at 15:34.
joaquimandrade is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-02-2009 , 15:54   Re: Stock for drop weapon. Need help >"<
Reply With Quote #15

"const" is useless. Why use it?
Quote:
it might even be faster because in the case of non-const the compiler won’t have to copy it into the heap first. In many cases you know it will never be modified, and the native declaration simply forgot a ‘const’ keyword.
__________________

Last edited by hleV; 05-02-2009 at 15:56.
hleV is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-02-2009 , 16:01   Re: Stock for drop weapon. Need help >"<
Reply With Quote #16

Why would you do this:

PHP Code:
equal(x,"stuff"

When you can do this?

PHP Code:
(x[0] == 's' && x[3] == 'f'



__________________
joaquimandrade is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-02-2009 , 16:26   Re: Stock for drop weapon. Need help >"<
Reply With Quote #17

Quote:
Originally Posted by hleV View Post
"const" is useless. Why use it?
You do not have to but defining it as a constant will prevent its data from being changed accidentally in your script. It will hold the same value and take up the same amount of memory regardless.

Example:
PHP Code:
new const iVar 5;

public 
TheFunc()
{
    
iVar 12;

Compiler:
Code:
Error: Must be lvalue (non-constant) on line 5
__________________
Bugsy is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 05-02-2009 , 17:21   Re: Stock for drop weapon. Need help >"<
Reply With Quote #18

Fine, I'm going on constants then.
Thanks.
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-02-2009 , 17:24   Re: Stock for drop weapon. Need help >"<
Reply With Quote #19

Quote:
Originally Posted by Dores View Post
Fine, I'm going on constants then.
Thanks.
Use what you prefer, defines will not use any memory and a const will. Jamoriquai was giving you his opinion
__________________
Bugsy is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-02-2009 , 17:40   Re: Stock for drop weapon. Need help >"<
Reply With Quote #20

Quote:
Originally Posted by Bugsy View Post
Use what you prefer, defines will not use any memory and a const will. Jamoriquai was giving you his opinion
Jamoriquai is me?
__________________
joaquimandrade 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 19:15.


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