|
Solaras Wanderer
Joined: 11 Mar 2002 Posts: 93
|
Posted: 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? |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sat Nov 10, 2007 3:58 pm |
That is #varfunc now.
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: 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! |
|
|
|
Lina Novice
Joined: 12 Oct 2006 Posts: 49
|
Posted: 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?
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: 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}} |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: 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. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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.
|
|
|
|
|
|