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
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Mon Jun 11, 2007 2:54 am   

Using %eval inside a Data Record Variable
 
Ok, basically what im trying to do is create a Settings Data Record to keep track of everything thats going to need constant updating, such as the %eval for my Auto-Sipper, that way I can easily change from sipping at say 7/8's to 1/2 when occasion called for. In zmud, I used this script

Code:
@settings.healthsip = %eval(@settings.maxhealth*7/8)
#if (@Health < @settings.healthsip) {rest of script here}


That worked great, the %eval inside the data record automatically expanded and tested in the system. The problem is when I try to do the same for Cmud, It shows it as this instead of expanding out to the actual number:

Code:
"%eval(@settings.maxhealth*7/8)"


Any help would be greatly appreciated
-- Tester

================================================================================================================
Edit: Added Code tags
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Jun 11, 2007 3:10 am   
 
You only need an @ before the variable name when you're calling the value of it, not when you're assigning it.

settings.healthsip = %eval(@settings.maxhealth*7/8)
#if (@Health < @settings.healthsip) {rest of script here}

Also, very often in CMUD, you don't actually need the %eval function, you can just surround the expression with brackets. This is one of those times.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Mon Jun 11, 2007 3:25 am   
 
Well, My problem isnt actually with setting the variable, I want the variable its self to equal the %eval, or just the expression
Code:
@settings.maxhealth*7/8

and then actually execute when used in a script.......I tried using your above example, but it just set the variable at a fixed point, which works, but really isnt what I was looking for.Before All I had to do was go into my settings data record and change the fraction at the end of the eval around and it would adjust when I sipped, thats what kinda Im looking for now..........

Really I could probably get away with something like this........

Code:

#alias Healthsip {settings.healthsip = %eval(@settings.maxhealth*%1}


To set it at a fixed point, but I was hoping to keep it the same Way as before :(

==================================================================================================================
EDIT:

Actually I think I just found a way to do this....If instead of

Code:
 Settings.healthsip = %eval(@settings.maxhealth*7/8)
#if (@settings.healthsip) {script}


I can use:

Code:
 settings.healthsip = @settings.maxhealth*7/8
#if (%eval(@settings.maxhealth) {script}


And it works the way I wanted it to.......Thanks for the help Very Happy
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