+USCcouple Posted April 10, 2008 Share Posted April 10, 2008 I am trying to get the user's current Latitude and Longitude and store them into number variables. I saw in one post that you could use this in the debug console: local o = Player.ObjectLocation; print(o); so I used this in the debug console: local o = Player.ObjectLocation.latitude; print(o); This worked, so I tried to get it to work in the code by adding a line: Lat1 = Player.ObjectLocation.latitude I also saw this: local accuracy = Player.PositionAccuracy:GetValue('ft') So I also tried: Lat1 = Player.ObjectLocation.latitude:GetValue Lat1 = Player.ObjectLocation.latitude:GetValue() Lat1 = Player.ObjectLocation.latitude:GetValue('deg') I'm just not sure what the proper way of writing the code is. If anyone knows I'd appreciate it. Thanks, Kevan Quote Link to comment
+USCcouple Posted April 10, 2008 Author Share Posted April 10, 2008 Well I think I see where a problem may be. I had this code in the OnStart event: Lat1 = Player.ObjectLocation.latitude I moved it elsewhere in the code and it seemed to work. Before when I had that line of code in the OnStart it just returned 0, so I assumed that it was not working or correct. After moving it, it works fine. I did have a few other lines of code before that in the OnStart event, but does it not have a location before it runs that event? Thanks, Kevan Quote Link to comment
+USCcouple Posted April 10, 2008 Author Share Posted April 10, 2008 One followup question: When you display a variable, after storing the longitude in it, how can you truncate the number, either in the variable itself or when printing it to the screen. So if I have "33.992583461304" stored in a variable "Lat1" I would like it to read something like "33.992" Also would the be any way to round a variable? So that I would get "33.993" Thanks, Kevan Quote Link to comment
+tands Posted April 10, 2008 Share Posted April 10, 2008 Why Kevan, Any time you need a little math help, like with the ideal gas law, perhaps, just ask ole T. Psuedo-code ta follah: TruncLat1 = ((INT (Lat1 * 1000)) / 1000) - T of TandS Quote Link to comment
+tands Posted April 10, 2008 Share Posted April 10, 2008 To round off, after you got TruncLat1, do this: If ((INT (Lat1 * 10000)) / 1000) - (TruncLat1 * 10) > 5 then TruncLat1 = TruncLat1 + 1 - T Quote Link to comment
+FoxFireX Posted April 11, 2008 Share Posted April 11, 2008 Actually, you could simplify the rounding logic a little more. Just add the 0.5 (at whatever decimal place is just below your threshold) before doing the multiply/divide steps. Then when the truncation hits, it'll actually act like it rounded the original number. Quote Link to comment
+tands Posted April 11, 2008 Share Posted April 11, 2008 Very cool FoxFireX! - T of TandS 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.