Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   nesting question (https://forums.graalonline.com/forums/showthread.php?t=87553)

screen_name 08-22-2009 01:24 PM

nesting question
 
Is it possible to nest multiple switch statements together?

xXziroXx 08-22-2009 01:27 PM

Quote:

Originally Posted by screen_name (Post 1517485)
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?

screen_name 08-22-2009 01:41 PM

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.

xXziroXx 08-22-2009 02:57 PM

Quote:

Originally Posted by screen_name (Post 1517488)
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.

Gambet 08-22-2009 06:03 PM

Yes, you can nest multiple switch() statements inside of each other.


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

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