Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Tokens? (https://forums.graalonline.com/forums/showthread.php?t=134262215)

Astram 02-24-2011 01:47 AM

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 >_<

fowlplay4 02-24-2011 01:52 AM

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]);



Astram 02-24-2011 02:11 AM

Quote:

Originally Posted by fowlplay4 (Post 1632991)
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?

Seich 02-24-2011 04:40 AM

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]

fowlplay4 02-24-2011 06:09 AM

Quote:

Originally Posted by Astram (Post 1632996)
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.

Astram 02-24-2011 11:03 PM

Thanks, I now understand


All times are GMT +2. The time now is 08:23 AM.

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