It is very late here, so I hope this makes sense...Using the private command ensures that that a variable is available throughout the entire scope/variable space of the script. Variables that are initialized inside a control structure (if, forEach, while, etc.) are only available inside that control structure. Example:
if (true) do
{
_var = 1;
};
hint format ["var = %1", _var];
In the above example, the hint will return nothing because _var is not available outside the if block. To make it available you have to 1) initialize it before the control structure OR 2) use the private command:
_var = 0;
if (true) do
{
_var = 1;
};
hint format ["var = %1", _var]; // Will return 1.
OR
private ["_var"];
if (true) do
{
_var = 1;
};
hint format ["var = %1", _var]; // Will return 1.
I know this doesn't seem overly relevant to your current script, but it is good practice to always begin your scripts with the private command to make sure that local variables will always be available (especially if there are times you don't want to actually initialize them right away) even if you aren't using inner scopes/control structures (because you might add one later!)...I have spent many a hour tracking down bugs down to failure to use the private command. Yes, there are times you don't want them available outside of a specific control structure, but those are fairly rare.
So on to setVariable/getVariable. These commands allow us to store/retrieve a value to/from the variable space of an object (player, vehicle, game logic, etc.). So just like _var = 1 stores the value of _var to the variable space of the script you are running, player setVariable ["var", 1]; stores the variable to the object. So this value is like a global variable, that is, it is available wherever the object is available. So, using your scenario for example:
obj1_trucks =1; // Where obj1_trucks is a global variable.
...and...
obj1 setVariable ["trucks", 1]; // Where obj1 is the name of a game logic.
...Achieve the same result, store a value of 1 to a global variable space.
So, why use setVariable instead of global variables? It really is a preference call, but there are times when one might be more useful than another. For example, say you had a group of 5 units and you wanted to store their "moods". You could do this one of two ways:
// Create GVs to store "moods" for the units in group1.
unit1Mood = "happy";
unit2Mood = "happy";
unit3Mood = "happy";
unit4Mood = "happy";
unit5Mood = "happy";
OR
// Use setVariable to create "moods".
{_x setVariable ["mood", "happy"]} forEach units group1;
In this case, I think the setVariable method is far easier.
You can also use setVariable like a public variable as well. You just add a boolean to the parameters array. Example:
obj1_trucks =1; // Where obj1_trucks is a global variable.
publicVariable "obj1_trucks";
...and...
obj1 setVariable ["trucks", 1, true]; // Where obj1 is the name of a game logic.
...do the same thing (for JIP as well).
I hope that clarifies things a little...do you need to use setVariable, no, but I wanted to make sure you were aware of the option.