Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #18  
Old 10-12-2008, 02:32 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Programmer View Post
Zzz...

PHP Code:
function onCreated()
{
    
temp.dataSet = {16425820100541000523};
    
    echo(
temp.dataSet);
    
temp.dataSet selectionSort(temp.dataSet);
    echo(
temp.dataSet);
    
    
temp.dataSet null;
    
temp.dataSet.destroy();
}

function 
selectionSort(temp.data)
{
    for (
0temp.data.size() - 1a++)
    {
        for (
1temp.data.size(); b++)
        {
            if (
temp.data[b] < temp.data[a])
            {
                
result temp.data[b];
                
temp.data[b] = temp.data[a];
                
temp.data[a] = result;
            }
        }
    }
    
    return 
temp.data;

That would cause an error because temp.dataSet is not an object with a destroy() function. And temp variables are destroyed automatically anyways when the function is over, no need to set it to null. Also, function parameters are automatically temp, you don't need to specify it. It's also less costly to send the array by reference using temp.dataSet.link() rather than duplicating it.
PHP Code:
function onCreated() {
  
temp.dataset = {16425820100541000523};

  echo(
dataset);
  
this.selectionsort(dataset.link());
  echo(
dataset);
}
function 
selectionsort(data) {
  
temp.0;
  
temp.0;
  
temp.tmp 0;

  for (
0data.size() - 1a++) {
    for (
1data.size(); b++) {
      if (
data[b] < data[a]) {
        
tmp data[b];
        
data[b] = data[a];
        
data[a] = tmp;
      }
    }
  }

Once a temp variable is initialized it can be referenced without using the temp prefix, however using the prefix is marginally faster.

Python is superior though.
__________________
Reply With Quote
 


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 06:25 AM.


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