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
FishyBug
Newbie


Joined: 10 Jan 2008
Posts: 3

PostPosted: Thu Jan 10, 2008 2:50 pm   

cMud and exponents.
 
Hi,

I am trying to get exponents to work in cMud.

I cannot get #SHOW {x^y} to work and can't find a function for it. Am I missing something?

Thanks
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Jan 10, 2008 5:43 pm   
 
I dont think there's a built in way in CMUD.
I wrote a quick function to take advantage of the lua library to get it done.
Code:
<func name="math" language="Lua" id="32">
  <value>if zs.numparam == 0 then return nil end
local func = zs.param(1)
if type(math[func]) ~= "function" then return nil end
local arg = {}
for i=2,zs.numparam do
  table.insert(arg,tonumber(zs.param(i)))
end
return math[func](unpack(arg))
</value>
</func>

It's just a wrapper to the Lua math library.
A description of the functions available can be found here

To use it you would do something like.
#echo @math("pow",2,4)
It would then echo 16
I had it return 'nil' if you messed up but you could just as easily change that to return an empty string or to raise an exception
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu Jan 10, 2008 6:10 pm   
 
Impressive!
_________________
Taz :)
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