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

Solved [Optimize] How to...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 12-20-2017 , 10:42   [Optimize] How to...
Reply With Quote #1

Hello everyone,

Question: which of types variables to be best place for storing data for menus?
Possible answers:
KeyValues?
2 x ArrayList?
Global MenuHandle?

Which of this will be faster?
Ex:
HTML Code:
data - "Key1" => "Helloworld" <- 2xArrayList? KeyValues? MenuHandle?

Then we will create menu from data:

Menu:
1. Helloworld

Last edited by neatek; 06-18-2019 at 05:55.
neatek is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 12-20-2017 , 11:28   Re: [Optimize] How to...
Reply With Quote #2

I'm fond of KeyValues since you can load a configuration file and iterate over the KeyValues handle, adding the menu entries as you go.

Never used a global Menu handle, but if you're able to generate the menu once and reuse the handle just for displaying, that would probably be better.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 12-20-2017 , 12:22   Re: [Optimize] How to...
Reply With Quote #3

Quote:
Originally Posted by nosoop View Post
Never used a global Menu handle, but if you're able to generate the menu once and reuse the handle just for displaying, that would probably be better.
yep, only one time.

Question2: How to check MySQL connection? Is connected or not connected?

PHP Code:
Handle StableConnection null// Handle? Or Database?

public void DB_CreateConnect() {
    
// here, how to check MySQL Connection?
    // != null  ?! or != INVALID_HANDLE?
    
if(StableConnection != null)  {
        
LogError("Cant connect to database, connection already exists.");
    }

    if(!
SQL_CheckConfig("some_of_databases.cfg")) {
        
LogError("Cant find 'some_of_databases.cfg' in databases.cfg");
    }

    
SQL_TConnect(DB_Callback"some_of_databases.cfg");
}

public 
void DB_Callback(Handle ownerHandle hndl, const char[] errorany data)
{
    if (
hndl == null)
    {
        
LogError("Connection to SQL database has failed! Error: %s"error);
        return;
    }

    
StableConnection hndl;
    
SQL_SetCharset(hndl"utf8");
    
PrintToServer("Successful connect to database.");


Last edited by neatek; 12-20-2017 at 12:27.
neatek is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 12-20-2017 , 17:10   Re: [Optimize] How to...
Reply With Quote #4

Quote:
Originally Posted by neatek View Post
PHP Code:
Handle StableConnection null// Handle? Or Database?
// here, how to check MySQL Connection?
// != null  ?! or != INVALID_HANDLE? 
Check if != null, meaning connection is not nullified aka connected. or check if == null meaning not connected, and return the error.
Handle? Or Database? -> Database
null or INVALID_HANDLE -> null

Also for connection use this little beauty https://sm.alliedmods.net/new-api/dbi/Database/Connect and for queries https://sm.alliedmods.net/new-api/dbi/Database/Query

Something like this for reference:

PHP Code:
Database StableConnection null

public 
void OnPluginStart()
{
    
Database.Connect(OnDatabaseConnect"my_database_name");
}

public 
void OnDatabaseConnect(Database idb, const char[] errorany data)
{
    if (
idb == null || strlen(error) > 0)
    {
        
PrintToServer("[Mysql] Unable to connect to database (%s)"error);
        
LogError("[Mysql] Unable to connect to database (%s)"error);
        return;
    }
    else
    {
        
//Set to our global variable database named "StableConnection"
        
StableConnection idb;
        
        
//Do a query of your choice upon connection?
        
char sQuery[512];
        
FormatEx(sQuerysizeof(sQuery), "DELETE FROM my_database_name WHERE map = 'de_dust2'"); //Example (non serious) query, change this to whatever you want...
        
        //Send query
        
StableConnection.Query(SQL_ErrorChecksQuery_DBPrio_Normal);

        
//Log Success Print.
        
LogMessage("[Mysq] Successfully connected to database!");
    }
}

//Callback Function to check for errors
public void SQL_ErrorCheck(Handle ownerDBResultSet results, const char[] errorany data)
{
    if (
results == null || strlen(error) > 0)
    {
        
LogError("[Mysql] Query failed! %s"error);
    }

__________________
xines 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 20:10.


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