ID:260369
 
Something similar to python's eval() proc would be great.

You could pass math functions and stuff into it and it'd return the final value, such as:
eval("5**2/2+12.5") //would return 25

This would be quite useful in creating a dynamic damage system or just making a calculator-esque application.
I'm sorry, I don't really get it. Why would you need a separate proc for math?
Isn't that what SET is for?
In response to Foomer (#2)
Oh, sweet!

I didn't notice that on the hub, thanks Foomer.
In response to Zagreus (#1)
Zagreus wrote:
I'm sorry, I don't really get it. Why would you need a separate proc for math?

eval()-type procs allow you to specify mathematical formulae as string variables associated with objects, reducing or eliminating the need to recompile every time you want to change a formula belonging to a specific object.
That's actually a really great idea. I like it, anyway. It allows for a much faster scripting language. After all, all you'd have to do is replace procedures and variables, and send them to eval(). It'd be like BAM!
In response to Jtgibson (#4)
Yeah, eval proc is really one of the built-in procs. However, I'm not absolutely sure if it still works yet, since I don't have 4.0. :P

Edit: Typo
In response to Bandock (#6)
eval() has been a recognized function for as long as BYOND has existed. It's never worked, and I don't see it working anytime soon.
In response to Nadrew (#7)
Nadrew wrote:
eval() has been a recognized function for as long as BYOND has existed. It's never worked, and I don't see it working anytime soon.

Au contraire. It's not that it doesn't work; it's incomplete and undocumented because there's currently little if any use. I'm sure Dan had great plans for it. However, what's there does work, more or less. Observe:

mob/verb/test()
var/result = eval({"var/num1 = 25
var/num2 = 37
// The minus operator is a little broken, but there's a workaround.
return "num1: \[num1]\\nnum2: \[num2]\\nsum: \[num2+num1]\\ndiff: \[num2+-num1]""}
)
src << "Result:\n[result]"


It uses DM Script which is very limited in comparison to DM. In addition to arithmetic and string operations as shown above, it's also supposed to support object variables and if statements. I couldn't get the usual DM if() syntax to work in my tests, and Dan's parsing code is written in ancient hieroglyphic (aka indecipherable). Also, floating point numbers are supposed to work but didn't for me.

Because it's not full DM, there's no real way for the evaluated script to operate in the context of the DM proc with access to its variables.
In response to Mike H (#8)
Ah, well I'll be damned it does work. That's not exactly viable to do anything major. Do embedded ?: conditionals work? I don't really have a way to test at the moment.