+ATXTracker Posted February 6, 2013 Share Posted February 6, 2013 I am using the Urwigo builder to try and do some coordinate math. I would like to get the lat/lon for a zone, preferably for the "center," but any point would do. For a character, I can do this with a LUA expression: characterID.ObjectLocation.latitude Question 1) How do I do this for a zone? What is the equivalent LUA for accessing a zone's coordinate(s)? Ultimately, I want to move a character around inside a zone, by setting a timer, doing some math and setting the character's ObjectLocation. Question 2) Will this work reliably on various devices, or is it asking too much? Will the compass/distance to that character update in the players as it move? Thanks. Quote Link to comment
Ranger Fox Posted February 7, 2013 Share Posted February 7, 2013 From what I've seen, if you place the character inside a zone, the player will be able to interact with the character as long as he or she is within that zone. I have not, however, experimented with zones larger than ten meters on each side, so, perhaps, the character's coordinates then play a part. I would doubt this, though, because it's possible to move a character and item between zones without adjusting the object's location. Zones have an OriginalPoint and Points object. The OriginalPoint does not mean as much, or so it has been my experience with Whack-A-Lackey and Battleship. Instead, it's Points, a table of ZonePoint objects, that matters. For instance, reference my function MoveZoneToRandom in Battleship (I intentionally created a large section of utility functions within that cartridge; they can be copied very easily to other cartridges). I update the OriginalPoint in another function. Anyway, I'm straying a bit. Let me answer your second question: a zone will not move until you reactivate it. I suggest you make it a rule of thumb to deactivate a zone before modifying its coordinates. Nothing bad will happen, but it's a good rule to have because it will also force you to reactivate it, and that's when its position will be updated. And here is the code I use to modify a zone's location, copied from Battleship's utility functions: function CenterZoneOnPoint(zZone, ZoneRadius, point) local dist = Wherigo.Distance(0, units) local newZp = Wherigo.TranslatePoint(point, dist, 0) -- new center point for the new zone dist = Wherigo.Distance(ZoneRadius, units) local pts = { Wherigo.TranslatePoint(newZp, dist, 45), Wherigo.TranslatePoint(newZp, dist, 135), Wherigo.TranslatePoint(newZp, dist, 225), Wherigo.TranslatePoint(newZp, dist, 315), } zZone.Active = false zZone.OriginalPoint = newZp zZone.Points = pts end You will notice I am assuming a zone is square and comprised of four points. You may have a different intention in mind. When I created the function, I decided I did not want to incur the performance costs of making things too generic because the Garmin units were (and still are, actually) popular in my area, including the underpowered and unstable Garmin Oregon. Quote Link to comment
+ATXTracker Posted February 7, 2013 Author Share Posted February 7, 2013 Thanks Ranger Fox, I think this is just what I needed. Quote Link to comment
+ATXTracker Posted February 7, 2013 Author Share Posted February 7, 2013 Of course, I have a follow up question. When I try to display the value of the first point on a zone, I get an exception. This is in the Urwigo emulator. Lua expression: zV.Points[0].latitude error: attempt to index field '?' (a nil value) the zone exists and has points Quote Link to comment
+charlenni Posted February 7, 2013 Share Posted February 7, 2013 In Lua arrays start with 1 and not with 0, so you had to use zV.Points[1].latitude. Quote Link to comment
+Plateo et Ana Posted October 31, 2016 Share Posted October 31, 2016 I'm taking this topic back because I've got the same question as the author, and it didn't get a real answer. I also want to get a zone coordinates in LUA. More precisely, I want to get the "original point" of the zone, and store it in a variable. Is it possible ? Quote Link to comment
Ranger Fox Posted October 31, 2016 Share Posted October 31, 2016 I'm not sure how useful having the OriginalPoint coordinates would be. You're thinking like a geocacher: a point, a dot on the map to indicate a location. In Wherigo, a zone is a group of coordinates. When you plot the coordinates in sequence on a map, they usually make a geometric shape, such as a rectangle. (I hide this away in the Wherigo\\kit builder, asking people only for a single coordinate and a radius for the zone, but Kit actually creates square zones when it generates the cartridge script.) Anyway, it's possible to store anything you want in a variable: --zoneObj contains a reference to your zone. local origpoint = zoneObj.OriginalPoint local allpoints = zoneObj.Points These days, I'm not sure how the current player apps use the OriginalPoint coordinates. Still, I consider it good practice to keep OriginalPoint either inside the zone or on an edge or corner, especially when you're moving a zone. If you do modify a zone's coordinates, don't forget to deactivate and reactivate the zone to force the player app to acknowledge the change. Quote Link to comment
+fizzymagic Posted November 4, 2016 Share Posted November 4, 2016 Why not just use the centroid of the zone points? It's easy to calculate and makes as much sense as anything else. Quote Link to comment
+Plateo et Ana Posted November 5, 2016 Share Posted November 5, 2016 Thanks for the help Ranger Fox and Fizzymagic. I tried several solutions on my side, but none of them gave satisfaction. I've simplified my cartridge gameplay and I just don't have to find my zone coordinates anymore. Quote Link to comment
+Arnaudd Posted November 4, 2017 Share Posted November 4, 2017 Hello, i'm trying to use the characterID.ObjectLocation.latitude Lua expression and assign it to an in game variable that i have called CurLatitude. I have created the variable and identifiers and tried CurLatitude=characterID.ObjectLocation.latitude as a lua user code. Then display CurLatitude as usual but the emulator does not run. I have also trued Wherigo.CurLatitude=characterID.ObjectLocation.latitude I'm new to using lua within urwigo. How can i do this? Thank you. 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.