+USCcouple Posted April 9, 2008 Share Posted April 9, 2008 Hi, I am trying to perform some basic math operations on some variables. Say I have three variables (Number1, Number2, and Answer). I would like to add Number1 to Number2 and store that in Answer. I would think that I could write: Answer = Number1 + Number2 But the compiler turns that into: Answer = Answer + Number2 So it seems that I have to write: Answer = Answer + Number1 Answer = Answer + Number2 is that correct? is there not a more condensed way of doing the addition? I also need to do division and multiplication. I looked through the lua documentation but could not get any of it to work with the compiler. Is there any documentation on what math can be done? Thanks, Kevan Quote Link to comment
Tydirium Posted April 9, 2008 Share Posted April 9, 2008 (edited) I believe the builder does not support adding variables. Instead you could try writng a function to handle your math such as: -- This goes in the main section Answer = addNumbers(Number1, Number2) -- This goes in the Author functions section function addNumbers(num1, num2) return num1 + num2 end Of course the issue with this is that the builder will more than likely do this: Answer = "addNumbers(Number1, Number2)" Notice the quotes. You'd have to manage that seperately. Edited April 9, 2008 by Tydirium Quote Link to comment
Tydirium Posted April 9, 2008 Share Posted April 9, 2008 Also, don't forget to: require "math" in the Author Directives section. This gives you access to the math library. Quote Link to comment
+USCcouple Posted April 9, 2008 Author Share Posted April 9, 2008 Also, don't forget to: require "math" in the Author Directives section. This gives you access to the math library. What would be the proper syntax for multiplication and division? Thanks, Kevan Quote Link to comment
Tydirium Posted April 9, 2008 Share Posted April 9, 2008 Standard math operators are used: num1*num2 (multiplication) num1/num2 (division) Quote Link to comment
Tydirium Posted April 9, 2008 Share Posted April 9, 2008 (edited) Also, don't forget to: require "math" in the Author Directives section. This gives you access to the math library. Actually you shouldn't need the require "math" statement for simple math operators. You do need it to call any math.* functions though Edited April 9, 2008 by Tydirium Quote Link to comment
+USCcouple Posted April 9, 2008 Author Share Posted April 9, 2008 Also, don't forget to: require "math" in the Author Directives section. This gives you access to the math library. Actually you shouldn't need the require "math" statement for simple math operators. You do need it to call any math.* functions though Cool, it works, Thanks! Kevan Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.