Jump to content
sbondo1234

Undefined Variable in Expression

Recommended Posts

I have created a script an assigned arma 3 weapon classnames to different variables, like this:

_sg_mk1 = "srifle_DMR_03_F";
_sg_mk1Mags = "20Rnd_762x51_Mag";

I have then made an addAction and put it on an ammo crate so that when you click mk-I you will get the weapon in the variable above. Like this:

_crate = sg_classes;

_crate addAction ["MK-I", _sg_mk1, _sg_mk1Mags];

I have made it like this for flexibility, instead of changing everything I can change one classname in a variable to edit the outcome of your option.

 

There is an issue though when I go in-game and scroll down on the crate I see MK-I, but when I click it I get the following error:

'|#|srifle_DMR_03_F'
Error Undefined Variable in expression: srifle_dmr_03_f

 

So my question is how would I properly go about assigning classnames to variables and then have the variables be put in an addAction to give players the items.

Share this post


Link to post
Share on other sites

addAction needs proper code to execute properly and you need to use addMagazine and addWeapon to give someone weapon and magazine.

Your code thrown to addAction is just a className, and className does nothing alone and the engine understands your code like this:

srifle_DMR_03_F

The engine thinks the srifle_DMR_03_F is a variable but it's defined nowhere and that's why it causes the error.

 

Remember the syntax of the addAction? You can achive the goal with the code like this:

_crate = sg_classes;

_crate addAction ["MK-I", {
	(_this#1) addMagazine (_this#3#1) ;
	(_this#1) addWeapon (_this#3#0) ;
}, [_sg_mk1,_sg_mk1Mags]];

The argument #2 (I count "Mk-I" as #0) [_sg_mk1,_sg_mk1Mags] is the arguments thrown into the addAction script as _this#3 (aka _this select 3) and can be used in the script now.

If you want to change weapons and magazines, you only need to change the arguments.

Share this post


Link to post
Share on other sites
4 minutes ago, POLPOX said:

addAction needs proper code to execute properly and you need to use addMagazine and addWeapon to give someone weapon and magazine.

Your code thrown to addAction is just a className, and className does nothing alone and the engine understands your code like this:


srifle_DMR_03_F

The engine thinks the srifle_DMR_03_F is a variable but it's defined nowhere and that's why it causes the error.

 

Remember the syntax of the addAction? You can achive the goal with the code like this:


_crate = sg_classes;

_crate addAction ["MK-I", {
	(_this#1) addMagazine (_this#3#1) ;
	(_this#1) addWeapon (_this#3#0) ;
}, [_sg_mk1,_sg_mk1Mags]];

The argument #2 (I count "Mk-I" as #0) [_sg_mk1,_sg_mk1Mags] is the arguments thrown into the addAction script as _this#3 (aka _this select 3) and can be used in the script now.

If you want to change weapons and magazines, you only need to change the arguments.

Thanks a lot! Works perfectly, I am going to have to adjust to the way this works. 

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

×