Jump to content
Sign in to follow this  
CharlieSp

Confused how to lay out a public variable

Recommended Posts

So after looking around the forums and the wiki I've got myself completely confused how to lay out a public variable. I under stand you start with a global variable and then do

publicVariable = "nameoftheglobal"; but when implementing that into my script to unlock/lock a vehicle it doesnt work?

unlockTransport.sqf

obj1 = 1;
unit1 = 2;
publicVariable "obj1";
publicVariable "unit1";


{ 
if((typeOf unit1) == "US_Soldier_TL_EP1") then
{
obj1 setvehiclelock "unlocked";
obj1 removeaction unlock;
lock = obj1 addaction ["<t color=""#F6FF00"">" +"Lock", "lockTransport.sqf"];

exit;
};

lockTransport.sqf

obj1 = 0;
unit1 = 1;
publicVariable "obj1";
publicVariable "unit1";

{
if((typeOf unit1) == "US_Soldier_GL_EP1") then
{
obj1 setvehiclelock "locked";
obj1 removeaction lock;
unlock = obj1 addaction ["<t color=""#F6FF00"">" +"Unlock", "unlockTransport.sqf"];

exit;
};

Thats my code for it, I'm also have trouble hiding the option if the unit isnt US_Soldier_GL_EP1?

Edited by CharlieSp

Share this post


Link to post
Share on other sites

I'm not sure what you are trying to achieve. Why not use http://community.bistudio.com/wiki/lock ? It's a global command and will lock the car on all computers in MP.

As for hiding an addaction you can use a condition within the addaction:

lock = obj2 addaction ["<t color=""#F6FF00"">" +"Lock","go.sqf",nil,1,false,true,"","(typeOf unit1) == ""US_Soldier_GL_EP1"""];

PublicVariable allows you to broadcast a variable to all computers. Like arrays, a string, code and so forth.

Share this post


Link to post
Share on other sites
I'm not sure what you are trying to achieve. Why not use http://community.bistudio.com/wiki/lock ? It's a global command and will lock the car on all computers in MP.

As for hiding an addaction you can use a condition within the addaction:

lock = obj2 addaction ["<t color=""#F6FF00"">" +"Lock","go.sqf",nil,1,false,true,"","(typeOf unit1) == ""US_Soldier_GL_EP1"""];

PublicVariable allows you to broadcast a variable to all computers. Like arrays, a string, code and so forth.

Thank you, sorry if I didn't make myself clear before, basically I'm making a training map for my clan and I want only instructors (US_Soldier_GL_EP1) to be able to unlock/lock the vehicles on the map so we have control over when a trainee can enter a vehicle, for that lock command would I just get rid of the public variables at the top of my script and replace obj1 setvehiclelock "locked" with obj1 lock true? and then obviously switch that around for the unlock

---------- Post added at 23:20 ---------- Previous post was at 23:15 ----------

so basically it would look like:

obj1 = 0;
unit1 = 1;

{
if((typeOf unit1) == "US_Soldier_GL_EP1") then
{
obj1 lock true:
obj1 removeaction lock;
unlock = obj1 addaction ["<t color=""#F6FF00"">" +"Unlock", "unlockTransport.sqf"];

exit;
};

And obj1 lock false in the unlock script?

Share this post


Link to post
Share on other sites
Thank you, sorry if I didn't make myself clear before, basically I'm making a training map for my clan and I want only instructors (US_Soldier_GL_EP1) to be able to unlock/lock the vehicles on the map so we have control over when a trainee can enter a vehicle, for that lock command would I just get rid of the public variables at the top of my script and replace obj1 setvehiclelock "locked" with obj1 lock true? and then obviously switch that around for the unlock

---------- Post added at 23:20 ---------- Previous post was at 23:15 ----------

so basically it would look like:

obj1 = 0;
unit1 = 1;

{
if((typeOf unit1) == "US_Soldier_GL_EP1") then
{
obj1 lock true:
obj1 removeaction lock;
unlock = obj1 addaction ["<t color=""#F6FF00"">" +"Unlock", "unlockTransport.sqf"];

exit;
};

And obj1 lock false in the unlock script?

Yes. :)

Share this post


Link to post
Share on other sites
Yes. :)

Hmm, followed exactly what I said before (changing the : to a ; on line 7 of course :P ) but it still doesnt work, the addaction pops up but when i click it nothing happens?

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  

×