Bunny75 10 Posted September 9, 2009 How do I create marker name dynamically? I have : _rMarker= floor(random 3); And then I want to create the last marker name from that _rMarker number to this: "main_target" setMarkerPos getMarkerPos "main_target_pos_0"; So the marker would be something like "main_target_pos_" + _rMarker Share this post Link to post Share on other sites
Ghost 40 Posted September 9, 2009 I use the following and seems to work well. _markname = "Your_markername" + str (random 999); Share this post Link to post Share on other sites
kylania 568 Posted September 9, 2009 You might run into a case where you have duplicate marker names doing this though, unless you keep track of currently used names or something. Share this post Link to post Share on other sites
Inkompetent 0 Posted September 9, 2009 _markerList = []; _markerStr = "Your_markername"; while {done_markers < wanted markercount} do { _markerNum = str (random 999); if !(_markerNum in _markerList) then { _markerName = markerStr + _markerNum; _markerList = _markerList + [_markerNum]; done_markers = done_markers + 1; }; }; Quite crude and can probably be done better, but should work to not get doublets. Share this post Link to post Share on other sites
galzohar 31 Posted September 9, 2009 If you hold the used numbers in a sorted array (or list, which would be more efficient but you'd have to implement the list yourself), then picking a random number that isn't already there is rather simple: // assuming you defined MAX_NUMBER // assuming array name is arrUsed _newNumber = random (MAX_NUMBER - count arrUsed); for "_i" from 0 to ((count arrUsed) - 1) do { if (_newNumber >= arrUsed select _i) then { _newNumber = _newNumber + 1; }; }; // now you need to add the new number into the used numbers array, which is why a linked list would owrk better than an array. Share this post Link to post Share on other sites
Defunkt 431 Posted September 9, 2009 Not necessary to maintain an array if he was previously happy to randomize it, just append a hi-marker counter and increment it by one each time a new marker is created. Share this post Link to post Share on other sites
shuko 59 Posted September 9, 2009 Since you know the position where the marker should be, why not just use that info instead of a number/random number. Idea: _markerName = _markerName + str round((_pos select 0)) + str round((_pos select 1)) If we have: _markerName = "myMarker" _pos = [2384.423,1492.332,0] the code should make it something like: "myMarker23841492" Share this post Link to post Share on other sites
galzohar 31 Posted September 9, 2009 I thought he actually cared about what the marker name is, if the marker name itself does not matter than you can just create it as "1", "2" etc, and have a global variable that counts which is next. Share this post Link to post Share on other sites
Mike84 1 Posted September 9, 2009 I use this in my create marker function: // create an unique number each time if ( isNil "mk4_uniqueNumber" ) then { mk4_uniqueNumber = 0 }; mk4_uniqueNumber = mk4_uniqueNumber + 1; // make a "unique" marker name _markerName = format["mk4_MRK%1", mk4_uniqueNumber ]; Share this post Link to post Share on other sites
Bunny75 10 Posted September 10, 2009 Thanks everyone! I think the first one will suit best as it's the simpliest. The thing is that I have multiple markers on map with a name main_target_pos_x (x is number) and I just have to pick one up randomly. Sorry, I should've mentioned that from the beginning. Share this post Link to post Share on other sites
Przemek_kondor 14 Posted September 10, 2009 the simplest way is (creating has to be done after start mission): _mName = format["m%1", time]; Share this post Link to post Share on other sites