Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
talonnb
Apprentice


Joined: 30 Oct 2004
Posts: 127

PostPosted: Tue Oct 05, 2010 3:14 am   

Real Quick Function Question #RETURN based
 
I've been browsing the forums like a madman looking for an example where a function returns a value and how that value is accessed.

Say I want to do:

#call @HandleAffliction(Tekura, ArmBreak)

and in that function it does #Return to return a specific value from said function back to a multistate trigger that I want to use said value to control the multistate. Now, I have no idea how to reference this, and I couldn't find any reference, so this is as close as I can think it might work

Trigger {Some bugger slaps you silly} //obviously not a real trigger, just an example
Value {
#call @HandleAfflict(Bugger, Slap)
#if ($returnedvalue=1) {#state 1} //reset the state to capture the next line as this one is ignored
#if ($returnedvalue=2) {#var affliction whatever;#State 0} //got the right 'next' line I wanted, resetting state to 0
}

problem is, I don't know how to get the value passed back from HandleAfflict into the $returnedvalue variable. I just hate to have a bunch of 'confirm' global variables kicking around if this return thing allows me to save the value to the local temp variable instead.
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Tue Oct 05, 2010 4:59 am   
 
You don't have to use #call to execute a function.

Code:
$val = @HandleAfflict(Bugger, Slap)
#if ($val == 1) {#state 1} //reset the state to capture the next line as this one is ignored
#if ($val ==2) {#var affliction whatever;#State 0} //got the right 'next' line I wanted, resetting state to 0
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Oct 05, 2010 12:53 pm   
 
Right. You would use #CALL if the function did not return a value, or if you did not need the return value. If you need the return value, you can use the function in a variable assignment, or directly within another statement. For instance, you could use the the function as part of the argument for a Cmud command, or as a value within another function. In general, you can use a function call (built-in function or user-defined) anywhere you can use a variable (though it's a bit tricky to use one in a trigger pattern).
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net