ID:2811451
 
(See the best response by Kozuma3.)
Code:
mob
var
A = 1
B = 2
verb
SwitchTest()
switch(TestProc())
if(0)
world<<"Zero"
else
world<<"The result is... [?]"
//How do I make this pass the result of TestProc without calling TestProc again?
proc
TestProc()
return A + B


Problem description:
Basically as above - If a switch is taking the return from a procedure, how can I pass that evaluated expression on to the "if" statements?

(My workaround is just to set var/Temp = TestProc(), then evaluate Temp in the switch)
Best response
mob
var
A = 1
B = 2
verb
SwitchTest()
var i = TestProc(A,B)
switch(i)
if(0)
world << "Zero"
else
world << "The result is [i]"
proc/TestProc(A,B)
return A+B


or you could do

var i
switch((i = TestProc(A,B)))
You shouldn't need a temporary var. The switch() statement basically pushes the result of the proc onto the stack and uses that to compare to its if/else cases.
In response to Lummox JR
Lummox JR wrote:
You shouldn't need a temporary var. The switch() statement basically pushes the result of the proc onto the stack and uses that to compare to its if/else cases.

Think the issue he's having is world << "Result is [?]" where ? would be the value of the proc
In response to Kozuma3
Alrighty, that's what I had ended up doing anyways. Good to know I can embed the statement in the switch at least. Thanks!
In response to Kozuma3
Kozuma3 wrote:
Lummox JR wrote:
You shouldn't need a temporary var. The switch() statement basically pushes the result of the proc onto the stack and uses that to compare to its if/else cases.

Think the issue he's having is world << "Result is [?]" where ? would be the value of the proc

Yep, exactly that - maybe I should have worded it better. Temp vars it is.