NGagedFX
Dec 3 2010, 10:51
Hello there, I'm getting more and more into scripting, and as a somewhat functional script - but more importandly as a personal tutorial - I'm writing this 'CreateMarker' script.
How to call:
nul = [position, "name", "type", "text", "colour", size, time, gps_object] execVM "scripts\CreateMarker.sqf"
Description of Variables:
position: array - getPos object or [x,y] - default = getPos this
name: string - name
type: cfgMarker - the actual icon (BISWiki > cfgMarkers) - default = empty
text: string - text visible on map - default = none
colour: string - ColorBlack, ColorBlue, ColorRed, ColorGreen, ColorYellow, ColorOrange, ColorWhite - default = ColorBlack
size: number - default = 1
time: number - time in seconds before marker gets deleted - default = 0 (infinite)
gps_object: name - object the marker should track - default = none
example: nul = [getPos unit1, "marker_unit1", "hd_objective", "Unit 1 is over here!", "ColorRed", 1, 20, unit1]
CreateMarker.sqf
_markerPos = _this select 0;
_markerName = _this select 1;
_markerType = _this select 2;
_markerText = _this select 3;
_markerColor = _this select 4;
_markerSize = _this select 5;
_markerTime = _this select 6;
_markerGpsObject = _this select 7;
_markerName = createmarker [_markerName, _markerPos];
_markerName setMarkerType _markerType;
_markerName setMarkerText _markerText;
_markerName setMarkerColor _markerColor;
_markerName setMarkerSize [_markerSize,_markerSize];
//_markerTime and _markerGpsObject are working fine so I haven't included them in this post (it's a lot of text atm :P)
If I fill in all the fields correctly, this script does exactly what I want it to. However, as with every script I've used up until now, you always had the choice to not assign some variables by cutting off the exec string or by using "" or not filling in anything. For example:
1 - nul = [getPos unit1, "", "", "Unit 1 is over here!", "", , , unit1]
2 - nul = [getPos unit1, "marker_unit1"]
As seen in 1, "" in case of a string or [space] in case of a number, or as seen in 2 where the last part is simply cut off, it should use the default values defined by the script. However, I've had major problems defining these.
if (_markerType == "") then {hint "true"}; this worked in case 1
if (isNil "_markerType") then {hint "true"}; this worked in case 2
But as you don't know how someone is gonna use your script:
if ((isNil "_markerType") || (_markerType == "")) then {hint "true"}; which didn't work at all and even gave me errors :confused:
So how do I define these default variables? :confused:
How to call:
nul = [position, "name", "type", "text", "colour", size, time, gps_object] execVM "scripts\CreateMarker.sqf"
Description of Variables:
position: array - getPos object or [x,y] - default = getPos this
name: string - name
type: cfgMarker - the actual icon (BISWiki > cfgMarkers) - default = empty
text: string - text visible on map - default = none
colour: string - ColorBlack, ColorBlue, ColorRed, ColorGreen, ColorYellow, ColorOrange, ColorWhite - default = ColorBlack
size: number - default = 1
time: number - time in seconds before marker gets deleted - default = 0 (infinite)
gps_object: name - object the marker should track - default = none
example: nul = [getPos unit1, "marker_unit1", "hd_objective", "Unit 1 is over here!", "ColorRed", 1, 20, unit1]
CreateMarker.sqf
_markerPos = _this select 0;
_markerName = _this select 1;
_markerType = _this select 2;
_markerText = _this select 3;
_markerColor = _this select 4;
_markerSize = _this select 5;
_markerTime = _this select 6;
_markerGpsObject = _this select 7;
_markerName = createmarker [_markerName, _markerPos];
_markerName setMarkerType _markerType;
_markerName setMarkerText _markerText;
_markerName setMarkerColor _markerColor;
_markerName setMarkerSize [_markerSize,_markerSize];
//_markerTime and _markerGpsObject are working fine so I haven't included them in this post (it's a lot of text atm :P)
If I fill in all the fields correctly, this script does exactly what I want it to. However, as with every script I've used up until now, you always had the choice to not assign some variables by cutting off the exec string or by using "" or not filling in anything. For example:
1 - nul = [getPos unit1, "", "", "Unit 1 is over here!", "", , , unit1]
2 - nul = [getPos unit1, "marker_unit1"]
As seen in 1, "" in case of a string or [space] in case of a number, or as seen in 2 where the last part is simply cut off, it should use the default values defined by the script. However, I've had major problems defining these.
if (_markerType == "") then {hint "true"}; this worked in case 1
if (isNil "_markerType") then {hint "true"}; this worked in case 2
But as you don't know how someone is gonna use your script:
if ((isNil "_markerType") || (_markerType == "")) then {hint "true"}; which didn't work at all and even gave me errors :confused:
So how do I define these default variables? :confused: