Using the "real" function
#1
Posted 06 July 2012 - 05:02 PM
First of all, whenever I try to get it to actually simplify a string (e.g. 2*2), it gives me "error in function real()".
Here is the code I use (there is a good chance that this is a user error):
{
calc=get_string("","")
show_message(real(calc))
}
My second question is if there is any way to get the "real" function to be more accurate than two decimal places, I am trying to write a program where accuracy to many more decimal places would greatly increase its functionality.
If it makes any difference I am using the free version of GM8.
#2
Posted 06 July 2012 - 05:10 PM
Therefore, the string you want to parse must be a number in a string, not a calculation.
#3
Posted 06 July 2012 - 06:12 PM
Unfortunately, coming up with a way to enter calculations, like 2*2, will require further string-handling. I would divide the string using the functions included in the manual and go from there.
Edited by Johnjwj, 06 July 2012 - 06:15 PM.
#4
Posted 06 July 2012 - 08:19 PM
This is true if you try to put an integer into a string, but show_message() can display integers only - it can display anything, but it must be of the same type throughout.Also, show_message() can only display strings, meaning that you will have to convert any real values using string().
#5
Posted 06 July 2012 - 09:51 PM
My bad. The same data type through-out is important, yes.This is true if you try to put an integer into a string, but show_message() can display integers only - it can display anything, but it must be of the same type throughout.Also, show_message() can only display strings, meaning that you will have to convert any real values using string().
#6
Posted 06 July 2012 - 11:34 PM
#7
Posted 06 July 2012 - 11:43 PM
Security issues, function deprecated in Studio.execute_string
#8
Posted 07 July 2012 - 12:24 AM
As I said, it's usually a bad idea. Even if it had no security issues at all, it's a slow function as well as very difficult to debug (if you use it a lot) and in general it's bad programming practice since people use it out of laziness to do something like this instead of writing an actual script to parse the string.Security issues, function deprecated in Studio.execute_string
Still, if he just wants a quick and easy way then he could use it. It does work, as long as he's not using Studio (in which case it won't work, but he specifically said he's not using Studio)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











