Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-24-2011, 01:47 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Tokens?

How do I use tokens? I usually see these in a lot of scripts, I belive it expands the playerchat, like
Hi, how are you?

temp.token1 = Hi,
temp.token2 = how
So on...
Im not sure if this is the correct variable usage but, however I see this alot...
Please Help
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 02-24-2011, 01:52 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Syntax: string.tokenize([delimiter])

delimiter - (Optional) string to break the string into tokens by, if you don't specify a delimiter it will be break it apart based on a space.

Examples:

PHP Code:
function onCreated() {
  
// Tokenize string with no passed delimiter.
  
temp.str "Hello World!";
  
temp.tokens temp.str.tokenize();
  echo(
"tokens[0]" SPC temp.tokens[0]);
  echo(
"tokens[1]" SPC temp.tokens[1]);

  
// Tokenize string with # passed as the delimiter.
  
temp.str "Hello#World!";
  
temp.tokens temp.str.tokenize("#");
  echo(
"tokens[0]" SPC temp.tokens[0]);
  echo(
"tokens[1]" SPC temp.tokens[1]);

__________________
Quote:
Reply With Quote
  #3  
Old 02-24-2011, 02:11 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Quote:
Originally Posted by fowlplay4 View Post
Syntax: string.tokenize([delimiter])

delimiter - (Optional) string to break the string into tokens by, if you don't specify a delimiter it will be break it apart based on a space.

Examples:

PHP Code:
function onCreated() {
  
// Tokenize string with no passed delimiter.
  
temp.str "Hello World!";
  
temp.tokens temp.str.tokenize();
  echo(
"tokens[0]" SPC temp.tokens[0]);
  echo(
"tokens[1]" SPC temp.tokens[1]);

  
// Tokenize string with # passed as the delimiter.
  
temp.str "Hello#World!";
  
temp.tokens temp.str.tokenize("#");
  echo(
"tokens[0]" SPC temp.tokens[0]);
  echo(
"tokens[1]" SPC temp.tokens[1]);

So.....
PHP Code:
function onCreated()
{
   
// Tokenize string with # passed as the delimiter.
  
temp.str "Thanks#Alot#Fowlplay4!";
  
temp.tokens temp.str.tokenize("#");
  echo(
"tokens[0]" SPC temp.tokens[0]);
  echo(
"tokens[1]" SPC temp.tokens[1]);
  echo(
"tokens[2]" SPC temp.tokens[2]);

This would make the weapon echo to the RC "Thanks Alot Fowlplay4"?
How could I apply this to playerchat?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #4  
Old 02-24-2011, 04:40 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich
PHP Code:
function onPlayerChats() {
    if(
player.chat.starts("/color")) {
           
temp.tokens player.chat.tokenize();
           if(
tokens[1] == "red") {
               
//do something when player says "/color red"
           
} else if(tokens[1] == "blue") {
               
////do something when player says "/color blue"
           
}
    }

I haven't scripted in like a year so, I hope I got that right x]
Reply With Quote
  #5  
Old 02-24-2011, 06:09 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
This would make the weapon echo to the RC "Thanks Alot Fowlplay4"?
How could I apply this to playerchat?
Basically, Yes.

player.chat is a string so you can use player.chat.tokenize() just as well. See Seich's example.
__________________
Quote:
Reply With Quote
  #6  
Old 02-24-2011, 11:03 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Thanks, I now understand
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
Reply


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 02:50 PM.


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