Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Clientside Switch (https://forums.graalonline.com/forums/showthread.php?t=134257111)

Kyranki 11-29-2009 05:00 AM

Clientside Switch
 
PHP Code:

//#CLIENTSIDE
function onCreated() {
}
function 
onPlayerChats() {
  if (
player.chat.starts("/")) {
    
temp.toks player.chat.tokenize();
    
temp.com player.chat.substring(1temp.toks[0].length());
    echo(
temp.com);
    switch (@
temp.com) {
      case 
"global"
        
player.chat "TELL IT ALL!";
      break;
    }
  }
  else {
    
// Local Chat
  
}
}
function 
onTimeout() {
}
/* CONFIGURATION */
public function config() {
  
// Font
  
this.msgfont "Comic Sans MS";
  
// Message Time
  
this.msgtime 5;
}
/* CONFIGURATION */ 

Am I stupid or is switch() not working for a reason?

cbk1994 11-29-2009 05:04 AM

switch works fine

PHP Code:

temp.foo "bar";

switch (
foo) {
  case 
"test":
    echo(
"blah"); // you won't see this
  
break;
  
  case 
"bar":
    echo(
"hi"); // you will see this
  
break;



Kyranki 11-29-2009 05:11 AM

Erm, Chris then explain to me why it's not working at all here. o.o

PHP Code:

function onPlayerChats() {
  
temp.toks player.chat.tokenize();
  
temp.com player.chat.substring(1temp.toks[0].length());
  echo(
temp.toks);
  echo(
temp.com);
  switch (
temp.com) {
    case 
"global":
      echo(
"boo");
    break;
    
    default:
      echo(
"bark");
    break;
  }


Is resulting to the default.

DustyPorViva 11-29-2009 05:12 AM

Ditch the @ in the switch statement.

Kyranki 11-29-2009 05:14 AM

Quote:

Originally Posted by DustyPorViva (Post 1541052)
Ditch the @ in the switch statement.

Did that Dusty...that was just a result of me trying to figure out the problem.

Kyranki 11-29-2009 05:16 AM

Solved the problem.

PHP Code:

function onPlayerChats() {
  
temp.toks null;
  
temp.com null;
  
  
temp.toks player.chat.tokenize();
  
temp.com temp.toks[0].substring(1);

  switch (
temp.com) {
    case 
"global":
      echo(
"boo");
    break;
    
    default:
      echo(
"bark");
    break;
  }



Tigairius 11-29-2009 05:19 AM

Quote:

Originally Posted by Kyranki (Post 1541051)
Erm, Chris then explain to me why it's not working at all here. o.o

PHP Code:

function onPlayerChats() {
  
temp.toks player.chat.tokenize();
  
temp.com player.chat.substring(1temp.toks[0].length());
  echo(
temp.toks);
  echo(
temp.com);
  switch (
temp.com) {
    case 
"global":
      echo(
"boo");
    break;
    
    default:
      echo(
"bark");
    break;
  }


Is resulting to the default.

Why wouldn't you just do:
PHP Code:

  temp.com temp.toks[0].substring(1);
  switch (
temp.com) {
    case 
"global":
      echo(
"hi");
      break;
  } 

Edit: Ah, see you figured it out before I posted it. :)


All times are GMT +2. The time now is 03:16 PM.

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