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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Solaras
Wanderer


Joined: 11 Mar 2002
Posts: 93

PostPosted: Sat Nov 10, 2007 3:47 pm   

function/variable help please
 
in zmud I had a variable that would look like this:

Code:

Name:
can_heal
value:
%if( %ismember(asleep, @afflictions) or %ismember(unconscious, @afflictions) or %ismember(stunned, @afflictions) or %iskey( @flags, paused) or %ismember(astralform, @defenses), 0, 1)


I understand that you need to make that a function now, or maybe I misunderstand. As a variable I can't get it working and as a function I can't either.

using the same code in a function I tried

#if (@can_heal(1)) {blah}

but that seems to be wrong.

Anyone tell me how to use it properly?
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Nov 10, 2007 3:58 pm   
 
That is #varfunc now.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Nov 10, 2007 4:47 pm   
 
Or you can make it a proper function with the following.

Code:
#FUNC {can_heal} {#RETURN %if( %ismember(asleep, @afflictions) or %ismember(unconscious, @afflictions) or %ismember(stunned, @afflictions) or %iskey( @flags, paused) or %ismember(astralform, @defenses), 0, 1) }


The new #FUNCTION command in CMUD is very powerful. It is a proper function call and requires a value to returned via the #RETURN command.
_________________
Asati di tempari!
Reply with quote
Lina
Novice


Joined: 12 Oct 2006
Posts: 49

PostPosted: Sun Nov 11, 2007 3:39 pm   
 
@Tech: For that sort of function, like the example you gave, do you recommend using #func over #varfunc?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Nov 11, 2007 5:43 pm   
 
#functions are compiled, #varfuncs aren't. Try to convert your varfuncs to real functions - as Tech's demonstrated, it's as simple as adding #return at the start.

But functions can do all sorts of things that varfuncs can't, as well, because they can run commnads just like aliases and triggers can. The above example could be written like this:

#function {can_heal} {#if (%ismember(asleep, @afflictions) or %ismember(unconscious, @afflictions) or %ismember(stunned, @afflictions) or %iskey( @flags, paused) or %ismember(astralform, @defenses)) {#return 0} {#return 1}}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Mon Nov 12, 2007 12:53 am   
 
Fang Xianfu wrote:
#functions are compiled, #varfuncs aren't. Try to convert your varfuncs to real functions - as Tech's demonstrated, it's as simple as adding #return at the start.

Actually I have managed to get my #varfuncs to show compiled code - you have to play around with setting them to various variable types and check each time to see if they will compile. Hmm, although if they don't show the compiled code, they don't actually work at all... Seems like #varfuncs may be bugged, since none of mine worked until I changed them from Autotype and something else until they showed the compiled code. It seems to be the act of changing them and not what type that is important. Because they will compile on Autotype sometimes.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Nov 12, 2007 5:48 pm   
 
Seb is correct that #varfuncs *are* compiled when possible internally. The difference is that if the #varfunc can't be compiled, then it just returns whatever value is stored without trying to execute it.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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