Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-10-2009, 11:53 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
Wildcard Finder

I got bored, so I made this simple wildcard finder.

PHP Code:
// Made by Chompy
/* 
   Only supports one wildcard!

   find(str, arr[], bool)

   Syntax defines what to search for.

   Array is a member of all strings to compare with.

   Strict determines if it will use stricter filter rules on output.
   ("foo*" would not return "foo" in the output array for example)

*/
function find(syntax, array, strict) {
  
temp.pos syntax.pos("*");
  if (
pos == -1) {
    return {array[array.
index(syntax)]};
  }
  else {
    
temp.0temp.""temp."";
    if (
pos 1) { // *x
      
1;
      
syntax.substring(1);
    }
    if (!(
pos == syntax.length()-1) && == 0) { // x*x
      
2;
      
syntax.substring(pos+1);
      
syntax.substring(0syntax.length()-1-c.length());
    }
    if (
pos == syntax.length()-1) { // x*
      
3;
      
syntax.substring(0pos);
    }
    if (
0) {
      
temp.out 0;
      
temp.compare syntax.substring(0pos);
      
compare @= syntax.substring(pos+1);
      for(
temp.: array) {
        if (
strict && == compare) continue;
        if (
== 1) {
          if (
i.ends(c)) out.add(i);
        }
        else if (
== 2) {
          if (
i.starts(b) && i.ends(c)) out.add(i);
        }
        else if (
== 3) {
          if (
i.starts(b)) out.add(i);
        }
      }
      return 
out;
    }
  }
  return 
0;

Example:

PHP Code:
function onCreated() { 
  
temp.= {"foo""foo1""bar""barfoo""baroo"};
  
  
temp.find("foo*"a); // foo,foo1
  
temp.find("foo*"atrue); // foo1,
  
  
temp.find("bar*oo"a); // barfoo,baroo
  
temp.find("bar*oo"atrue); // barfoo
  
  
temp.find("*o"a); // foo,barfoo,baroo
  
  
temp.find("*"a); // foo,foo1,bar,barfoo,baroo

Please post any bugs and criticism below I guess.
__________________
Reply With Quote
  #2  
Old 03-11-2009, 12:08 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Very nice, I like it.
__________________
Reply With Quote
  #3  
Old 03-11-2009, 12:39 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Nice work man
Reply With Quote
  #4  
Old 03-11-2009, 07:52 AM
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
Thanks guys.

I'll probably release a new version soon though, which will support more then one wildcard :]
__________________
Reply With Quote
  #5  
Old 03-11-2009, 08:10 AM
MiniOne MiniOne is offline
SomeOne
MiniOne's Avatar
Join Date: Dec 2006
Location: Australia
Posts: 1,145
MiniOne is on a distinguished road
Send a message via MSN to MiniOne
Seems right
Good work keep it up.
__________________
Quote:
Originally Posted by Huwajux View Post
The pistols look like they have cancer, reduce the big buboe shaped thing's size.
Reply With Quote
  #6  
Old 03-12-2009, 12:34 AM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
This was a bit rushed but here is my version of the Wildcard Finder I hope it works as you want it to work.

PHP Code:
function onCreated() {
  
temp.= {"foo1231594","foo437793","bar1234","bar4321","moo4567"};
  
temp.findWildcard("foo*3*9*",temp.a); // foo1231594,foo437793

PHP Code:
function findWildcard(syntax,array) {
  if (
temp.syntax == "*")
    return 
temp.array;
  if (
temp.syntax.pos("*") == - 1)
    return (
temp.array.index(temp.syntax) > - temp.array[temp.array.index(temp.syntax)] : false);
  
  
temp.newsyntax = {};  
  
this.syntaxend = !temp.syntax.ends("*");  
  while (
temp.syntax.pos("*") > - 1) {
    if (!(
temp.syntax.pos("*"in {0,temp.syntax.length()}))
      
temp.newsyntax.add(temp.syntax.substring(0,temp.syntax.pos("*")));
    
temp.syntax temp.syntax.substring(temp.syntax.pos("*") + 1);
  }
  if (
temp.syntax != "")
    
temp.newsyntax.add(temp.syntax);
    
  
temp.copysyntax = {};
  for (
temp.stemp.newsyntax) {
    
temp."";
    for (
temp.0temp.temp.s.length(); temp.++)
      
temp.@= "*";
    
temp.copysyntax.add(temp.r);
  }
  
  
this.syntax temp.newsyntax;
  
this.syntaxcopy temp.copysyntax;
  
  
temp.result = {};
  for (
temp.checktexttemp.array) {
    
temp.check checkText(temp.checktext);
    if (
temp.check != false)
      
temp.result.add(temp.check);
  }
  return (
temp.result.size() > temp.result false);
}

function 
checkText(realtext) {
  if (
this.syntaxend && !temp.realtext.ends(this.syntax[this.syntax.size() - 1]))
    return 
false;
  
temp.highest = - 1;
  
temp.checktext temp.realtext;
  for (
temp.0temp.this.syntax.size(); temp.++) {
    
temp.checkpart this.syntax[temp.c];
    if (
temp.checktext.pos(temp.checkpart) == - 1)
      return 
false;
    
    if (
temp.checktext.pos(temp.checkpart) > temp.highest) {
      
temp.checkpos temp.checktext.pos(temp.checkpart);
      
temp.checktext temp.checktext.substring(0,temp.checkpos) @ 
                       
this.syntaxcopy[temp.c] @ 
                       
temp.checktext.substring(temp.checkpos this.syntaxcopy[temp.c].length());
                       
      
temp.highest temp.checkpos;
    }
    else
      return 
false;
  }    
  return 
temp.realtext;

__________________
Reply With Quote
  #7  
Old 03-12-2009, 12:53 AM
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
Nice script Dan
__________________
Reply With Quote
  #8  
Old 03-12-2009, 01:00 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Nice work guys
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #9  
Old 03-12-2009, 07:53 AM
MiniOne MiniOne is offline
SomeOne
MiniOne's Avatar
Join Date: Dec 2006
Location: Australia
Posts: 1,145
MiniOne is on a distinguished road
Send a message via MSN to MiniOne
Nice Dan
OMGG That gives me a great idea for a zone event, I'd like to discuss it with you
reply my emails...
__________________
Quote:
Originally Posted by Huwajux View Post
The pistols look like they have cancer, reduce the big buboe shaped thing's size.
Reply With Quote
  #10  
Old 03-12-2009, 07:08 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Thanks for the comments My script doesn't have the "strict" stuff yet but that shouldn't be hard.
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:47 PM.


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