Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-07-2011, 06:02 AM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
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
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #2  
Old 09-07-2011, 06:13 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
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;
    }
  }

Reply With Quote
  #3  
Old 09-07-2011, 06:17 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
PHP Code:
function onPlayerChats(){
   
temp.txt player.chat.tokenize()[0];
   switch (
txt){
     case 
"test"// or case "("test")":
        // bla bla bla
     
break;
   }

Should work.
Reply With Quote
  #4  
Old 09-07-2011, 06:20 AM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
interesting, cool!
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #5  
Old 09-07-2011, 11:01 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by furry_mougle View Post
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.
Reply With Quote
  #6  
Old 09-07-2011, 05:52 PM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
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;

__________________
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:36 PM.


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