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
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Nov 16, 2008 10:56 pm   

Can't remember what I did to make this work before...
 
I had an alias called 'calc' that would perform calculations without all the extra typing. I could type or paste an expression, and it would calculate it properly. I had it in lua because that is a better engine to calculate things with, considering it'll do floating points without the need for %float... Here is what I have now.

print(zs.params())

The problem with that is it prints it as the string, so calc 3*3 returns 3*3, not 9.

Then I tried

#LUA {print(%params)}

It evaluates simple things, such as 3*3, but throw in something like (3*3)/(3*6), then it just returns 0, whereas print((3*3)/(3*6)) will return the proper 0.5 result.

I know I used to be able to do things like that with no problems, so I'm not sure why it's not working now. I had lost my scripts when my computer crashed, so that was no fun. But any help would be greatly appreciated.

Charneus
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Nov 17, 2008 2:24 am   
 
The trouble you're having is that %params and zs.params return a string, which print() then prints without parsing. To get it to parse, you'd have to do something pretty weird, probably something like assert(loadstring("print("..zs.params()..")"))(). Pretty convoluted, I know.

Tbh, though, if all you want to do is maths on the command line, put the command line in Lua mode and write the print(3*3) yourself, it'll probably be less hassle.
_________________
Rorso's syntax colouriser.

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


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Nov 17, 2008 3:48 am   
 
Heh. Not sure how I got it to work previously without that convolution you speak about.

The reason I don't want to put the command in lua mode and just type it out myself is because it'd be more of a hassle when I have to switch back and forth, and also when I'm running scripts, I can't rightly do that. I'll try your suggestion, though... Thanks. :)

Edit: The suggestion did not work... :\

Charneus
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Nov 17, 2008 2:14 pm   
 
All I did to get it to work was open CMUD, press Esc, press Ctrl+' and then enter print(3*3) on the command line. That put 9 on the screen.

And if you weren't using the keyboard shortcut already (it might be Ctrl+` on your keyboard), you should. It's a lot less hassle.

EDIT: Oh, you meant the other thing. Checking that now.

EDIT2: Working fine for me:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="test" copy="yes">
    <value>assert(loadstring("print("..zs.params()..")"))()</value>
  </alias>
</cmud>
_________________
Rorso's syntax colouriser.

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


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Nov 17, 2008 2:27 pm   
 
Had to change it to lua in order to get yours to work at all. Didn't copy the lua part, apparently.

Regardless, yes, it works for simple things like 3*3, but throw in (3*3)/(3*6), that returns (incorrectly) 0. I remember that what I had prior was MUCH simpler than what you've provided, simply because I don't know lua all that well yet and wouldn't have even come up with your suggestion. :\

Charneus
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