Jump to content
  • 0

Special Variables or query_sql?


Question

Posted (edited)

This is a short example of what i'm meaning. I want to know what do you think is better for script optimization:

Using Special Variables:

...
mes "Player ID: "+[color=#000000]getcharid(.@CharName$);[/color]
mes "Player Sex: "+((sex==0)?"Female":"Male");
mes "Player Level: "+BaseLevel+" / "+JobLevel;
mes "Player "+((upper==2)?"Is Child":"Is not Child");
...

Using query_sql:


...
query_sql("SELECT char_id,sex,base_level,job_level,father WHERE name = '"+escape_sql([color=#000000].@CharName$[/color])+"';"),.@CH_ID,.@CH_Sex$,.@CH_Blvl,.@CH_Jlvl,.@CH_Father);

mes "Player ID: "+.@CH_ID[color=#000000];[/color]
mes "Player Sex: "+((.@CH_Sex$=="F")?"Female":"Male");
mes "Player Level: "+.@CH_Blvl+" / "+.@CH_Jlvl;
mes "Player "+((.@CH_Father!=0)?"Is Child":"Is not Child");
...

First case:

- 1 temp string variable.

- 4 Special Variables (Sex, BaseLevel, JobLevel, Upper).

- 5 queries (getcharid to retrieve Char_ID and 1 query for every Special Variable).

Second Case:

- 6 temp variables (2 of them strings).

- Only 1 query.

What is your suggestion? Case one (less variables, more queries) or case two (less queries, more variables)?

Edited by Brainstorming

3 answers to this question

Recommended Posts

Posted

- 5 queries (getcharid to retrieve Char_ID and 1 query for every Special Variable).

huh ? those "special variable" need to run as query ?? isnt that is same as variable ? just direct retrieved ...it dont need any query to execute...it should work the same like other variable stuff....

but method 1 only work when there is a attached player

method 2 will work to search for any players.....even offline...

Posted

- 5 queries (getcharid to retrieve Char_ID and 1 query for every Special Variable).

huh ? those "special variable" need to run as query ?? isnt that is same as variable ? just direct retrieved ...it dont need any query to execute...it should work the same like other variable stuff....

but method 1 only work when there is a attached player

method 2 will work to search for any players.....even offline...

Forget about it... After reading it again I understand that's something wrong. Special Variables retrieve local variables of the character executing script. So, if I want to know mines BaseLevel, both works and first one is better. But if I want to retrieve BaseLevel from someone else, first one won't work.

Posted

you can actually retrieve the value from other online players via attachrid

and it should be faster/optimized than running a query_sql, I guess

however considering the speed, actually both doesn't really different much, nobody will feel the micro-second lag

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...