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

a lot of question [ Must See lol ]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-26-2015 , 06:17   a lot of question [ Must See lol ]
Reply With Quote #1

So i want to ask you a few questions ....

Question Number 1 ( About char array ) :

Is there a difference between

Code:
new bool:g_Ex[33 char]

and

Code:
new bool:g_Ex[33]

i heard that if i use 'char' (like in the first ex ) i need to put { } Like :

g_Ex{ index } = 0

not [ ]
also it output different bytes .



Question Number 2 ( Cheking string ):


Is it better to check a string like this ?

Code:
if(strcmp("HelloNoobs", "HelloNoobs") == 0) {     }

or using equal() i know that strcmp shouldn't be use in (!) ...
My question is : If there is a equal() ... why there is a strcmp()



Question Number 3 ( about consuming CPU much ):


I will give you two different events and tell me who is killingCPU More ( I know that its a different events )


Code:
FM_Touch
Or

Code:
FM_AddToFullPack
Question Number 4 ( Read ):


So this is a simple one :

Code:
new sz_Test[ MAX + 1 ] = { 0, 10, 20, ... }

So , the rule is : +10 , what if we want an unlimited Number ( What should i do ? )



Question Number 5 ( Why set_fail_state cant format a string from 1.8.3 ):


Why set_fail_state cant format a string from 1.8.3 ?



Question Number 5 ( who is more sensible ? ) :



Is there a difference between this two ? :

Code:
new stringValue[40] = "Can you answer me about that please , thanks" for (new i=0; i<strlen(stringValue); i++)

and

Code:
new stringValue[40] = "Can you answer me about that please , thanks" new len = strlen(stringValue) for (new i=0; i<len; i++)

And what method is sensible( AND WHY ) ?



Question Number 6 ( what make formatex() better than format() ):


what make formatex() have a ' high-speed'


Question Number 7 ( about character like %s .. ):


Can u give me different character as : %s ( that its important to know )
What i know is
Spoiler



And what does it mean this :
%04d



Question Number 8 ( About bit flags ... ):



As Bugsy said

Operator: &
Function: And
Description: This operator is used to check if and only if both of the corresponding bits in both operands are 1. The resulting bit-field will consist of bits (1's) that were present at the same location within both operands.

so

Why its used
Code:
#define CheckPlayerBit(%1,%2)    (%1 & (1<<(%2&31)))

and not
Code:
#define CheckPlayerBit(%1,%2)            ((%0) & (%1))

so basicly if the flag isn't set it will return false (0) .


Question Number 9 ( about #tryinclude & #assert) :


What does it mean this

PHP Code:
#tryinclude includeheremaybe? 
and also #assert


Question Number 10 ( about return) :


i see some people do
Code:
return -1.0

my question is why its negative and its float ??

Question Number 11 ( About #error ... ):


Code:
#define HELLOFYSIKS "Im fysiks ? yes you are "
Code:
    #if !defined HELLOFYSIKS         #error Please put HELLOFYSIKS in the define #endif

This will return just message output of compiler ? nothing else ?

Question Number 12 ( About static stock ... ):


Code:
static stock sendMsg(id,msg[] ) client_cmd( id , msg )

What the meaning of this ? is it the same as stock sendMsg.... ??

Question Number 13 ( about (sizeof - 1) and charsmax ... ):


Why sometimes i see people using
Code:
sizeof - 1

Or

Code:
charsmax
They say that they are the same but its not i guess right ? if yes please tell me why!


Question Number 14 ( about #emit ... ):


if i set a value to #emit what does it change ? ( i know that its related to the compiler but i don't know exactly ... )

Question Number 15 ( about x-- & --x & x++ & ++x... ):


Lol , i can't understand the difference between x-- & --x also the (+) , please give me examples ... i search but i didn't understand it well !

Question Number 16 ( Why the compiler give me an error ):



HOPE YOU ANSWER ME THANKS ( WELL I SEARCH BUT I DIDN'T FOUND MOST

i will update my post if i have more questions xD ...

Last edited by Freezo Begin; 04-26-2015 at 08:46.
Freezo Begin is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 04-26-2015 , 07:34   Re: a lot of question [ Must See lol ]
Reply With Quote #2

Answer 7: http://www.cplusplus.com/reference/cstdio/printf/

Not all of them are for AMX ModX

Last edited by Obada; 04-26-2015 at 08:55.
Obada is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-26-2015 , 08:11   Re: a lot of question [ Must See lol ]
Reply With Quote #3

Obada : 404 Page Not Found lol ...

Well what i give is working
Take a look ...
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> new arrayEx [] [] []  = {     { {'A', 'S', 'S', 'Y'}, 0x21, float:1.1020 , 100},     { {'K', 'I', 'S', 'S'}, 0x22, float:2.1021 , 200},     { {'K', 'I', 'L', 'L'}, 0x23, float:3.1031 , 300} }; public plugin_init() {     register_clcmd("say a","getValue") } public getValue(id){     for ( new i = 0; i < sizeof arrayEx; i++ )     {         server_print( "String: %s |Hex = %x |Float num = %f |Character =  %c  |I don't know what is it %04d",arrayEx[i][0],arrayEx[i][1],arrayEx[i][2],arrayEx[i][3],arrayEx[i][4])     } }

Last edited by Freezo Begin; 04-26-2015 at 08:13.
Freezo Begin is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 04-26-2015 , 08:42   Re: a lot of question [ Must See lol ]
Reply With Quote #4

So many of this questions are so pointless. Why do you care so much about what is faster?
About question 2, you know that equal is fine why does it matters?
Question 3, i am note sure why you compare this 2, they are totaly different. Well, the one that consumes more CPU is FM_AddToFullPack
Number 4, i am not an enum expert but i guess it can do the trick since you can make it be +X. There is some tutorial about enums, go take a look.
You have 2 questions number 5 xD
The first i have no idea, i dont use 1.8.3. About the other one, didn't understood the question. You want to know what's the best way? If so, the best way is the first because you don't create unnecessary memory. Yet, the second is fine, is not a big deal at all and is more readable than the first.
Question 6, i have no idea. But from what i have read before you shoud use always formatex except if you want to format the buffer.
Question 10, it depends of what you are trying to get. If you call a function to get some return as float, but fails, it should be -1.0 and not -1 because you are getting a float.
Question 13, i have no idea what's the difference, but it doesn't matters. They return the same value and you should use charsmax so it becomes more readable.
Question 15, doing --x is the same as x-1. doing x-- is the same as x-1.
__________________
Jhob94 is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-26-2015 , 08:54   Re: a lot of question [ Must See lol ]
Reply With Quote #5

Quote:
Originally Posted by Jhob94 View Post
So many of this questions are so pointless. Why do you care so much about what is faster?
About question 2, you know that equal is fine why does it matters?
Question 3, i am note sure why you compare this 2, they are totaly different. Well, the one that consumes more CPU is FM_AddToFullPack
Number 4, i am not an enum expert but i guess it can do the trick since you can make it be +X. There is some tutorial about enums, go take a look.
You have 2 questions number 5 xD
The first i have no idea, i dont use 1.8.3. About the other one, didn't understood the question. You want to know what's the best way? If so, the best way is the first because you don't create unnecessary memory. Yet, the second is fine, is not a big deal at all and is more readable than the first.
Question 6, i have no idea. But from what i have read before you shoud use always formatex except if you want to format the buffer.
Question 10, it depends of what you are trying to get. If you call a function to get some return as float, but fails, it should be -1.0 and not -1 because you are getting a float.
Question 13, i have no idea what's the difference, but it doesn't matters. They return the same value and you should use charsmax so it becomes more readable.
Question 15, doing --x is the same as x-1. doing x-- is the same as x-1.
Thanks,
i appreciate it , Let me read first xD then i will reply you !

Edit :
Alright , its not pointless , it can be useful if you want to optimize your code with such simple things like that ...

Answer num 3 :
i saw some people using it as a touch event LOL !

About Answer num 4

I didn't get what you said to me are you trying to say something like this ?
(+=X) ?

Answer num 10 :
Yes i totally forget about this , thanks .

Answer num 15 :
So its the same --x & x-- because you said both are (x-1) ?

Last edited by Freezo Begin; 04-26-2015 at 09:08.
Freezo Begin is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 04-26-2015 , 08:55   Re: a lot of question [ Must See lol ]
Reply With Quote #6

Quote:
Originally Posted by Freezo Begin View Post
Obada : 404 Page Not Found lol ...

Well what i give is working
Take a look ...
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> new arrayEx [] [] []  = {     { {'A', 'S', 'S', 'Y'}, 0x21, float:1.1020 , 100},     { {'K', 'I', 'S', 'S'}, 0x22, float:2.1021 , 200},     { {'K', 'I', 'L', 'L'}, 0x23, float:3.1031 , 300} }; public plugin_init() {     register_clcmd("say a","getValue") } public getValue(id){     for ( new i = 0; i < sizeof arrayEx; i++ )     {         server_print( "String: %s |Hex = %x |Float num = %f |Character =  %c  |I don't know what is it %04d",arrayEx[i][0],arrayEx[i][1],arrayEx[i][2],arrayEx[i][3],arrayEx[i][4])     } }
My bad, I edited the link.
Obada is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-26-2015 , 09:09   Re: a lot of question [ Must See lol ]
Reply With Quote #7

1. Read Bugsy's tutorial about packed/unpacked strings. I never used a packed string, but from what I read, it doesn't use the same ammount of memory as an unpacked one. My advice is don't try to over-optimize.
2. Lol, read function description. You will understand.
3. Why do you compare some forward that have no connection between them ? But, yes, both are cpu consuming. The thing is that for FM_AddToFullPack you don't have a direct alternative. For FM_Touch you have engine/hamsandwich. Engine does the same thing as fakemeta, it hooks pfnTouch, but allow you to filter by some classnames, so the forward is not fired every time a touch occurs.
4. Jhob, where do you see an enum at question 4 ? You can't have unlimited values. When you want compiler to determinate the next number based on a rule, you must specifiy a max size for it. Not sure if this was your question or not.
5. set_fail_state CAN format a string in 1.8.3. It can't do that in versions lower that 1.8.3
If you want to display a message that depends on some values, strings etc(like "The plugin failed because of %s") you would need to use formatex to format the message, and pass the string-array that holds it into set_fail_state. In 1.8.3, it is easy, you can use %s %i %f with it.
5.Here you are wrong Jhob. Second is better, but this is a little optimizations. Here we can talk more about keeping good practices, not about memory usage. The lenght of a constant string is, guess, constant. If you don't cache it, when the for structure check again the condition, it will call strlen again, to get the same value as before. You can't cache it if you alter the string during the "for" because it's lenght will change.
6. Read on the wiki. formatex is faster because it doesn't create a copy, but this bring the limitation that you can't format in the same buffer from where you get a value.
7. Search, search, search.
8. Because you need to add player index to the bitsum and be sure that the bits or the player index doesn't fall out of range.
9. It will try to include the specified file. If file could not be found, the script will be still compiled, but it won't work fully. I was using asser in some of my plugins to notify in the compiler console if an include could not be found and from where you can download it.
10. It's a custom return. If you make a stock/native that works with floats, and it fails(could not find what is needed or whatever it is his purpose) you should return a value so the coder can check and work with the output only if it is valid. Basically, you tell them that if they see that value returned something is going wrong.
11. Never used it, so I don't know how it works.
12. Why would someone make a stock static ? It seems to be pointless.
13. They are the same thing. charsmax() is defined as sizeof -1. So, it's just a define that is replaced during compilation with sizeof -1. sizeof give you the size of the entire array, charsmax give you the usable size of that array(the last item from an array must be 0). You should use charsmax when working with strings for readability purpose.
14. I think you can find some info about emit around here.
15. Jhob, you are wrong again. --var/++var is called pre decrementation/pre incrementation. var--/var++ is called post decrementation/post incrementation. Pre change the value of the variable before using it inside an expresion. Post firstly use it's value inside an expresion, and after that it change the value.

PHP Code:
new a  5
new b  6
new 1

new = --b--
new 
a++
new 
= ++
Code:
a = 5 b = 6 c = 1
d = --a  + b-- = --5 + 6-- = 4 + 6 = 10(the value of a is changed right now, b will be changed after the calculation)
a = 4 b = 5 c = 1 d = 10
e = 1 + 4++ = 1 + 4 = 5 //a will be changed later
a = 5 b = 5 c = 1 d = 10 e = 5
f = ++5 - 5 = 6 - 5 = 1
a = 5 b = 5 c = 1 d= 10 e = 6 f = 1
They add or substract 1 based on the type: pre or post.
Hope this helps.
__________________

Last edited by HamletEagle; 04-26-2015 at 09:10.
HamletEagle is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-26-2015 , 09:09   Re: a lot of question [ Must See lol ]
Reply With Quote #8

Quote:
Originally Posted by Obada View Post
My bad, I edited the link.
Thanks,
i think its all can be used ...
Freezo Begin is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 04-26-2015 , 09:22   Re: a lot of question [ Must See lol ]
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
1. Read Bugsy's tutorial about packed/unpacked strings. I never used a packed string, but from what I read, it doesn't use the same ammount of memory as an unpacked one. My advice is don't try to over-optimize.
2. Lol, read function description. You will understand.
3. Why do you compare some forward that have no connection between them ? But, yes, both are cpu consuming. The thing is that for FM_AddToFullPack you don't have a direct alternative. For FM_Touch you have engine/hamsandwich. Engine does the same thing as fakemeta, it hooks pfnTouch, but allow you to filter by some classnames, so the forward is not fired every time a touch occurs.
4. Jhob, where do you see an enum at question 4 ? You can't have unlimited values. When you want compiler to determinate the next number based on a rule, you must specifiy a max size for it. Not sure if this was your question or not.
5. set_fail_state CAN format a string in 1.8.3. It can't do that in versions lower that 1.8.3
If you want to display a message that depends on some values, strings etc(like "The plugin failed because of %s") you would need to use formatex to format the message, and pass the string-array that holds it into set_fail_state. In 1.8.3, it is easy, you can use %s %i %f with it.
5.Here you are wrong Jhob. Second is better, but this is a little optimizations. Here we can talk more about keeping good practices, not about memory usage. The lenght of a constant string is, guess, constant. If you don't cache it, when the for structure check again the condition, it will call strlen again, to get the same value as before. You can't cache it if you alter the string during the "for" because it's lenght will change.
6. Read on the wiki. formatex is faster because it doesn't create a copy, but this bring the limitation that you can't format in the same buffer from where you get a value.
7. Search, search, search.
8. Because you need to add player index to the bitsum and be sure that the bits or the player index doesn't fall out of range.
9. It will try to include the specified file. If file could not be found, the script will be still compiled, but it won't work fully. I was using asser in some of my plugins to notify in the compiler console if an include could not be found and from where you can download it.
10. It's a custom return. If you make a stock/native that works with floats, and it fails(could not find what is needed or whatever it is his purpose) you should return a value so the coder can check and work with the output only if it is valid. Basically, you tell them that if they see that value returned something is going wrong.
11. Never used it, so I don't know how it works.
12. Why would someone make a stock static ? It seems to be pointless.
13. They are the same thing. charsmax() is defined as sizeof -1. So, it's just a define that is replaced during compilation with sizeof -1. sizeof give you the size of the entire array, charsmax give you the usable size of that array(the last item from an array must be 0). You should use charsmax when working with strings for readability purpose.
14. I think you can find some info about emit around here.
15. Jhob, you are wrong again. --var/++var is called pre decrementation/pre incrementation. var--/var++ is called post decrementation/post incrementation. Pre change the value of the variable before using it inside an expresion. Post firstly use it's value inside an expresion, and after that it change the value.

PHP Code:
new a  5
new b  6
new 1

new = --b--
new 
a++
new 
= ++
Code:
a = 5 b = 6 c = 1
d = --a  + b-- = --5 + 6-- = 4 + 6 = 10(the value of a is changed right now, b will be changed after the calculation)
a = 4 b = 5 c = 1 d = 10
e = 1 + 4++ = 1 + 4 = 5 //a will be changed later
a = 5 b = 5 c = 1 d = 10 e = 5
f = ++5 - 5 = 6 - 5 = 1
a = 5 b = 5 c = 1 d= 10 e = 6 f = 1
They add or substract 1 based on the type: pre or post.
Hope this helps.

....

THIS IS AWESOME MAN ... THANKS A LOT

YES THIS HELPS A LOT THAAANKS xD !
Freezo Begin is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 04-26-2015 , 10:30   Re: a lot of question [ Must See lol ]
Reply With Quote #10

Quote:
Originally Posted by HamletEagle View Post
4. Jhob, where do you see an enum at question 4 ? You can't have unlimited values. When you want compiler to determinate the next number based on a rule, you must specifiy a max size for it. Not sure if this was your question or not.
I know he didn't spoke about enums. Just saw now the enum tutorial by exolent and what i thought that maybe was possible, is not.

Quote:
Originally Posted by HamletEagle View Post
5.Here you are wrong Jhob. Second is better, but this is a little optimizations. Here we can talk more about keeping good practices, not about memory usage. The lenght of a constant string is, guess, constant. If you don't cache it, when the for structure check again the condition, it will call strlen again, to get the same value as before. You can't cache it if you alter the string during the "for" because it's lenght will change.
My bad, when i saw i didn't realized it was a loop.

Quote:
Originally Posted by HamletEagle View Post
15. Jhob, you are wrong again. --var/++var is called pre decrementation/pre incrementation. var--/var++ is called post decrementation/post incrementation. Pre change the value of the variable before using it inside an expresion. Post firstly use it's value inside an expresion, and after that it change the value.
I was not wrong, the max you can say is that i was incomplete. He never spoke about it. I assumed he was talking about simple variables like:
PHP Code:
Add_XP(id)
{
    
g_iXP[id]++

__________________
Jhob94 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 05:00.


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