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

nVault Tutorial


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-21-2016 , 15:28   Re: nVault Tutorial
Reply With Quote #11

Quote:
Originally Posted by Craxor View Post
@prostetamoto: Just for safety, 'maybe' player is not fully connected so i make a little delay, is not big deal but just to be sure( and in my past i was having problems some times so this should be there ).

It's you preferences rose, but bugsy said to make a global var gAuthId to avoid calling get_user_authid more times, even if you make it in a stock calls are maded more times but that's about preferences.


About szPoints should be [11] sorry i did not know about max integers

Oo, about '33' as i know:

32 - the container wich hold the the arrays:

31 - id 32
30 - id 31
29 - id 30
28 - id 29
27 - 28
..... bla bla bla...
4 - id 5
3 - id 4
2 - id 3
2 - id 3
1 - id 2
0 - id 1.

So why using 33 ?
Yeah. Ignore the fact that I've been coding for AMXX for 11 years.

My example only calls get_user_authid() once on authorized.
EDIT: This is wrong as pointed out by Bugsy: Then it stores the integer value generated from that and never use the string again.
Trust me, it's better in every way. It's just a question of overkill.


Indexes range from either 0-31 if you use a listen server or 1-32 if you have a dedicated server (because the server has id 0).
If you set up a variable with 32 indexes (new array[32]), you get 32 indexes, but they range from 0-31. If a player joins and gets the id 32 and you try calling array[id(32)], you will get index out of bounds error and the plugin fails miserably.
You can use array[id-1], but that means if you run a listen server you will get index out of bounds in the other end instead since there is no array[-1].
For simplicity people tend to use 33 because there is no need to worry. Nothing can go wrong. I don't think many people knows about the listen server problem though, but that doesn't matter.

You can also look at it from another perspective.
If you use array[id-1] it means that the engine has to carry out a math operation which steals precious CPU. And optimization (in my world) is about using memory to preserve CPU. Because memory is almost never an issue. And in this case we're talking about 1 cell extra, that's 4 bytes. Again, overkill. The point of not carrying out any math operations with the player ID is readability. And that's the most important thing of any code.
If you can read it properly, you can understand it.
If you can understand it you can debug and support it.
That's the way of becoming a good coder IMHO.

You clearly want to become a good coder. And I support you. But you have to chill out a bit. You will make mistakes in the beginning, don't worry about it.
__________________

Last edited by Black Rose; 09-24-2016 at 05:45.
Black Rose is offline
 


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 22:29.


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