Jump to content
Sign in to follow this  
Igitur

My first little function

Recommended Posts

Hey,

I've written my first little function for Arma. Nothing exceptional, I just begin to familiarize myself with the scripting commands, syntax, procedures, etc... The function itself allows you to place and remove the Cinema Border at will while you're playing, hiding and showing the HUD consequently to micromanage your team as you want. You do it by pressing the LCTRL+DELETE keys simultanously. Here is the code :

//IGIT_CinBorder.sqf

//

//Release : 28/04/2013 by Igitur.

//

//To use this function, save this file in your root mission folder as IGIT_CinBorder.sqf and write the following in your init.sqf (create one if needed):

//

// [0.5] execVM "IGIT_CinBorder.sqf";

//

//The passed parameter [0.5] can be modified and defines the change duration in seconds.

//

//

//Hit LCTRL+DELETE to place and remove the cinema Border at will;

//

//

/////////////////////////////////////////////////////////////////////

//// Initializing speed, counter and first border display

IGIT_cb_speed = _this select 0;

IGIT_cb=1;

[0, 0] spawn BIS_fnc_cinemaBorder;

//// Keyboard input detection (Keys : LCtrl+Delete), "Delete" neutralization and variable evaluation

waitUntil {!isNull findDisplay 46};

(findDisplay 46) displayAddEventHandler ["KeyDown", "_this call IGIT_disabling_MoveLeft"];

IGIT_disabling_MoveLeft = {

_done = false;

if ((_this select 1) in ActionKeys "MoveLeft" and (_this select 3) and ((IGIT_cb/2) > floor (IGIT_cb/2))) then {_done = true; [1, IGIT_cb_speed] spawn BIS_fnc_cinemaBorder; IGIT_cb=IGIT_cb+1} else {

if ((_this select 1) in ActionKeys "MoveLeft" and (_this select 3) and ((IGIT_cb/2) == floor (IGIT_cb/2))) then {_done = true; [0, IGIT_cb_speed] spawn BIS_fnc_cinemaBorder; IGIT_cb=IGIT_cb+1}};

_done;

};

Now I still have a couple of questions :

1) I've not been able to figure out how to upload a simple Notepad file on this forum. Anyone knows ?

2) In the code above I use a variable (cb) to check whether the Cine Border must be put in or removed. I first wanted to use a local variable (_cb) instead, but that does not work. So I declared my variable as private, just in case. Can someone tell me why the _cb variable won't work, and if or not my current cb variable is actually private ?

3) I never play online and have no clue of the specifics of multiplayer Scripting, so do you think that function could work in multiplayer as well ? Why, and what should I care for to make it usable online ?

Thx a lot :cool:

EDIT : duration parameter and downloadable sqf file added;

https://www.dropbox.com/s/0s8s0m4y0yqb50j/IGIT_CinBorder.sqf

Edited by Igitur
function name changed, one line deleted, variable name changed, downloadable version added, duration parameter added

Share this post


Link to post
Share on other sites

1. You cannot upload files to the forum, you have to use a file host (or host from your own public dropbox or the like) and provide a link.

2. If you make "cb" a local variable, any reference to its value is lost after the functions ends as it only exists within the scope of the function. You would either need to pass it to another instance or return it to the calling instance. That being said, having it as a global variable works just fine because its value is acessible and updated inside and out of the function.

3. If the function and the event handler are added in the init.sqf or other code that runs on all machines, then it would be muttiplayer compatible, but, only the player that calls the function will see the border.

A quick note about tagging your global variables, you should your tag in front of cb just to make sure it does not overwrite (or is overwritten) by another use of cb in the mission or any addons the player is using. Further, I see that you use the IG_ tag in the name of the .sqf. FYI , although not compuslory, the de facto standards for tags are 3-5 characters. More info here and here.

Edited by Loyalguard

Share this post


Link to post
Share on other sites
1. You cannot upload files to the forum, you have to use a file host (or host from your own public dropbox or the like) and provide a link.

2. If you make "cb" a local variable, any reference to its value is lost after the functions ends as it only exists within the scope of the function. You would either need to pass it to another instance or return it to the calling instance. That being said, having it as a global variable works just fine because its value is acessible and updated inside and out of the function.

3. If the function and the event handler are added in the init.sqf or other code that runs on all machines, then it would be muttiplayer compatible, but, only the player that calls the function will see the border.

A quick note about tagging your global variables, you should your tag in front of cb just to make sure it does not overwrite (or is overwritten) by another use of cb in the mission or any addons the player is using. Further, I see that you use the IG_ tag in the name of the .sqf. FYI , although not compuslory, the de facto standards for tags are 3-5 characters. More info here and here.

Thank you Loyalguard :)

So if I understand correctly, my "cb" variable IS local even though there is no "_" sign before it. Just a naming convention, the important point being to declare is as private before using it in the script, right ? That's what I wanted, since I dont want this script to interfere with other players display or addons.

As for the tag in the function name, I just put it to distinguish my own scripts from other files in my scripts Library, but I'll follow your advise and change the name.

thx again.

Share this post


Link to post
Share on other sites

Not to mention, shouldn't private ["cb"] cause a compile error?

private scope is just limiting that variable's content to that script (or braces block, depending on where it's defined), so you can have many _cb in different scripts, and they could all have differing values.

all variables starting with an _underscore are treated as private by the engine. All variables without an underscore, are treated as 'global' variables, which can be accessed anywhere within the game session where it's defined (so, on the client, in this case). Changing that value anywhere, will change the value for all other uses of it also (essentially).

Global variables are not public variables (in regard to how Arma works, a public variable is one that is synchronised across the network to all clients + the server, unless done specifically for individual sessions), so using a global variable wont interfere with other clients.

Share this post


Link to post
Share on other sites

Ok I understand better now (well, I think). The cb variable is global and that's why the function works, but that implies the counter can possibly be affected by another script or addon. I re-edit my first post and delete the " private ["cb"] " line.

Share this post


Link to post
Share on other sites

I would also recommend adding your tag in front of every instance of cb (IGIT_cb) and in front of your function (IGIT_disabling_MoveLeft) to identify them as unique to you and again so they cannot be overwritten or confused for commands.

Share this post


Link to post
Share on other sites
I would also recommend adding your tag in front of every instance of cb (IGIT_cb) and in front of your function (IGIT_disabling_MoveLeft) to identify them as unique to you and again so they cannot be overwritten or confused for commands.

Done. It's always great to see helpful people :)

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
Sign in to follow this  

×