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

Storing string in cVar


Post New Thread Reply   
 
Thread Tools Display Modes
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 21:22   Re: Storing string in cVar
Reply With Quote #11

Quote:
Originally Posted by fysiks View Post
Hardcoding things like this is bad practice. Stop advising people to do unnecessary optimizations.



That's a dumb thing to say. It's used for code maintainability. This too is a magic number.
If the array will always be at 32, what maintenance? You should also recommend it to Bugsy so, if the array will always be 32, the charsmax will always be 31, an unnecessary operation, it makes me laugh when they take arguments from anywhere just to contradict something that is true

charsmax = 32 -1

XD

It is more stupid not to use the head to do a simple subtraction, if the array were changing over time, if you would have to use charsmax to do the operation, it is something logical

Last edited by MrPickles; 11-17-2022 at 21:29.
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-17-2022 , 21:29   Re: Storing string in cVar
Reply With Quote #12

Quote:
Originally Posted by MrPickles View Post
If the array will always be at 32, what maintenance? You should also recommend it to Bugsy so, if the array will always be 32, the charsmax will always be 31, an unnecessary operation, it makes me laugh when they take arguments from anywhere just to contradict something that is true
If you have a larger code base where not everything is visible on the screen at the same time then it's not so clear that 31 is actually the correct value. If you need to make the string longer, you would have to make the change in several places instead of just the array declaration.

That code that you linked to was from 2010. In most of the code that Bugsy posts lately, he does use sizeof and charsmax.

Also, as I told you in the other thread, there are reasons to do things certain ways that provide benefits that may take a few nano seconds longer. I've never said that it was not more efficient so don't claim that I did, I've only ever told you that it's negligible.
__________________
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 21:32   Re: Storing string in cVar
Reply With Quote #13

Quote:
Originally Posted by fysiks View Post
If you have a larger code base where not everything is visible on the screen at the same time then it's not so clear that 31 is actually the correct value. If you need to make the string longer, you would have to make the change in several places instead of just the array declaration.

That code that you linked to was from 2010. In most of the code that Bugsy posts lately, he does use sizeof and charsmax.

Also, as I told you in the other thread, there are reasons to do things certain ways that provide benefits that may take a few nano seconds longer. I've never said that it was not more efficient so don't claim that I did, I've only ever told you that it's negligible.
As I said if the size of the array changes over time (and I don't mean changing the size manually ), you would need to use charsmax, but since it will always be 32, the charsmax will always be 31, so it's a dumb operation, if you say What are you going to look for in the super long code, you will have to go down to where you created the array, at that moment you change the subtraction done, it is not that difficult, if it is not more comfort than doing something more efficient
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-17-2022 , 21:36   Re: Storing string in cVar
Reply With Quote #14

Quote:
Originally Posted by MrPickles View Post
As I said if the size of the array changes over time (and I don't mean changing the size manually ), you would need to use charsmax, but since it will always be 32, the charsmax will always be 31, so it's a dumb operation, if you say What are you going to look for in the super long code, you will have to go down to where you created the array, at that moment you change the subtraction done, it is not that difficult, if it is not more comfort than doing something more efficient
It is not a dumb operation. When you have large code, it makes it easier to introduce a bug into the code when you're having to manually change a value in several places when you're only actually changing a single functional value. Also, they are magic numbers.
__________________
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 21:38   Re: Storing string in cVar
Reply With Quote #15

Quote:
Originally Posted by fysiks View Post
It is not a dumb operation. When you have large code, it makes it easier to introduce a bug into the code when you're having to manually change a value in several places when you're only actually changing a single functional value. Also, they are magic numbers.
several places?, they only change in 2 instead of 1, you are being too serious for something so simple, but more efficient if you do the operation yourself, it is comfort, but not efficiency, simply that, it is not very difficult to change a single number
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-17-2022 , 21:42   Re: Storing string in cVar
Reply With Quote #16

Quote:
Originally Posted by MrPickles View Post
several places?, they only change in 2 instead of 1, you are being too serious for something so simple, but more efficient if you do the operation yourself, it is comfort, but not efficiency, simply that, it is not very difficult to change a single number
It's about developing good habits for future code and reducing the potential for bugs.
__________________
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 22:01   Re: Storing string in cVar
Reply With Quote #17

Quote:
Originally Posted by fysiks View Post
It's about developing good habits for future code and reducing the potential for bugs.
I don't see any future bug for an exact subtraction

if you have an array of 32 cells, you put 31 in it
if for some reason you later change it to 46, you also have to change it to 45

It is something really simple that you get very complicated and use a function

bugs come from things you don't do well, if you do everything right, you don't need extra functions or operations that make your work easier, instead of making the work of the code and the machine easier
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-17-2022 , 22:10   Re: Storing string in cVar
Reply With Quote #18

Quote:
Originally Posted by MrPickles View Post
I don't see any future bug for an exact subtraction

if you have an array of 32 cells, you put 31 in it
if for some reason you later change it to 46, you also have to change it to 45

It is something really simple that you get very complicated and use a function

bugs come from things you don't do well, if you do everything right, you don't need extra functions or operations that make your work easier, instead of making the work of the code and the machine easier
That fine and dandy for small bits of code.
__________________
fysiks is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-17-2022 , 22:13   Re: Storing string in cVar
Reply With Quote #19

Quote:
Originally Posted by fysiks View Post
It's because you never actually populated the string.
Thanks a lot, much appreciated!
But I have a question.

Instead of making many cvars and variables I would like to parse a long string like I mentioned before.
But I'm not sure how to handle a user NOT placing a weapon in the string.

For example, I can use the parse function to split:
"ak47 usp flash flash smoke"
Only if I know the user will put exactly four items in there.

The only solution I can think of is making tons of cvars like:

PHP Code:
new g_cVarTerroristPrimWepRound1
new g_cVarTerroristSecWepRound1
new g_cVarTerroristGrenadeRound1
new g_cVarTerroristArmorRound1 
But it looks like shit and takes a lot of time.
Any ideas on how to solve this in a clean way?
Maybe telling the user to put "weapon_none" and follow a syntax?

Thanks again.
GoldNux is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 22:13   Re: Storing string in cVar
Reply With Quote #20

Quote:
Originally Posted by fysiks View Post
That fine and dandy for small bits of code.
what elegance? if those are your priorities and "good habits" when coding you are very bad, in a code efficiency, saving unnecessary operations, making it more optimal are real priorities, and well, in 3 pieces of code they are unnecessary, imagine that you make 3 plugins with 3000 lines coded in this "elegant" way
MrPickles 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 16:18.


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