Jump to content
  • 0

Special Variables or query_sql?


Brainstorming

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   4
  • Joined:  01/22/13
  • Last Seen:  

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
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10018
  • Reputation:   2371
  • Joined:  10/28/11
  • Last Seen:  

- 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...

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   4
  • Joined:  01/22/13
  • Last Seen:  

- 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.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

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

Link to comment
Share on other sites

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.

×
×
  • Create New...