ID:140594
 
Code:
proc
Rand_Dir()
var/r = rand(1,8)
r==1 ? return NORTH : r==2 ? return EAST : r==3 ? return SOUTH : r==4 ? return WEST : r==5 ? return NORTHWEST : r==6 ? return NORTHEAST : r==7 ? return SOUTHEAST : return SOUTHWEST


Problem description:
loading RPG - Unnamed.dme
loading Interface.dmf
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:error: : missing expression
Code\Procs and Verbs.dm:4:warning: ?: statement has no effect
Code\Procs and Verbs.dm:58:warning: dir: variable defined but not used


Here you go.
Meet the pick proc...
http://www.byond.com/docs/ref/info.html#/proc/pick
proc
Rand_Dir()
return pick(NORTH,EAST,SOUTH,WEST,NORTHWEST,NORTHEAST,SOUTHEAST,SOUTHWEST)
Three answers.

1) What Chowder said is the way to go.

2) Specifically concerning the attempt you made, the ?: operators don't work that way. It's more like
proc/randomlyReturns1or2()
return rand(0,1) ? 1 : 2

Obviously there's a bunch of ways to do that better than what I just did in that code, but that was just an example of the operators.

It cannot work with more than 2 options though. It's "condition ? value1 : value2" where condition is either true or false, and value1 is returned if true, value2 if false. So you get only 2 options.

3) Another way you could do this if you wanted only the 4 main directions, although not a very readable way, would be
proc/Rand_Dir()
return 1<<rand(0,3)

Just felt like throwing that in there for the fun of it.
In response to Loduwijk
Loduwijk wrote:
It cannot work with more than 2 options though. It's "condition ? value1 : value2" where condition is either true or false, and value1 is returned if true, value2 if false. So you get only 2 options.

You can nest the statements:

proc/dumb_num_to_text(var/N)
return N>5?N>8?N>9?"ten":"nine":N>6?N>7?"eight":"seven":"six":N>3?N>4?"five":"four":N>2?"three":N>1?"two":"one"