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 , 22:20   Re: Storing string in cVar
Reply With Quote #21

Quote:
Originally Posted by GoldNux View Post
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.
I think this could guide you through that, it doesn't use cvars, but I could help you with the issue of giving the weapons and the strings use

https://forums.alliedmods.net/showthread.php?t=245803

Last edited by MrPickles; 11-17-2022 at 22:20.
MrPickles is offline
GoldNux
Senior Member
Join Date: Mar 2018
Old 11-17-2022 , 22:56   Re: Storing string in cVar
Reply With Quote #22

Quote:
Originally Posted by MrPickles View Post
I think this could guide you through that, it doesn't use cvars, but I could help you with the issue of giving the weapons and the strings use

https://forums.alliedmods.net/showthread.php?t=245803
Very nice! Thanks a ton.
I will take a look at it tomorrow.

5 am over here, time to get some sleep.
Goodnight thanks again.
GoldNux is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-17-2022 , 22:59   Re: Storing string in cVar
Reply With Quote #23

Quote:
Originally Posted by MrPickles View Post
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
I don't use 1980's computers any more.

Quote:
Originally Posted by GoldNux View Post
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.
You can parse a string into multiple strings dynamically and then validate each one as you parse them to make sure they are valid weapon names.

Whether or not to use multiple cvars really depends on how many you'd have to create. If it's just 4 and they have specific use cases then I don't see any major issues with creating 4 cvars. If you need to have more complex configuration then you probably want to do it with files instead of cvars.

To get the best advice, I think you may need to better describe what you're trying to do. How many weapons are you needing to store? How are they going to be used?
__________________
fysiks is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-17-2022 , 23:16   Re: Storing string in cVar
Reply With Quote #24

Quote:
Originally Posted by fysiks View Post
I don't use 1980's computers any more.
That lets me see what kind of coder you are lol, no matter the machine, coding efficiently and optimally should be a habit, a good habit, like i do

.....

I think that u need a menu instead of using cvars, you should adapt that plugin to a new one, a menu that opens, you choose the weapons, and when you have them all(like a shopping cart, which is what you want from what I understand) you press give for example

using many cvars for that is very tedious and inefficient, but as I said, take a look and if you still want to make a cvar ask questions

Last edited by MrPickles; 11-18-2022 at 00:55.
MrPickles is offline
zXCaptainXz
Member
Join Date: May 2017
Old 11-18-2022 , 05:55   Re: Storing string in cVar
Reply With Quote #25

Looks like you didn't hear of compile-time operations. Not all operations are handled at runtime, if the compiler detects code that doesn't need to be computed at runtime, it will automatically do that computation once and for all instead of running it every time. Don't believe it? Here's the output of an amxx decompiler (amxxdump), which is what the AMXX file contains in the end.

PHP Code:
#include <amxmodx>

new array[32]

public 
test()
{
    new 
charsmax(array)
    new 
sizeof(array) - 1
    
new 31

Code:
0x8                        PROC              ; public test()
0xC                       BREAK 
0x10                      BREAK 
                                             ; new a
0x14                     PUSH.C  0x1F       
0x1C                      BREAK 
                                             ; new b
0x20                     PUSH.C  0x1F       
0x28                      BREAK 
                                             ; new c
0x2C                     PUSH.C  0x1F       
0x34                      STACK  0xC         ; free 3 cells
0x3C                   ZERO.pri 
0x40                       RETN
PHP Code:
#include <amxmodx>

new array[32]

public 
test()
{
    new 
31
    
new 31
    
new 31

Code:
0x8                        PROC              ; public test()
0xC                       BREAK 
0x10                      BREAK 
                                             ; new a
0x14                     PUSH.C  0x1F       
0x1C                      BREAK 
                                             ; new b
0x20                     PUSH.C  0x1F       
0x28                      BREAK 
                                             ; new c
0x2C                     PUSH.C  0x1F       
0x34                      STACK  0xC         ; free 3 cells
0x3C                   ZERO.pri 
0x40                       RETN
Both versions are EXACTLY the same, in the 1st version it says 0x1F (31 in hex) 3 times despite the fact that I used sizeof and charsmax. Unless you are worried for the sanity of your system while it's compiling the plugin, using charsmax and sizeof is definitely the better option.

Last edited by zXCaptainXz; 11-18-2022 at 05:57.
zXCaptainXz is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-18-2022 , 18:48   Re: Storing string in cVar
Reply With Quote #26

Honestly @fysiks i don't know why're you still bothering with this shmuck !?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-18-2022 , 20:23   Re: Storing string in cVar
Reply With Quote #27

Quote:
Originally Posted by Natsheh View Post
Honestly @fysiks i don't know why're you still bothering with this shmuck !?
https://forums.alliedmods.net/showpo...39&postcount=3
https://forums.alliedmods.net/showpo...43&postcount=4

It seems that he has not answered yet, you are the one who knows the least the basics and speaks xd
on the other hand, absolutely off topic your post, 5 posts in a row in which you post off topic, if I were an administrator I would have banned you a while ago

Last edited by MrPickles; 11-18-2022 at 20:28.
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:35.


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