Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2007, 04:34 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Generic Sorting

For those who wanted to know what use does variable functions do... Here's an example:

class: math-sort
PHP Code:
function defaultSortsideAsideB )
  {
  return (
sideA sideB);
  }

function 
sortList( list, compFunc )
  {
  
this.sortFunc = ( compFunc == null this.defaultSort compFunc );

  for ( 
temp.0temp.< list.size() - 1temp.i++ )
    {
    
temp.min temp.i;
    for ( 
temp.temp.1temp.< list.size(); temp.++ )
      {
      if ( 
sortFunc( list[temp.j], list[temp.min]) )
        
temp.min temp.j;
      }

    
temp.= list[temp.i];
    list[
temp.i] = list[temp.min];
    list[
temp.min] = temp.b;
    }

  return list;
  } 
PHP Code:
function onCreated()
  {
  
join("math-sort");
  
temp.= {{1,3},{3,2},{2,1},{4,2} };

  
temp.func = function(sideAsideB)
    {
    return ( 
sideA[0] < sideB[0] );
    };

  
temp.list = sortListtemp.ltemp.func );
  echo( 
temp.list ); // {{1, 3}, {2, 1}, {3, 2}, {4, 2}}
  

You could have them sorted by this function...

A practical use of this is sorting a list of NPCs with respect to how far it is!
One way to do this is simply defining this function:

PHP Code:
  temp.func = function(sideAsideB)
    {
    return ( (
sideA.this.x)^+ (sideA.this.y)^< (sideB.this.x)^+ (sideB.this.y)^);
    }; 
Reply With Quote
  #2  
Old 05-22-2007, 12:49 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Good job Novo!
I didn't think of using it that way
__________________
Do it with a DON!
Reply With Quote
  #3  
Old 05-22-2007, 09:53 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
You suck, at trying to disappoint me that is!
__________________
Reply With Quote
  #4  
Old 05-23-2007, 06:32 PM
sam_is_me sam_is_me is offline
Registered User
Join Date: Sep 2004
Posts: 195
sam_is_me is on a distinguished road
lol, i really cant read that script...
but if it works, hey, good job.
__________________
Aim: xxspazmxx929


Reply With Quote
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 +2. The time now is 09:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.