ID:138831
 
Code:
mob
var
a = 0

verb
abc()
switch (input ("Select one option") in list ("a [a]","b","c")
if ("a [a]")
usr << "a"
if ("b")
usr << "b"
if ("c")
usr << "c"


Problem description:
As you can see, I put the "a" var in the "a" option of the input list, but, in the condition (if ("a [a]") it doesn't work.
It shows: "8:error: : expected a constant expression"
How can I put the "a" var in the condition?



Try var/AA = "a [a]" before switch(). If that still won't work then you cannot. Use if() else if() structure.
Like the error tells you, if you're using switch(), then they all have to be constant expressions.

Solution: Don't use switch()
In response to Immibis
Now it's like this:
mob
var
a = 0

verb
abc()
input ("Select one option") in list ("a [a]","b","c")
if ("a [a]")
usr << "a"
if ("b")
usr << "b"
if ("c")
usr << "c"

Errors:
7:error: list: undefined proc
8:error: : invalid expression
In response to DarkHitz
DarkHitz wrote:
Now it's like this:
> mob
> var
> a = 0
>
> verb
> abc()
> input ("Select one option") in list ("a [a]","b","c")
> if ("a [a]")
> usr << "a"
> if ("b")
> usr << "b"
> if ("c")
> usr << "c"
>

Errors:
7:error: list: undefined proc
8:error: : invalid expression

You need to specify a variable for input() to return the selected choice to, e.g:

var/value = input("Input a number")as num
usr << value
In response to Hashir
I just want to show the "a" var in the condition o_o
In response to Hashir
No you don't, his problems are with indentation, not the input() line.
In response to El Wookie
Actually Hashir is correct, when checking the value of an input() outside of switch() you need to set a variable to the value input() returns and check against that value. You can't just if(value) outside of switch() you need to if(variable == value).
In response to Nadrew
Technically I was not wrong, I was under the impression there was a switch() in there.

SADFACE
In response to Hashir
Hashir wrote:
DarkHitz wrote:
Now it's like this:
> > mob
> > var
> > a = 0
> >
> > verb
> > abc()
> > input ("Select one option") in list ("a [a]","b","c")
> > if ("a [a]")
> > usr << "a"
> > if ("b")
> > usr << "b"
> > if ("c")
> > usr << "c"
> >

Errors:
7:error: list: undefined proc
8:error: : invalid expression

You need to specify a variable for input() to return the selected choice to, e.g:

> var/value = input("Input a number")as num
> usr << value
>


You are not understanding...
I don't want to input the value, I want to show it in the option.
In the real code it is one room system, and it need to be like this: "Room 1 (4 players)", for example.
In this case, "a" var is the number of the players. I don't want to choose the number of the players. Just show it.
I made this "a" version because I thought it could make you understand better, but it don't G_G
I can't believe how long this has gone on for such a small question. A short read of the switch documentation shows the values :

"must be constants" << Grr

You cannot specify a variable to be checked in a switch statement.

Here is how you would approach it:

        var/L = list("a [a]","b","c")
var/R = input(usr,"Hello","Title",usr.name) in L

if(R == "a [a]")
usr << "You picked a [a]"
if(R == "b")
usr << "You picked b"
if(R == "c")
usr << "You picked c"


To be honest I think the switch statement has become surpassed by the input statement.
In response to DarkHitz
DarkHitz wrote:
Hashir wrote:
DarkHitz wrote:
Now it's like this:
> > > mob
> > > var
> > > a = 0
> > >
> > > verb
> > > abc()
> > > input ("Select one option") in list ("a [a]","b","c")
> > > if ("a [a]")
> > > usr << "a"
> > > if ("b")
> > > usr << "b"
> > > if ("c")
> > > usr << "c"
> > >

Errors:
7:error: list: undefined proc
8:error: : invalid expression

You need to specify a variable for input() to return the selected choice to, e.g:

> > var/value = input("Input a number")as num
> > usr << value
> >

You are not understanding...
I don't want to input the value, I want to show it in the option.
In the real code it is one room system, and it need to be like this: "Room 1 (4 players)", for example.
In this case, "a" var is the number of the players. I don't want to choose the number of the players. Just show it.
I made this "a" version because I thought it could make you understand better, but it don't G_G


It was just an example to show you how input() works.
In response to Despa1r
Despa1r wrote:
I can't believe how long this has gone on for such a small question. A short read of the switch documentation shows the values :

"must be constants" << Grr

You cannot specify a variable to be checked in a switch statement.

Here is how you would approach it:

>       var/L = list("a [a]","b","c")
> var/R = input(usr,"Hello","Title",usr.name) in L
>
> if(R == "a [a]")
> usr << "You picked a [a]"
> if(R == "b")
> usr << "You picked b"
> if(R == "c")
> usr << "You picked c"
>
>

To be honest I think the switch statement has become surpassed by the input statement.

It doesn't work.
In response to DarkHitz
I compiled it and tested it. I know it works. What is happening?
In response to DarkHitz
mob
var/a=0
verb/abc()
var/list/selection = list ("a [a]"="you selected a","b"="that\'s b","c"="c, the last option")
var/select=input ("Select one option") in selection
src << selection[select]


See list associations.