Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-22-2009, 01:24 PM
screen_name screen_name is offline
is watching you
Join Date: Mar 2002
Location: The 3rd Dimension
Posts: 2,160
screen_name is on a distinguished road
Send a message via AIM to screen_name Send a message via MSN to screen_name
nesting question

Is it possible to nest multiple switch statements together?
__________________
[signature]insert here[/signature]
Reply With Quote
  #2  
Old 08-22-2009, 01:27 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by screen_name View Post
Is it possible to nest multiple switch statements together?
Do you mean like this?

PHP Code:
switch (foo) {
  case 
"bar":
    switch (
foo2) {
      case 
"bar2":
        break;
      case 
"baz2":
        break;
    }
    break;
  case 
"baz":
    break;

Possible? Probably. But why would you want to complicate it like that?
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 08-22-2009, 01:41 PM
screen_name screen_name is offline
is watching you
Join Date: Mar 2002
Location: The 3rd Dimension
Posts: 2,160
screen_name is on a distinguished road
Send a message via AIM to screen_name Send a message via MSN to screen_name
Exactly what I meant. I was thinking that you could do something like this;

PHP Code:
function onPlayerChats() {
   
temp.pc player.chat.tokenize();
   switch (
pc[0]) {
     case 
"+":
       switch (
pc[1]) {
         case 
"gold":
         break;
         case 
"item":
         break;
         case 
"health":
         break;
         default:
           
player.chat "Invalid parameter";
         break;
      }
     break;
     case 
"?":
     break;
     default:
     break;
  }

Something of the sort. I realize after typing that though, if I wanted the ? command to display help, then there would be a lot of extra typing.
__________________
[signature]insert here[/signature]
Reply With Quote
  #4  
Old 08-22-2009, 02:57 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by screen_name View Post
Exactly what I meant. I was thinking that you could do something like this;

PHP Code:
function onPlayerChats() {
   
temp.pc player.chat.tokenize();
   switch (
pc[0]) {
     case 
"+":
       switch (
pc[1]) {
         case 
"gold":
         break;
         case 
"item":
         break;
         case 
"health":
         break;
         default:
           
player.chat "Invalid parameter";
         break;
      }
     break;
     case 
"?":
     break;
     default:
     break;
  }

Something of the sort. I realize after typing that though, if I wanted the ? command to display help, then there would be a lot of extra typing.
You're probably better off nesting if/else if-statements in this case.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #5  
Old 08-22-2009, 06:03 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Yes, you can nest multiple switch() statements inside of each other.
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 11:58 AM.


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