Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-22-2006, 06:58 PM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
String Contains?

How do I do

NPC Code:
if (strcontains(,)) { }



in GS2? I checked the basic scripting page and it's not there...

Quote:
Originally Posted by Basic Scripting Page (Graal Wiki)
obj.type() - gets the type of the var (float 0, string 1, object 2, array 3)
obj.length() - string length
obj.trim() - removes spaces from the front and back of a string
obj.lower() - converts a string to lower case
obj.upper() - converts a string to upper case
obj.tokenize([delimiters])
obj.charat(pos)
obj.pos(substring)
obj.starts(string)
obj.ends(string)
obj.substring(index[,length])
obj.size() - array length
obj.subarray(index[,length])
obj.addarray(obj2)
obj.insertarray(index,obj2)
obj.index(obj2) - position of obj2 in the array
obj.clear()
obj.add(obj2)
obj.delete(index)
obj.remove(obj2)
obj.replace(index,obj2)
obj.insert(index,obj2)
Can anyone help me out?
__________________



Reply With Quote
  #2  
Old 06-22-2006, 07:03 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by Omini
How do I do

NPC Code:
if (strcontains(,)) { }



in GS2? I checked the basic scripting page and it's not there...



Can anyone help me out?
PHP Code:
function containsstrStackstrNeedle )
  { 
// Usage: container( this.var, "foo" );
  
for ( 0strStack.length() - strNeedle.length(); ++ )
    if ( 
strStack.substringistrNeedle.length()) == strNeedle)
      return 
true;
  return 
false;
  } 
Reply With Quote
  #3  
Old 06-22-2006, 07:05 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by JustBreathe
PHP Code:
function containsstrStackstrNeedle )
  { 
// Usage: container( this.var, "foo" );
  
for ( 0strStack.length() - strNeedle.length(); ++ )
    if ( 
strStack.substringistrNeedle.length()) == strNeedle)
      return 
true;
  return 
false;
  } 
:X not needed dude.

if(foo.pos("bar") >= 0) {
}
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #4  
Old 06-22-2006, 07:06 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by ApothiX
:X not needed dude.

if(foo.pos("bar") >= 0) {
}
; True. I just took segments from my replaceAll( strStack, strNeedle, strReplace) function.
Reply With Quote
  #5  
Old 06-22-2006, 07:08 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by JustBreathe
; True. I just took segments from my replaceAll( strStack, strNeedle, strReplace) function.
ARGH! You are using contiga's style. >:[
Why the hell is he getting you guys to use it?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #6  
Old 06-22-2006, 07:10 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by ApothiX
ARGH! You are using contiga's style. >:[
Why the hell is he getting you guys to use it?
Err... I wrote that too quickly, I guess. I usually do ( str ). ( As you could see in the first function I supplied. I think you're over-reacting... )
Reply With Quote
  #7  
Old 06-22-2006, 07:13 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by JustBreathe
( As you could see in the first function I supplied. I think you're over-reacting... )
>> if ( strStack.substring( i, strNeedle.length()) == strNeedle)

Alright, it's good that you don't use that style. It's just super annoying to see people use it.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #8  
Old 06-22-2006, 08:11 PM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?
__________________



Reply With Quote
  #9  
Old 06-22-2006, 08:12 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by Omini
so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?
Try it and see!
Reply With Quote
  #10  
Old 06-22-2006, 08:48 PM
CheeToS2 CheeToS2 is offline
That Guy
CheeToS2's Avatar
Join Date: Dec 2001
Location: Seattle, WA
Posts: 2,528
CheeToS2 will become famous soon enough
Send a message via AIM to CheeToS2
It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}
__________________

Reply With Quote
  #11  
Old 06-22-2006, 08:52 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by CheeToS2
It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}
GraalScript: Function contains not found at line 6 in script of SandBox (in level onlinestartlocal.nw at pos (30.5, 30))
Reply With Quote
  #12  
Old 06-22-2006, 09:06 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Omini
so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?
Isn't that what I said? O_o
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #13  
Old 06-22-2006, 09:21 PM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
Quote:
Originally Posted by CheeToS2
It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}
Ah-ha! So that DOES work... I guess I used (this.msg.contains() text) or something stupid.

Quote:
Originally Posted by ApothiX
Isn't that what I said? O_o
Yeah sorta. You said if (foo.pos("bar") >= 0) { }, with the foo.pos sorta confusing me. I just wanted to clarify.
__________________



Reply With Quote
  #14  
Old 06-22-2006, 09:29 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Omini
Ah-ha! So that DOES work... I guess I used (this.msg.contains() text) or something stupid.
Quote:
Originally Posted by JustBreathe
GraalScript: Function contains not found at line 6 in script of SandBox (in level onlinestartlocal.nw at pos (30.5, 30))
Hmm?


Quote:
Originally Posted by Omini
Yeah sorta. You said if (foo.pos("bar") >= 0) { }, with the foo.pos sorta confusing me. I just wanted to clarify.
Ah, I see. Well yes, that is how you do it.


EDIT: Ogasp, post #1234. I r winnar.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #15  
Old 06-23-2006, 01:42 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
I use this method, I'm sure it works too.

PHP Code:
function onCreated()
{
  
temp.test = {"hey""test"};
  if (
contains(temp.test"test")) //If 'test' is in temp.test, it'll echo 'Found' to the NC users
  
{
    echo(
"Found");
  }
    else
  {
    echo(
"Not Found");
  }

__________________
Reply With Quote
  #16  
Old 06-23-2006, 02:20 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by xAndrewx
I use this method, I'm sure it works too.

PHP Code:
function onCreated()
{
  
temp.test = {"hey""test"};
  if (
contains(temp.test"test")) //If 'test' is in temp.test, it'll echo 'Found' to the NC users
  
{
    echo(
"Found");
  }
    else
  {
    echo(
"Not Found");
  }

Same thing as the in operator? if("test" in temp.test) {?
He is trying to compare substrings, not check if a value is in an array, I believe.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #17  
Old 06-23-2006, 09:19 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Oh I see, my mistake.
__________________
Reply With Quote
  #18  
Old 06-23-2006, 10:57 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Yes the replacement for strcontains(oldstring,oldstring) is contains(string,string)
Reply With Quote
  #19  
Old 06-24-2006, 07:41 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Stefan
Yes the replacement for strcontains(oldstring,oldstring) is contains(string,string)
It's not obj.contains(string) ?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
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 10:01 PM.


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