Search the Community
Showing results for tags 'string'.
Found 9 results
-
Limit the number of characters in a string
ColonelKernel posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hi. Is it possible to limit the number of characters in a string variable? For example, let's say I use "typeOf" to get the name of a vehicle. How can I display the first five characters of its name? -
Back again with another function, Not sure if there are other string replacement routines, but I've quickly put this one together. Source // // PX_fnc_stringReplace :: Replace substrings // Author: Colin J.D. Stewart // Usage: ["xxx is awesome, I love xxx!", "xxx", "Arma"] call PX_fnc_stringReplace; // PX_fnc_stringReplace = { params["_str", "_find", "_replace"]; private _return = ""; private _len = count _find; private _pos = _str find _find; while {(_pos != -1) && (count _str > 0)} do { _return = _return + (_str select [0, _pos]) + _replace; _str = (_str select [_pos+_len]); _pos = _str find _find; }; _return + _str; }; Example: ["xxx is awesome, I love xxx!", "xxx", "Arma"] call PX_fnc_stringReplace; // Output: Arma is awesome, I love Arma! -Colin
-
array Compare var string to an array
JustRoger posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
I searched for a long while for this before posting. (fairly new to this so keep the snark to a min) I am trying to compare a string against an array: _Wep = "Weapon1; _ArrayWeps = ["Weapon1", "Weapon2", "Weapon3"]; _IsInArray = _Wep in _ArrayWeps; // is _Wep inside the array should give me a boolean for _isInArray of true/false? or do I have to do: if (_Wep in _ArrayWeps) then { // true}; OR if there is a better way to please do share. I do appreciate the input. -
Group name not recognised (type string, expected group)
lawman_actual posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
A recurring problem that i seem to run into is I don't know how to use group names as group names when writing scripts. Let me explain: In the eden editor, I have set the name of a group; by opening the interface for the group (double click on the icon above group leader) and entering something in the 'callsign' field. However, if I now go to write a script that requires the name of that group, i can't seem to format it in such a way that the command will accept the name I have inputted. For example, here is a snippet from the mission: _group = "R Rustam 1 - Alpha"; _leader = leader _group; _passangers = _group - _leader; _leader assignAsDriver qrf_w1; {_x assignAsCargo qrf_w1} forEach _passangers; _group orderGetIn true; What i can't get to work is the leader command, because no matter how I format the group name it doesn't seem to want to accept it. I believe the following has been tried without success: _group = "R Rustam 1 - Alpha"; _group = "Rustam 1 - Alpha"; _group = R Rustam 1 - Alpha; _group = Rustam 1 - Alpha; -
Hello everyone, here is a really simple function that I put together: /* Author: Terra Description: Converts the elements of an array into a string Parameter(s): 0: ARRAY - array of elements of any type 1 (Optional): STRING - seperator between elements (default: ", ") Returns: STRING */ params [ ["_array", [],[[123]]], ["_seperator", ", ", ["123"]] ]; _str = format ["%1", _array select 0]; { private _addString = _x; if (typeName _addString != typeName "123") then {_addString = str _addString}; _str = _str +_seperator +_addString; } forEach (_array -[_array select 0]); _str Just some code that I wrote down while working on another project. Feel free to modify and comment.
-
--------------------------------- UPDATE 29.01.2022 With Arma 3 2.06+ it is now possible to use regexReplace instead: https://community.bistudio.com/wiki/regexReplace Performance: ["12345 123456", "123", "abc"] call TER_fnc_editString; Execution Time: 0.0093 ms | Cycles: 10000/10000 | Total Time: 93 ms "12345 123456" regexReplace ["123/g", "abc"] Execution Time: 0.0016 ms | Cycles: 10000/10000 | Total Time: 16 ms --------------------------------- Hello everyone, I just wanted to share a small function. It can replace certain parts of a string with your own string. /* Author: Terra Description: Substitute a certain part of a string with another string. Parameters: 1: STRING - Source string 2: STRING - Part to edit 3: STRING - Substitution Returns: STRING Example: ["12345 123456", "123", "abc"] call TER_fnc_editString; Returns: "abc45 abc456" */ TER_fnc_editString = { params ["_str", "_toFind", "_subsitution"]; _char = count _toFind; _no = _str find _toFind; while {-1 != _str find _toFind} do { _no = _str find _toFind; _splitStr = _str splitString ""; _splitStr deleteRange [(_no +1), _char -1]; _splitStr set [_no, _subsitution]; _str = _splitStr joinString ""; }; _str }; Additional information:
-
I'm trying to access an object while only having the object's name in string format. For instance, I have an object Box_East_WpsSpecial_F named "ammoBox_23". There are another 22 ammo boxes, so I need to reference this specific one. How can I do something like hideObjectGlobal or removeMPEventHandler when they expect the format OBJECT hideObjectGlobal BOOLEAN?
- 3 replies
-
- getvariable
- variable name
-
(and 2 more)
Tagged with:
-
Hi all, I am currently developing a system that will select random objectives then assign markers to that area so that it is visible. I have run into an issue with the "SetMarkerPos" command. The error I receive is "Error setmarkerpos: type string, expected Array". The reason it is setup below is due to the fact I have 3 objective types. Town Objectives Primary Objectives Secondary Objectives The script i have created for setting marker positions for Town and Primary objectives is simple as all that is required is that the markers for those are moved to that designated town. However, a secondary objective can only exist inside a primary objective and not all of the primary objectives have a secondary objective. The idea is/was to combine the name of the Primary objective (publicvariable of "mainmark") with secondary_%1 to create the names of the secondary objective markers. I am then able to see if there is a secondary objective nearby to the randomly selected Primary objective and if there is, move the marker to it to indicate such. however I receive the above mentioned error when trying to set the markers position. I was hoping I could receive assistance in fixing this error either via directing me on how to assign the string into an array so the error stops or by finding another way to achieve this goal. Thanks. Below is the script I am using to achieve this goal. null = execVM "obj\objective_controller.sqf"; _distm = getmarkerpos mainmark; _distt = getmarkerpos townmark; _dista = _distm distance _distt; if (_dista < 2200) then { execVM "obj\objective_controller.sqf"; }; if (_dista > 2200) then { _getmarkm = getmarkerpos mainmark; _showobjectivem = "mark_main_area" setMarkerPos _getmarkm; _showobjectivem = "mark_main_name" setMarkerPos _getmarkm; _getmarkt = getmarkerpos townmark; _showobjectivet = "mark_town_area" setMarkerPos _getmarkt; _showobjectivet = "mark_town_name" setMarkerPos _getmarkt; }; //----------------------------------------------------------------------------------------------- //Find secondary nearby _townsec = format ["secondary_%1",mainmark]; _dists = getmarkerpos _townsec; _secfind = _distm distance _dists; if (_secfind < 500) then { hint format ["placing %1 in %2 area", _townsec, mainmark]; _showobjectivesec = "mark_secondary_area" setMarkerPos _townsec; _showobjectivesec = "mark_secondary_name" setMarkerPos _townsec; }; if (_secfind > 500) then { };
- 3 replies
-
- SetMarkerPos
- string
-
(and 2 more)
Tagged with:
-
Hi all, Have not found a function to change every occurrence of given string in deeply nested array to another string, so made it myself. Hopefully some one will find it usefull ;) Fill free to critic and/or improve, this way everyone wins :) Code will return positive number showing how many times string was replaced, zero if string was not found and -1 if input is wrong. This function WILL modify provided array, if this is not wanted, perform function with copy of array. Function will make CaSE SenSitivE check. Use showcase: myArray = ["BAD","fsgg",0,[0,5,3,"BAD"],"something",[[0,0,5,4,"BAD",["Bad"]]],["ddftest","BAD"],[],[]]; searchString = "BAD"; replaceString = "GOOD"; result = [myArray, searchString, replaceString] call fnc_replaceStringDeep; So here is output result == 4 myArray == ["GOOD","fsgg",0,[0,5,3,"GOOD"],"something",[[0,0,5,4,"GOOD",["Bad"]]],["ddftest","GOOD"],[],[]]