SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 04/01/2020, 07:38 AM   #1
zowzow
Little Clucker
 
Join Date: Nov 2018
Location: Ifa4uu9T36
Posts: 37
Reputation: 0
Default Optimization

So all these code I've use to set the job reward
I don't know how bad code is just wanna know what should I do with it by "Optimization"

PHP Code:
new jobFish 0;
new 
jobTrash 0;
new 
jobPearl 0;
new 
jobWood 0;
new 
jobDurian 0;
new 
jobSteel 0;
new 
jobWeed 0;
new 
jobYaba 0;
new 
jobOpium 0;
new 
jobSeaweed 0;

forward Job_Load();
public 
Job_Load()
{
    new 
count_job 0;
    new 
CacherStuff mysql_query(dbCon"SELECT * FROM jobprice");
    for ( new 
icache_num_rows ( ); != j; ++)
    {
        
cache_get_value_int(i"JobFish"jobFish);
        
cache_get_value_int(i"JobTrash"jobTrash);
        
cache_get_value_int(i"JobPearl"jobPearl);
        
cache_get_value_int(i"JobWood"jobWood);
        
cache_get_value_int(i"JobDurian"jobDurian);
        
cache_get_value_int(i"JobSteel"jobSteel);
        
cache_get_value_int(i"JobWeed"jobWeed);
        
cache_get_value_int(i"JobYaba"jobYaba);
        
cache_get_value_int(i"JobOpium"jobOpium);
        
cache_get_value_int(i"JobSeaweed"jobSeaweed);
        
count_job++;
    }
    
printf"MySQL: (%d) `jobprice` succesfuly loaded."count_job);
    
cache_delete(rStuff);
    return 
1;
}
forward Job_Save();
public 
Job_Save()
{
    new 
string[256];
    
mysql_format(dbConstringsizeof(string), "UPDATE `jobprice` SET JobFish = '%d', JobTrash = '%d', JobPearl = '%d', JobWood = '%d', JobDurian = '%d', JobSteel = '%d', JobWeed = '%d', JobYaba = '%d', JobOpium = '%d', JobSeaweed = '%d'",
    
jobFish,jobTrash,jobPearl,jobWood,jobDurian,jobSteel,jobWeed,jobYaba,jobOpium,jobSeaweed);
    
mysql_tquery(dbConstring);
    return 
1;

zowzow is offline   Reply With Quote
Old 04/01/2020, 09:41 AM   #2
ShadowMortar
Big Clucker
 
ShadowMortar's Avatar
 
Join Date: Jul 2016
Location: Croatia
Posts: 146
Reputation: 24
Default Re: Optimization

People who hate you, will always tell you that you are a bad developer, that you don't know anything, and I know that from personal occasion. People who want you to genuinely improve will suggest you how to. I honestly don't know you, however, not every time the optimization matters.
This is what I was told, and since then I accept advices, but barely listen to those who are like "THIS CODE SUCKS, THIS IS SHIT", etc..
->https://forum.sa-mp.com/showthread.php?t=669090
Quote:
Originally Posted by CheezIt View Post
Follow your heart and own style, doesn't matter
__________________
Quote:
Originally Posted by CheezIt View Post
Follow your heart and own style.
Feel free to PM me if you need help.
ShadowMortar is offline   Reply With Quote
Old 04/01/2020, 09:50 AM   #3
Banditul18
Huge Clucker
 
Join Date: Nov 2014
Location: Brasov,Romania
Posts: 402
Reputation: 32
Default Re: Optimization

Only thing i would do to that code is uzing inline mysql_tquery other than that is completly fine
Banditul18 is offline   Reply With Quote
Old 04/01/2020, 10:39 AM   #4
coool
Gangsta
 
coool's Avatar
 
Join Date: Feb 2013
Location: Republic of Pakistan
Posts: 610
Reputation: 54
Default Re: Optimization

I don't have an optimization (you don't need it) but variables have 0 value by default.
__________________
coool is offline   Reply With Quote
Old 04/01/2020, 02:32 PM   #5
Modather
Little Clucker
 
Join Date: Sep 2017
Posts: 4
Reputation: 0
Default Re: Optimization

Use local variables instead.
And use

cache_get_value_index_int(row_idx, column_idx, &destination);
Instead of cache_get_value_int. The above one is definitely faster.

Also you don't need count_job cuz you already got cache_num_rows
Modather is offline   Reply With Quote
Old 04/01/2020, 06:20 PM   #6
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: Optimization

Quote:
Originally Posted by Modather View Post
And use

cache_get_value_index_int(row_idx, column_idx, &destination);
Instead of cache_get_value_int. The above one is definitely faster.
It is exactly the same. It calls appropriate function based on the type of the second parameter.
__________________
Calisthenics is offline   Reply With Quote
Old 10/01/2020, 08:51 PM   #7
Mohny
Little Clucker
 
Join Date: Dec 2019
Location: 127.0.0.1
Posts: 1
Reputation: 0
Smile Re: Optimization

Code Smart.

Code:
new jobFish, jobTrash, jobPearl, jobWood, jobDurian, jobSteel,
    jobWeed, jobYaba, jobOpium, jobSeaweed;
Mohny is offline   Reply With Quote
Reply

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimization Micko123 Scripting Help 12 04/05/2016 11:22 AM
Optimization Etolas Scripting Help 12 20/02/2015 11:43 PM
Optimization anou1 Scripting Help 14 13/02/2014 08:57 PM
Optimization OnY Scripting Help 1 15/12/2013 01:34 AM


All times are GMT. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.