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
Hazram
Wanderer


Joined: 24 May 2005
Posts: 71

PostPosted: Fri Aug 26, 2011 8:01 pm   

Indirect Function syntax?
 
What's the syntax for calling an indirect function?

I tried:
#FU func1 {#PRINT success!}
#VAR myFunc = func1
@{@myFunc}()

but that doesn't work.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Fri Aug 26, 2011 8:22 pm   
 
Try putting something between the parenthesis when calling the function indirectly, like:
Code:
#show @{@myfunc}(a)
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Aug 26, 2011 9:01 pm   
 
You don't need to put anything for arguments. Not all functions require arguments.

However, to solve your problem, you'll need to do this:

Code:
#EXEC %concat("@",@myFunc,"()")


Yes, it's probably an awkward way of doing it, but it's the only way I can think of for now.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Fri Aug 26, 2011 9:07 pm   
 
Putting the argument in will work as well.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Hazram
Wanderer


Joined: 24 May 2005
Posts: 71

PostPosted: Fri Aug 26, 2011 9:27 pm   
 
Confirmed that using #exec and %concat works. Also found that relying on the bracket-evaluation syntax does not always work. Putting the indirect function call in an #alarm does not work with the bracket notation, but does work with #exec and %concat.

Because #EXEC @{@myfunc}(a) does not work, while #SHOW @{@myfunc}(a) does, I suspect the difference is tied to the difference between #show and #exec.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Sat Aug 27, 2011 1:10 am   
 
I guess it's possible the package I'm testing in is corrupted and is causing odd behavior on my end, since it's been a while since that has happened. Also I'm not sure how exactly you are using this in an alarm, but my simple tests below work fine without the slowdown everyone talks about experiencing when using #exec.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="test" copy="yes">
    <trigger name="test" type="Alarm" priority="9550" prompt="true" copy="yes">
      <pattern>10</pattern>
      <value>@{@myfunc}("")


</value>
    </trigger>
    <alias name="test" copy="yes">
      <value>$loc = %1
@func1(%1)
@{@myfunc}(%1)</value>
    </alias>
    <func name="func1" copy="yes">
      <value>#print success!</value>
      <arglist>$a</arglist>
    </func>
    <var name="myFunc" copy="yes">func1</var>
  </class>
</cmud>
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Aug 30, 2011 12:40 pm   
 
The slowdown from #EXEC comes from the need to compile the script during execution, instead of when you save it. This slowdown is small if the script can be compiled quickly (as yours can, Fizgar), but can become noticeable with complex scripts.

In addition, it is a bad idea to execute a function without a command in front of it. The general rule of thumb is that you should never start a command line with @ or %. While this may work some of the time, it is not guaranteed to work, and could stop working unexpectedly. The proper way to execute a function is to precede it by a proper Cmud command, such as #CALL, #EXEC, #SAY, or whatever is appropriate. In this case, you probably want #CALL.
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