Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Basic object arrays (https://forums.graalonline.com/forums/showthread.php?t=78587)

Chompy 02-03-2008 04:45 PM

Basic object arrays
 
PHP Code:

/*
  Scripted by Chompy v0.1
*/
public function array(a) {
  
this.array = a;
  return 
this.array;
}
public function 
debug() {
  return 
this.array;
}
public function 
debug2() {
  echo(
this.array);
}
public function 
sub(se) {
  return 
this.array.subarray(s: -1);

public function 
getsize() {
  return 
this.array.size();
}
public function 
getindices(v) {
  
temp.out 0temp.0;
  for(
temp.this.array) {
    if (
== vout.add(i);
    
++;
  }
  return 
out;
}
public function 
addlist(a) {
  if (
a.type() == 3) {
    for(
temp.a) {
      
this.array.add(m);
    }
  }
}
public function 
hasvalue(v) {
  return (
this.array.index(v) > -1);
}
public function 
hasindex(i) {
  return (
this.array[i] != NULL);
}
public function 
addvalue(v) {
  
this.array.add(v);
}
public function 
removevalue(vmode) {
  while(
this.array.index(v) > -1) {
    
this.array.delete(this.array.index(v));
    if (!
mode) break;
  }
}
public function 
removeindex(i) {
  if (
this.array.size()) this.array.delete(i);
}
public function 
addindex(iv) {
  
this.array.insert(iv);


I was kinda inspired by Knight's Associative array code (http://forums.graalonline.com/forums...ad.php?t=68643),
so I decided to make my own :o This is just the first version, alot more functions will come, so suggestions would be nice :)

Example of usage:

PHP Code:

function onCreated() {
  
this.object = new TStaticVar();
  
this.object.join("util_array");  // change this to the class you putted the code into
  
  
echo(this.object.array({"foo""bar"})); // creates the array and echoes it
  
  
this.object.addlist({"baz""baz""baz"}); // adds a list of members to the array
  
this.object.debug2(); // echoes the current array
  
  
echo(this.object.sub(2)); // works like obj.subarray()
  
echo(this.object.hasvalue("bar")); // if the array contains "bar"
  
echo(this.object.getindices("baz")); // obj.indices
  
echo(this.object.addindex(2"lol")); // obj.insert
  
echo(this.object.removeindex(1)): // obj.delete
  
echo(this.object.addvalue("lol")); // obj.add
  
echo(this.object.getsize()); // obj.size()
  // etc.


And again, will work on it, so suggestions for functions/things I could add would be nice :)

Rapidwolve24 02-03-2008 05:01 PM

I don't understand why you made this when the functions are already there.

Chompy 02-03-2008 05:44 PM

Quote:

Originally Posted by Rapidwolve24 (Post 1373469)
I don't understand why you made this when the functions are already there.

:) Because I can. This is just the basic features (It's not done), gonna add more advanced functions that normal arrays don't have ;)


All times are GMT +2. The time now is 06:31 PM.

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