Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   player.chat.starts with switch() (https://forums.graalonline.com/forums/showthread.php?t=134264496)

furry_mougle 09-07-2011 06:02 AM

player.chat.starts with switch()
 
I know you can do something like,

PHP Code:

function onPlayerChats(){
  if(
player.chat.starts("test"){
     
// bla bla bla
  
}


but why can't you do something like this?

PHP Code:

function onPlayerChats(){
   switch (
player.chat.starts){
     case 
"test"// or case "("test")": ?
        // bla bla bla
     
break;
   }


might be a really simple solution, but idk it's been bugging me for a while

Mark Sir Link 09-07-2011 06:13 AM

try something like
PHP Code:

function onCreated(){
  
this.prefix "what chat should start with";

function 
onPlayerChats(){
  if(
player.chat.starts(this.prefix)){
    switch(
player.chat.substring(this.prefix.length())){
      case 
"test": break;
      case default : break;
    }
  }



DustyPorViva 09-07-2011 06:17 AM

PHP Code:

function onPlayerChats(){
   
temp.txt player.chat.tokenize()[0];
   switch (
txt){
     case 
"test"// or case "("test")":
        // bla bla bla
     
break;
   }


Should work.

furry_mougle 09-07-2011 06:20 AM

interesting, cool!

Crow 09-07-2011 11:01 AM

Quote:

Originally Posted by furry_mougle (Post 1667291)
why

Because string.starts(substring) is a function that returns either true or false, depending on whether the string begins with substring or not; making it useless in a switch statement.

0PiX0 09-07-2011 05:52 PM

Usually I check a substring from position 0 to the position the first space is at
PHP Code:

switch (player.chat.substring(0player.chat.pos(" "))) {
  case  
"herp":  derp();  break;
  case  
"tick":  tock();  break;




All times are GMT +2. The time now is 12:09 AM.

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