ID:1305802
 
(See the best response by Kaiochao.)
Code:
mob/verb/Test()
for(var/mob/M in players)
M = pick(players)
switch(input(M,"") in list ("",""))


Problem description: So I've created a piece of code simliar to the one above. Since I have no other players to test with I was wondering would this work in sending the switch to M to accept or decline?

Best response
Do you realize that the input() proc exists independently of switch()? The input() proc is a proc that asks a player for input. The switch() instruction is a tool commonly used to handle the return value of procs like input() and alert(). This isn't the first time I've seen this misconception.

Secondly, you're also misusing for().

Anyway, back on topic. As the DM Reference says, the first argument of input() (if it isn't text) is the target of the popup.
You can also test multiplayer on your own machine by running another instance of the pager (or if you are logged in, logout of the pager). Next, host the game, remember the port number. Finally, go to the pager and hit Ctrl + O and type "localhost:port_number_here" and hit the Enter key.

Make sure you're not logged into your key when you host the game or that you're logged out when you go to open the pager, otherwise the server will kick you and your host will die (one key can't be in the same game more than once.)
In response to Kaiochao
Kaiochao wrote:
Do you realize that the input() proc exists independently of switch()? The input() proc is a proc that asks a player for input. The switch() instruction is a tool commonly used to handle the return value of procs like input() and alert(). This isn't the first time I've seen this misconception.

Secondly, you're also misusing for().

Anyway, back on topic. As the DM Reference says, the first argument of input() (if it isn't text) is the target of the popup.

In this instance I would be challenging another player so would I not be looking for a return value with switch()?

Also I'm not sure how I'm misusing for(). players is a list which i want the verb to pick a random player from the list to challenge them. Could it be done by picking from world? Would their be a better way to go about this?
In response to Rickoshay
//  This initiates a loop through all mobs in 'players'
// each mob referred to using M as an identifier
for(var/mob/M in players)
src << M
// the above is an example of a "Who verb"

// This makes a variable called M and sets it to
// the return value of pick()
// for() is not necessary for this.
var mob/M = pick(players)


switch() doesn't ask for a value or return a value. It's not a proc.

input() is a proc. It returns a value according to what the player chooses.

switch() is a statement that takes an expression has its own syntax to handle the given expression. It has nothing to do with asking a player anything.
var some_number = 5
switch(some_number)
if(4) world << "Four!"
if(5) world << "Five!" // this is what is displayed
if(6) world << "Six!"


The problem here isn't that you're using switch() to handle input()'s return value. It's that you're calling it "sending a switch() to a player," as if the switch() is what asks the player for input.
Ahh right now I'm more on track.

So something more along the lines of?

mob/verb/Test()
var/mob/M = pick(players)
input(M,"") in list ("Yes","No")
if("Yes")
//do stuff
if("No")
//do stuff
In response to Rickoshay
That didn't work for me (testing)
But this one worked for me.
mob/verb/Test()
var/mob/M = pick(players)
var/e=input(M,"") in list ("Yes","No")
if(e == "Yes")
//do stuff
if(e == "No")
//do stuff
Make sure to handle if(!e) which will occur if the player disconnects while making a decision
Rickoshay, did you even read Kaiochao's explanation? It literally explained exactly what you need to do.
His second code snippet is exactly what you need. Here's a hint: Put the switch back in.

Don't even look at Undefeated Saiyan's example, it shows some very unnecessary things.
In response to Super Saiyan X
Super Saiyan X wrote:
Rickoshay, did you even read Kaiochao's explanation? It literally explained exactly what you need to do.
His second code snippet is exactly what you need. Here's a hint: Put the switch back in.

Don't even look at Undefeated Saiyan's example, it shows some very unnecessary things.

Okay, yes I did read and I asked "would I not be looking for a return value with switch()?", What I really should have said is using switch(). I've just misread what he's trying to tell me after that. Assuming he was telling me that switch wasn't necessary. Guess I should proof read more.