Jump to content
SophionBlack

Formatting Question (") vs (') vs (_variables)

Recommended Posts

I have a script that's causing me to learn a bit more in formatting and an except is below:

 

private _PhonAlph = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","Xray","Yankee","Zulu"];

private _LZNameID = format ["LZ_%1", _PhonAlph select random 26];

onMapSingleClick "_marker = createMarker [_LZNameID, _pos,0,player]; clicked = 1; openmap false;onMapSingleClick ''; true;";

The problem is that as how the code is written now, the further commands just don't have a target and the changers aren't made.

_LZNameID setMarkerType "mil_end";

I notice when I specify a name for it and forgo it using a variable I have to put it in single quote marks such as: 'MarkerName' how do I get it to read the variable as a single quote string to be read? Such as the str command but for single quote marks?

Share this post


Link to post
Share on other sites

@SophionBlack, private variables, declared outside event handlers, won't be available inside them.

Form LZ name ID inside event handler:

#define PHON_ALPH ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "Xray", "Yankee", "Zulu"]

onMapSingleClick {
    _marker = createMarker [selectRandom PHON_ALPH, _pos, 0, player];

    _marker setMarkerType "mil_end";

    clicked = 1;

    openMap false;

    onMapSingleClick "";

    true
};

 

  • Like 2

Share this post


Link to post
Share on other sites
30 minutes ago, SophionBlack said:

single quote marks

 

Are used when you are already inside a double quote block (string). 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Schatten said:

@SophionBlack, private variables, declared outside event handlers, won't be available inside them.

Form LZ name ID inside event handler:


#define PHON_ALPH ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "Xray", "Yankee", "Zulu"]

onMapSingleClick {
    _marker = createMarker [selectRandom PHON_ALPH, _pos, 0, player];

    _marker setMarkerType "mil_end";

    clicked = 1;

    openMap false;

    onMapSingleClick "";

    true
};

 

That's an issue... The variables inside the event handler must be passed outside, otherwise the marker and LZ report wont match. I've revised the code but still find myself in the same boat. Am I using the wrong tool for the job? Please see the full code below:

 

private _PhonAlph	= ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","Xray","Yankee","Zulu"];
private _LZNameID	= format ["LZ_%1", _PhonAlph select random 26];
private _LZNameTXT	= format ["LZ %1", _LZNameID select [3,8]];
private _Time		= format ["%1-%2%3", date select 2, date select 3, date select 4];
private _AMC		= player;
private _LZPOC 		= GroupID (group _AMC);

clicked = 0;
hint "Click on map to set the target location";
openmap true;
onMapSingleClick {_marker = createMarker [LZMark, _pos,0,player]; _marker setMarkerType "mil_end"; _marker setMarkerText _LZNameTXT; _Helipad = 'Land_HelipadCivil_F' createvehicle getmarkerpos _marker; clicked = 1; openmap false; onMapSingleClick ''; true; };
waitUntil {(clicked == 1)};
hint "LZ Designated";
sleep 3;

//Generate LZ Report;
private _LZCoords	= mapGridPosition getmarkerpos _LZNameID;
private _LZLine1 	= format ["%1 Open - %2", _LZNameTXT, _Time];
private _LZLine2 	= format ["Coordinates: %1", _LZCoords];
private _LZLine3 	= format ["Contact %1 prior to approach", _LZPOC];
private _LZLine4 	= format ["LZ marked with smoke/chemlight (day/night)"];
private _LZLine5 	= if (windStr <= 0) then {format ["Wind: Calm"]} else {format ["Wind %1 at %2", windstr, winddir]};
private _LZLine6 	= if (getposASL _Helipad select 2 <= 0) then {format ["Elevation: Sea Level"]} else {format ["Elevation: %1", round (getposASL _Helipad select 2)]};
private _LZLine7 	= format ["Report all fire recieved"];

hint composeText [_LZLine1, lineBreak, _LZLine2, lineBreak, _LZLine3, lineBreak, _LZLine4, lineBreak, _LZLine5, lineBreak, _LZLine6, lineBreak, _LZLine7];

 

Share this post


Link to post
Share on other sites

The code for onMapSingleClick is a separate scope from the rest of the script.  Change _LZNameTXT from private variable to global: LZNameTXT; then it can be seen inside the onMapSingleClick.

 

(And I don't see LZMark defined, I assume you have this string defined elsewhere, or is _LZNameID supposed to be LZMark?)

 

As @Schatten pointed out, when you're referencing a variable defined outside of the onMapSingleClick, it has to be global for onMapSingleClick to see it.  It won't see the private variables, they're out of scope.

 

And same for variables that get defined inside onMapSingleClick, like your _marker variable; to be seen outside of the onMapSingleClick it has to be global, not private, because onMapSingleClick has its own scope apart from the rest of the script.

 

As to strings, @Harzach rightly points out that semi-quotes ( ' ' ) are used to represent a string within a string expression ( " " ).  If semi-quotes aren't used, then double-quotes ( """") get used, which can become a pain to explain or comprehend how they work when the engine runs the string expression.  Semi-quotes make it much simpler to understand and use.

 

But as Schatten showed, for onMapSingleClick either string or code can be used and by using code, you no longer have the string-within-string happening, so: onMapSingleClick ' ' (semi-quotes),  perhaps should be onMapSingleClick "" (normal string), maybe same with 'Land_HelipadCivil_F'.

  • Like 1

Share this post


Link to post
Share on other sites
11 minutes ago, opusfmspol said:

(And I don't see LZMark defined, I assume you have this string defined elsewhere, or is _LZNameID supposed to be LZMark?)

 

Correct, I was messing with that line trying to figure things out. The main issue that I'm having is calling those variables, after declaring them as a public variable, from inside the event handler. Such as:

 

createMarker [_LZNameID, _pos,0,player]

The _LZNameID isn't taken as the name and adding str doesn't do it either.

Share this post


Link to post
Share on other sites

Because _LZNameID is a private variable (local variable, assigned private to a scope), it's kept within the scope of the script.  The script sees it in the scope where it's defined; however onMapSingleClick runs in a separate scope of its own and can't see it.

 

Define a global variable, like LZMark, within the script, and onMapSingleClick can see that - global meaning visible everywhere on the local machine where it gets defined.  Any scope of all scripts run by the machine will be able to see it.

 

But if it needs to be a public variable, where all machines connected in multiplayer also have the variable because their scripts will need it; first the variable gets defined global on the local machine, then publicVariable is used to broadcast it to all the other machines.

 

Variable scopes

 

Edit ---

See if this is what you intended (not tested):

Spoiler

// Private variables predefined for the script.
private _PhonAlph	= ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","Xray","Yankee","Zulu"];
private _Time		= format ["%1-%2%3", date select 2, date select 3, date select 4];
private _AMC		= player;		// <<--- Note: this is okay for singleplayer, but in multiplayer, player is different on every machine
private _LZPOC 		= GroupID (group _AMC);

// Global variables that get read by onMapSingleClick.
LZNameID	= format ["LZ_%1", _PhonAlph select random 26];
LZNameTXT	= format ["LZ %1", LZNameID select [3,8]];

//Global variables that will be redefined by onMapSingleClick.
clicked = false;
LZMark = "";
Helipad = objNull;

// Get the map click.
hint "Click on map to set the target location";
openmap true;
onMapSingleClick {LZMark = createMarker [LZNameID,_pos,0,player]; LZMark setMarkerType "mil_end"; LZMark setMarkerText LZNameTXT; Helipad = "Land_HelipadCivil_F" createvehicle (getmarkerpos _marker); clicked = true; openmap false; onMapSingleClick ""; true};
waitUntil {Sleep 0.1; clicked};
hint "LZ Designated";
sleep 3;

//Generate LZ Report;
private _LZCoords	= mapGridPosition getmarkerpos LZMark;
private _LZLine1 	= format ["%1 Open - %2", LZNameTXT, _Time];
private _LZLine2 	= format ["Coordinates: %1", _LZCoords];
private _LZLine3 	= format ["Contact %1 prior to approach", _LZPOC];
private _LZLine4 	= "LZ marked with smoke/chemlight (day/night)";
private _LZLine5 	= (if (windStr <= 0) then {"Wind: Calm"} else {format ["Wind %1 at %2", windstr, winddir]});
private _LZLine6 	= (if (getposASL Helipad select 2 <= 0) then {"Elevation: Sea Level"} else {format ["Elevation: %1", round (getposASL Helipad select 2)]});
private _LZLine7 	= "Report all fire recieved";

hint composeText [_LZLine1, lineBreak, _LZLine2, lineBreak, _LZLine3, lineBreak, _LZLine4, lineBreak, _LZLine5, lineBreak, _LZLine6, lineBreak, _LZLine7];

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×