Home   Help Search Login Register  

Author Topic: grid2pos function  (Read 1521 times)

0 Members and 1 Guest are viewing this topic.

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
grid2pos function
« on: 23 Apr 2009, 20:24:28 »
I haven't seen a grid2pos function anywhere on the interwebs, so I thought I'd make one which I was also planning to use in a artillery dialog.

You can use it by putting this in your init.sqf:
Code: [Select]
mk_grid2pos = compile preprocessFileLineNumbers "mk_grid2pos.sqf";
And then you can call that function like this (accepts a string as argument, returns a 2d pos array):
Code: [Select]
["0285717619"] call mk_grid2pos;You can look at the screenshot to see what happens if you call it like that (screenshot was taken when debugging mode was enabled, so normally there wont be a marker of course).


It currently only works for 6, 8 and 10 digit coordinates, and has been tested in ACE and ACEIP. Only islands listed in the function are supported because doing grid2pos and pos2grid conversion are kinda dodgy in arma.

It also does not support islands with alphanumeric characters in the grid, but islands shouldn't have those anyway (even bis is realizing that these days).





Btw, special thanks to Spooner, because without the code he posted about his pos2grid solution I would've dropped this idea as soon as I found out the obvious problem with the Y axis.

Re: grid2pos function
« Reply #1 on: 02 May 2009, 00:26:30 »
Good idea, saves me from getting my hands dirty ;)

Any particular reason why you pass one string instead of an array with two numbers?
It seems to be a more userfriendly way to do it in my opinion :)

Offline Denisko-Redisko

  • Members
  • *
Re: grid2pos function
« Reply #2 on: 05 May 2009, 12:55:12 »
An interesting script! :good:
I failed when I tried to write a similar solution. I really did not want to be dependent on the specific islands.
Tell me, please: is there a way to do without _magicIslandNumber?
One more thing. Your script - a function (not process)? If so, it might spoil (rewrite) some of the variables the user:
_debugmode,
_strlen,
_isnumber,
_strcut,
_debugmsg,
_magicislandnumber,
_magicnumber,
_testmarker
sorry for my english

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: grid2pos function
« Reply #3 on: 05 May 2009, 17:01:44 »
Yes, SPON Map works out the "magic island number" using a workaround. By measuring the size of the map in a map control at the start of the mission, you can work out the size of the island and therefore don't need any list of measurements. As mikey says, his code is based on my SPON_Map_worldTogrid function, but since he didn't want to rely on SPON Map being used, he used the old list of island measurements that previous worldToGrid implementations had used.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline mikey

  • Former Staff
  • ****
  • Whitespace Whore
Re: grid2pos function
« Reply #4 on: 08 May 2009, 15:12:01 »
That's correct spooner, I couldn't make this function rely on an additional addon, so I hardcoded the island width/height in (which I got from putting in some debug code in the SPON_map addon). I know calling it a "magic number" is probably wrong, but the value should really be in the island config imho.

I did make something that was similar like the spon_worldToGrid function with the map dialog you get with forceMap, but it makes your screen blink for a second when it is trying to get the map width/height, and that wasn't really desirable so I opted for the hardcoded values again.

Anyhow, I'll release 1.01 this weekend to incorporate the suggestions by HulkingUnicorn and Denisko-Redisko. Thanks for the feedback guys  :good:
« Last Edit: 08 May 2009, 15:13:57 by mikey »