Location: JBPLAY \ Meteor 2 \ Editing \ Square root in Meteor 2 scripting? Back to Threads |
Dthdealer Joined: 10 March 2007 Posts: 476 |
11 April 2010 09:51 (UK time)
I'm encountering some pretty mean memory errors. When using integers in M2 scripting their values are getting really screwed up. For example a value equals ( all of these, depending on what Is calling it ( eg gamemessage, setobjecthits etc )) 0, 627 and -842150451. Even odder is the fact it is impossible for the variable to be negative, as I have this in my code. If ( variableA > variable B ) int theculpritvariable = variableA - variableB; Only some variables are affected ( generally the last declared in a code block ). Using staticflags instead of variable fixes this problem. Odd eh? EDIT: *Hits self over head* Damn local variables! I'm an idiot! None the less, the original topic question still stands. Any help? Regards, William
Edited: 11 April 2010 10:25 You need to login to create posts in this thread. |
me_mantis Joined: 26 September 2003 Posts: 1152 |
13 April 2010 19:49 (UK time)
I'm pretty sure I've tried to use this, and it hasn't worked... in the range finding system for my tracking rockets. They basically use a square search pattern now. James? Any hope from you? You need to login to create posts in this thread. |
arezey Joined: 16 June 2005 Posts: 1599 |
14 April 2010 11:20 (UK time)
Does M2 support floats or doubles? I recall it might but not sure. Anyhow, as M2 does not support square root, make it yourself. Use the Babylonian method: First pick a starting point (maybe half of the original value or so?). Then iterate the equation of: (Wikipedia) where S is the original value you have and xn is your current result (initially the starting point). With every xn+1 result you get, make it as xn and go over again. Keep going on until the result stops increasing or decreasing (significantly). It's how computers and calculators do it. Problem though is that if M2 does not support floats or doubles, will integers be accurate enough? Edited: 14 April 2010 11:39 You need to login to create posts in this thread. |
Dthdealer Joined: 10 March 2007 Posts: 476 |
14 April 2010 12:04 (UK time)
This is the method I was afraid of using. I'll see if it clogs M2 every times it is run ( but of course I do not need to iterate it too much as accuracy is not really needed ) but if not I'll use it. M2 supports floats and doubles happily. But learn from this lesson float foobar = 5 / 3; You will get the message int happybar = foobar * 100 and putting that in the GameMessage will yield float foobar = 5.00 / 3; Any of the values can have the decimal points. Probably the amount of points determines how many will be in the answer, but I don't know right now. It is 9 pm here in Sydney, and my eyeballs have burnt out from working on the Boss mod I'm going to release by the end of this week ( with only one boss so far mind you ).
You need to login to create posts in this thread. |
me_mantis Joined: 26 September 2003 Posts: 1152 |
14 April 2010 20:01 (UK time)
Lemme know how that sqrt thing works. I'm interested. You need to login to create posts in this thread. |
ParaSait Joined: 26 June 2007 Posts: 1478 |
17 April 2010 15:09 (UK time)
me_mantis(keens) wrote:I don't remember the M2 script syntax very clearly, but here's a c++ implementation of arezey's method: float precision = 0.001; // The smaller, the more precise, but the more cpu intensive Haven't tested it, but that should do it I guess. However, I'm not quite sure how it's going to work in Meteor scripts cause if I understood it right, there are some problems with float division..?
Edited: 17 April 2010 15:21 You need to login to create posts in this thread. |
|
Forums system (C) 1999-2023 by James Bunting.
Terms of Use