Author Topic: Using a switch to create a selectable list  (Read 564 times)

No code at the moment, im just trying to figure how this would work, plus the fact that it takes some while to get a response.

Im making something like a pestle & mortar

you type /p&m help   and you get a list similar to
1. Health Potion - (names of ingredients)
2. Poison - (ingredients)
3. Ect.....


Then after choosing one with /create 1    or /create 2  it would call a switch that would figure out what ingredients to look for, then create it if you have what you need.



Is there an easier way to do this?
or do i have the right idea?

(p.s. Im a Massive Newbie)


-----------------------------------

This is what i have at the moment :p

Code: [Select]
//p&m.cs

function servercmdpotion(%client,%choice)
{
echo("p&m");
  switch(%choice)
    {
      case 1:
        //potion 1 stuff
        echo("Potion1");
        if(%client.redberry > 0 && %client.blueberry > 0)
          {
          echo("blu and red");
          }
         else
          {
          echo("Else");
          }
       case 2:
        //potion 2 stuff
        echo("Potion2");
       default:
         messageClient(%client,'','1. Health Potion - Red Berry(1), Glow Berry (1)');
    }
 
}

function servercmdpick(%client)
{
%client.redberry = 100;
%client.blueberry = 100;
}



That all worked

Ill tell all you people how it goes
« Last Edit: July 26, 2010, 12:11:39 PM by Obibital »

You don't do callFunction(potioncheck);
Just potioncheck();


If I were doing this, I would use a single command for making and help, as it would be less commands to remember
Code: [Select]
function serverCmdPotion(%client,%choice)
{
    switch(%choice)
    {
        case 1:
            //potion 1 stuff here
        case 2:
            //potion 2 stuff here
        //add more cases for more potions
        default:
            //help messages here
    }
}
« Last Edit: July 26, 2010, 11:41:14 AM by Headcrab Zombie »

So what your saying is, that the /potion command will be used aswell instead of making a /make#


By Potion Stuff do you mean the Checks for the ingrediants or....errrr

What would i be using to set the value of the %choice?

So what your saying is, that the /potion command will be used aswell instead of making a /make#


By Potion Stuff do you mean the Checks for the ingrediants or....errrr

What would i be using to set the value of the %choice?


%choice is whatever has been said after /potion

/potion mayonnaise

mayonnaise would then be %choice

%choice is whatever has been said after /potion

/potion mayonnaise

mayonnaise would then be %choice

Wow, this just became a whole lot easier

o3o derp


Edit:

Ok then, ive got the switch working fine, and now all i have to set up is the checks for the ingredients.
im planning on using if(%client.ingredient1 > 0 Ect......

Is that a bad idea?
« Last Edit: July 26, 2010, 11:57:26 AM by Obibital »

by the way it's currently looking for a "1" or a "2" after /potion

change the "1" in "case 1" to whatever you want if you want to make it "health" or whatever

"case health" would make it look for "/potion health"



Ok then, ive got the switch working fine, and now all i have to set up is the checks for the ingredients.
im planning on using if(%client.ingredient1 > 0 Ect......

Is that a bad idea?

I don't know if there's a more efficient way to do this, but that sounds fine

if there is a more efficient way, someone will tell you
« Last Edit: July 26, 2010, 12:00:04 PM by SpreadsPlague »

by the way it's currently looking for a "1" or a "2" after /potion

change the "1" in "case 1" to whatever you want if you want to make it "health" or whatever

"case health" would make it look for "/potion health"

Really? because of the appendix i was under the impression that switches could only read numerical values

well you could always try it and see if it works, I'm a little bit rusty at the whole server-sided coding thing, but it looks like it should work.

I recall an add-on that did this with nodes, and it used the "case" thing so I'll go dig that up and tell you what I find ..

I had to dig up FFC. ew.

anyways here's a snippet from FFC using a switch to handle text input

Code: [Select]
switch$(%Color)
{
case "":%Player.mountimage(DogImage,1);
case "red":%Player.mountimage(DogRedImage,1);
case "blue":%Player.mountimage(DogBlueImage,1);
case "pink":%Player.mountimage(DogPinkImage,1);
case "green":%Player.mountimage(DogGreenImage,1);
case "black":%Player.mountimage(DogBlackImage,1);
case "white":%Player.mountimage(DogWhiteImage,1);
case "yellow":%Player.mountimage(DogYellowImage,1);
case "orange":%Player.mountimage(DogOrangeImage,1);
case "purple":%Player.mountimage(DogPurpleImage,1);
}

so yes you can use case with non-numerical values
« Last Edit: July 26, 2010, 12:10:45 PM by SpreadsPlague »

Well, the named case does work, but it tells me in the console that that string always evaluates to 0

Still it worked :p