Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   "Reversing" Arrays (https://forums.graalonline.com/forums/showthread.php?t=72212)

projectigi 02-15-2007 06:14 PM

"Reversing" Arrays
 
Hrm, is there a function that reverses a array?
like
this.array[ 0 ] = 2;
this.array[ 1 ] = 3;
this.array[ 2 ] = 1;

now this.array.reverse(); or something like this would make

this.array[ 0 ] == 1;
this.array[ 1 ] == 3;
this.array[ 2 ] == 2;

Chompy 02-15-2007 07:44 PM

Make a function for it..?

Chandler 02-15-2007 07:52 PM

Can I ask why you would want to do this?

PHP Code:

  temp.myArray = {35"test"};
  for (
temp.curPar = (temp.myArray.size() - 1); temp.curPar > -1temp.curPar--)
  {
    
temp.newArray.add(temp.myArray[temp.curPar]);
  }
  echo(
temp.newArray); 


projectigi 02-15-2007 08:01 PM

making a function is easy

but before i make a function i ask if theres already another function that does the same thing

Gambet 02-15-2007 08:02 PM

Quote:

Originally Posted by projectigi (Post 1277970)
making a function is easy

but before i make a function i ask if theres already another function that does the same thing


You should check the wiki more often.

Chandler 02-15-2007 08:10 PM

Quote:

Originally Posted by projectigi (Post 1277970)
making a function is easy

but before i make a function i ask if theres already another function that does the same thing

There isn't an option :(

Admins 02-15-2007 09:27 PM

There is not (yet). We could add a few more string and array operators if wanted though.

projectigi 02-16-2007 12:15 AM

Well, the wiki's search function sucks

xXziroXx 02-16-2007 01:57 AM

Quote:

Originally Posted by projectigi (Post 1278044)
Well, the wiki's search function sucks

Go to for example the clientside scripting page, CTRL + F and type in what you are looking for. Voilá, check mate.

Inverness 02-16-2007 02:06 AM

Some string functions I use sometimes.

ReverseArray:
PHP Code:

public function reversearray(temp.array) {
  
temp.newarray;
  
temp.i;
  
  
newarray "";
  for (
= array.size() - 1> -1--) {
    
newarray.add(array[i]);
  }
  return 
newarray;


ReverseString:
PHP Code:

public function reversestring(temp.string) {
  
temp.i;
  
temp.out;
  
  for (
string.length() - 1> -1--) {
    
out @= string.charat(i);
  }
  return 
out


ReplaceSubString:
PHP Code:

public function replacesubstring(temp.stringtemp.positiontemp.lengthtemp.newstring) {
  
temp.stringa;
  
temp.stringb;
  
temp.outstring;
  
  if (
position 0) {
    return;
  }
  
stringa string.substring(0position);
  
stringb string.substring(position length, -1);
  
outstring stringa newstring stringb;
  return 
outstring;




All times are GMT +2. The time now is 04:26 PM.

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