Jump to content
Sign in to follow this  
creartan

change variable name Global, how

Recommended Posts

i put in init

MP_fnc_changevar =
{
private["_oldvar","_newvar"];
_oldvar = _this select 0;
_newvar = _this select 1;

_oldvar setVehicleVarName "_newvar";
_newvar = _oldvar;
};

in dialog

onButtonClick = "CloseDialog 0;_nil = [_this select 1] execVM 'changevar.sqf'";

in script

//check if variablename is Nil or available
if (isNil {"Newvar"}) exitwith
{
hint "Newvar is already being used";
sleep 2;
hint "";
};

//and if variable name is available it will change it
if (playerside == east && !isNil {"Newvar"}) exitwith
{
[[_this,Newvar],"MP_fnc_changevar",nil,true] call BIS_fnc_MP;
hint "you are Newvar";

sleep 2;
hint "";
};

and it seems nothing is working

the Nil check

and the change varname

please can you guys show me, how to do it right?

Share this post


Link to post
Share on other sites

Either use isNil {Newvar} or isNil "Newvar", not both https://community.bistudio.com/wiki/isNil. Also when isNil returns true, this means that variable is nil, means it has not been defined, so hint "Newvar is already being used"; is exactly the opposite. Use !isNil instead.

PS MP_fnc_changevar doesn't make sense.

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites
PS MP_fnc_changevar doesn't make sense.

KK is right, I don't see how that's supposed to work.

Also, can you be a little more specific with that you want to change the variable for? Not sure why you need setVehicleVarName. This should be sufficient for changing a variable everywhere (keep scope in mind as well)

MP_fnc_changeVar = compileFinal
'
_old = (_this select 0);
_new = (_this select 1);

call compile format ["%2 = %1", _old call {_this;}, _new];
';

[["_myOldVar","newVar"],"MP_fnc_changeVar",nil,true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites

killzone thanks for the response

1.MP_fnc_changevar made my self to change var Globaly each client,

or is "setVehicleVarName" is GLOBAL?

2.and what is the parameter from the dialog,

is it same as the addaction parameter?

mean,

_attched = _this select 0;

_caller = _this select 1;

_ID = _this select 2;

---------- Post added at 20:16 ---------- Previous post was at 20:12 ----------

hi dread just saw your response comin,

yup theres something i need to do with changing varname ingame,

MP_fnc_changeVar = compileFinal
'
   _old = (_this select 0);
   _new = (_this select 1);

   call compile format ["%2 = %1", _old call {_this;}, _new];
';

[["_myOldVar","newVar"],"MP_fnc_changeVar",nil,true] call BIS_fnc_MP; 

so this is the same function as setvehiclevarname?

like changing the varname?

and what is the scope you mean?

Share this post


Link to post
Share on other sites
so this is the same function as setvehiclevarname?

like changing the varname?

All setVehicleVarName does is make it so if you use hint on an object, instead of returning the default engine-given name to the object (such as "ce06b00# 164274: offroad_01_unarmed_f.p3d") it will return whatever you set the var name to.

_myVehicle = createVehicle ["B_Soldier_F", [0,0,0], [], 0, "CAN_COLLIDE"];
hint str _myVehicle //ce06b00# 164274: b_soldier_f.p3d
_myVehicle setVehicleVarName "MyLittleSoldier";
hint str _myVehicle //MyLittleSoldier

It doesn't change the variable reference to the object, you have to do that manually or you can automate it using the code I posted

Share this post


Link to post
Share on other sites

is the parameter from the dialog right?,

is it same as the addaction parameter?

mean,

_attched = _this select 0;

_caller = _this select 1;

_ID = _this select 2;

and theres something wierd,

when i put

_varname = vehiclevarname _this;

the script not working anymore, why is that?

is it somting to do with the dialog?

---------- Post added at 20:46 ---------- Previous post was at 20:42 ----------

MP_fnc_changeVar = compileFinal
'
   _old = (_this select 0);
   _new = (_this select 1);

   call compile format ["%2 = %1", _old call {_this;}, _new];
';

[["_myOldVar","newVar"],"MP_fnc_changeVar",nil,true] call BIS_fnc_MP;

is't that same as

_newvar = _oldvar

what if i put it inside one function?

MP_fnc_changevar =
{
   private["_oldvar","_newvar"];
   _oldvar = _this select 0;
   _newvar = _this select 1;

   _oldvar setVehicleVarName "_newvar";
   _newvar = _oldvar; // this is the reference, its same right?;
}; 

Share this post


Link to post
Share on other sites
is't that same as

_newvar = _oldvar

Yes, and that's what it does too. But you can't just put that because you are using strings and a string cannot be a variable, so you have to do some trickery to get it to work.

Share this post


Link to post
Share on other sites

ok i got it,

im using "PLAYER" instead of _this

is that right?

Share this post


Link to post
Share on other sites
ok i got it,

im using "PLAYER" instead of _this

I don't think that will work, try to stay away from reserved words

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  

×