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
  #1  
Old 02-03-2008, 04:45 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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
__________________
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 11:42 PM.


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