ID:141011
 
Code:
mob/proc
playerturn(mob/player/P)
var/list/commands = list("Attacks","Skills","Magics","Run")
var/commandchoice = input(usr,"What do you wish to do?","Commands") in commands
switch(commandchoice)
if("Attacks")
var/list/atkcommands = usr.ATKlist
var/atkchoice = input(usr,"Which attack do you wish to do?","Attacks") in atkcommands
var/E = input(usr,"On which enemy?","Target") in targetlistt
switch(atkchoice)
if("Weak Attack")
WeakAttack(P,E)
if("Normal Attack")
NormalAttack(P,E)
if("Fierce Attack")
FierceAttack(P,E)


Problem description:
How do I make the code so that when I have just 1 type of attack in ATKlist, it doesn't automatically pick that one. For example, I want to be able to see "Weak Attack" on the selection menu even if that is the only one in the list without the program assuming that I want that.
After the input(), try "as null|anything in". It adds a Cancel button. It means you can choose anything in the list, OR(the | symbol) null, meaning cancel.
In response to Kaiochao
thanks! i got it now
In response to Kaiochao
Another question. Also how do I make so that when I click cancel, it goes back to the previous selection? I'm guessing it has something to do with goto proc? Not sure.
In response to Sandlight
Add an else to the end of your switch conditions that will restart the player's turn. The else is what is ran if none of the other conditions are met.

switch(atkchoice)
if("Weak Attack")
blah
if("Normal Attack")
blah
if("Strong Attack")
blah
else //No other conditions met.
playerturn(P)//Start the player's turn over again

Depending on how the rest of your playerturn proc is, you may wabt to add a return in there to end it prematurely or whatever. Or instead of just starting the proc over, use some kinda loop.

In response to Zagreus
Recursively calling the proc is a bad idea here. A proper do-while() loop is much better. It can be a bit tricky to understand how to nest them properly, so here's an example:

//choose a character, an attack, and a target
var/character
var/attack
var/target
do
choose a character
do
choose an attack (or null)
if(attack)
choose a target (or null)
while(attack && !target)
while(!target)
//perform the attack:
character.attack(target)


And to show you how they would nest further:

//choose a character, an attack, its power, and a target
var/character
var/attack
var/power
var/target
do
choose character
do
choose attack (or null)
if(attack)
do
choose power (or null)
if(power)
choose target (or null)
while(power && !target)
while(attack && !target)
while(!target)

character.attack(power, target)


You might have to explicitly work out how the flow in that actually goes, but there is a pattern to it. Each loop breaks when either we finish the whole selection tree (target is chosen) or we cancel that portion's selection (attack or power are not chosen). Because we MUST take an action, the outermost loop can only break on success (note: include a default choice for all of the decisions, or else if a player disconnects it gets stuck in a nasty infinite loop). On any decision we can cancel out of, we need to use an if() statement to ensure we can ask the next question.

Note that it would really be cleaned up if you have each selection sent to its own proc, especially if - for example - you needed a different selection process for different attacks.

Also: BYOND's restrictions on where you can do assignments is annoying, and made me take way too long to figure this out. Honestly, I'd much rather do this:

while(!target)
character = getcharacter()
while(!target && (attack = getattack()))
while(!target && (power = getpower()))
target = gettarget()