Jump to content

Get Coordinates for a Zone in Lua


ATXTracker

Recommended Posts

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.

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...