Raised This Month: $ Target: $400
 0% 

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
nergal
Veteran Member
Join Date: Apr 2012
Old 03-18-2017 , 14:23   Re: New API and Syntax
Reply With Quote #851

Quote:
Originally Posted by abrandnewday View Post
This x1000. I've actually pushed myself to learn to use StringMaps, ArrayLists, DataPacks as well as learning to use menus and panels more efficiently under new syntax via the methodmaps. Next up on my list is KeyValues which I am not looking forward to as I've never messed around with while and do before. But I really want to get into making config files for things, so I have to learn it.
do-while loops are loops that you need to run at least once but it can possibly run again.
__________________
nergal is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-18-2017 , 16:15   Re: New API and Syntax
Reply With Quote #852

Actually, scratch that, I have messed with while a little bit. In my private chat tag plugin I commissioned (then made my own major modifications to), it uses while for the SQL_TQuery's;

PHP Code:
while (SQL_FetchRow(hHandle))
{
    
int iID SQL_FetchInt(hHandle0);
    
    
char sTag[256];
    
SQL_FetchString(hHandle1sTagsizeof(sTag));
    
    
char sID[12];
    
IntToString(iIDsIDsizeof(sID));
    
    
char sDisplayName[256];
    
SQL_FetchString(hHandle2sDisplayNamesizeof(sDisplayName));
    
    if (
strlen(sTag) > 0)
    {
        
hTagsTrie.SetString(sIDsTag);
        
hDisplayTrie.SetString(sIDsDisplayName);
    }

But no, I've not messed with do-while loops (like in keyvalues for config files) very much as I've never done any config file stuff for my plugins.

Last edited by 404UserNotFound; 03-18-2017 at 16:27.
404UserNotFound is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 03-19-2017 , 07:41   Re: New API and Syntax
Reply With Quote #853

Quote:
Originally Posted by abrandnewday View Post
This x1000. I've actually pushed myself to learn to use StringMaps, ArrayLists, DataPacks as well as learning to use menus and panels more efficiently under new syntax via the methodmaps. Next up on my list is KeyValues which I am not looking forward to as I've never messed around with while and do before. But I really want to get into making config files for things, so I have to learn it.
Here's you a sample bit of code to get started. You can find everything else you need in the API.
https://sm.alliedmods.net/new-api/keyvalues/KeyValues

Spoiler


Here would be an example cfg to go with that:

Spoiler
__________________

Last edited by ThatOneGuy; 03-20-2017 at 22:19.
ThatOneGuy is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-19-2017 , 19:56   Re: New API and Syntax
Reply With Quote #854

Ooh, that's some good info. I've got an idea of how to write up the actual configs, it's just a matter of working backwards and figuring out how to code the functions to make the config file work how I want it to. Thanks

Side question: Regarding this bit:

PHP Code:
KeyValues oKeyValues null;
oKeyValues = new KeyValues("Setups"); 
Is this something I should be doing? I usually do this:

PHP Code:
KeyValues oKeyValues = new KeyValues("Setups"); 

Last edited by 404UserNotFound; 03-19-2017 at 20:01.
404UserNotFound is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 03-20-2017 , 22:19   Re: New API and Syntax
Reply With Quote #855

Quote:
Originally Posted by abrandnewday View Post
Ooh, that's some good info. I've got an idea of how to write up the actual configs, it's just a matter of working backwards and figuring out how to code the functions to make the config file work how I want it to. Thanks

Side question: Regarding this bit:

PHP Code:
KeyValues oKeyValues null;
oKeyValues = new KeyValues("Setups"); 
Is this something I should be doing? I usually do this:

PHP Code:
KeyValues oKeyValues = new KeyValues("Setups"); 
Yes. That was a relic of some code that I put together a while back and haven't updated that part. I'll update my previous post just now. I'm not sure why I did it that way for that plugin.
__________________
ThatOneGuy is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-21-2017 , 01:25   Re: New API and Syntax
Reply With Quote #856

Ah, so it is the old way. Makes sense.

Last edited by 404UserNotFound; 03-21-2017 at 01:26.
404UserNotFound is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-21-2017 , 01:57   Re: New API and Syntax
Reply With Quote #857

It's not the old way. It's just a longer way of doing the same thing.

PHP Code:
int someResult//or " int someResult = 0; "
someResult someFunction(); 
as opposed to
PHP Code:
int someResult someFunction(); 
The old way of creating a new KeyValues structure would be something like this:

PHP Code:
new Handle:oKeyValues CreateKeyValues("Setups"); 
__________________

Last edited by ddhoward; 03-21-2017 at 01:58.
ddhoward is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 03-21-2017 , 04:14   Re: New API and Syntax
Reply With Quote #858

Quote:
Originally Posted by ddhoward View Post
-snip-
This^

It is the longer way, but personally I think it often times looks much cleaner to separate var declaration from it's initialization when I have a bunch of things that way it's a little easer to see. Just a matter of preference.

I do it more in java than sourcemod
Java

Last edited by headline; 03-21-2017 at 04:14.
headline is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 03-21-2017 , 04:56   Re: New API and Syntax
Reply With Quote #859

Will 'decl' have a comeback or is there a heuristic in the compiler now?
Timocop is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-21-2017 , 05:20   Re: New API and Syntax
Reply With Quote #860

Quote:
Originally Posted by Timocop View Post
Will 'decl' have a comeback or is there a heuristic in the compiler now?
The consensus is that decl is pretty pointless, is dangerous, was a mistake to have implemented into SourcePawn in the first place, and if what you're doing actually requires decl to perform adequately, then an alternative to what you're doing should be found (such as making the variable static/global if possible, etc.)
__________________
ddhoward 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:12.


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