draoth 13 Posted September 7, 2016 Hello everyone! I'm pretty new to scripting in Arma, so i hope someone can help me out.I've created a script that makes a global variable grow when a unit spawns.it worked great in singleplayer but when i tested it in multiplayer, it suddenly threw this error. Undefined variable in expression: participants So now i'm asking myself, what did i do wrong? init.sqf participants = 0; code when unit spawns participants = participants + 1; Share this post Link to post Share on other sites
davidoss 552 Posted September 7, 2016 global variable assigned on some PC are not global for other PC if you need to spreed over the network to other PC you need to public it publicVariable publicVariableServer publicVariableClient or you can store the variable in missionNameSpace and update its value on each +1 setVariable Share this post Link to post Share on other sites
Tajin 349 Posted September 7, 2016 it worked great in singleplayer Unlikely. Unit-inits are executed before the init.sqf so this shouldn't work at all. Is participants supposed to be the number of players? If so, you're better off using: count allPlayers Share this post Link to post Share on other sites
killzone_kid 1331 Posted September 7, 2016 Hello everyone! I'm pretty new to scripting in Arma, so i hope someone can help me out. I've created a script that makes a global variable grow when a unit spawns. it worked great in singleplayer but when i tested it in multiplayer, it suddenly threw this error. Undefined variable in expression: participants So now i'm asking myself, what did i do wrong? init.sqf participants = 0; code when unit spawns participants = participants + 1; You might not realise but exact error message contains a lot of useful information that can help to debug. From what you posted, it should not throw error. Share this post Link to post Share on other sites
draoth 13 Posted September 8, 2016 You might not realise but exact error message contains a lot of useful information that can help to debug. From what you posted, it should not throw error. Good tip! Here's the error. '...tered.altis\players.sqf" participants = |#|participants + 1;' Error Undefined variable in expression: participants File C:\Users\Peter\Documents\Arma 3\Missions\Testmission.altis\players.sqf, line 1 Error undefined variable in expression: participants That's all. Share this post Link to post Share on other sites
killzone_kid 1331 Posted September 8, 2016 put participants = 0; in some preInit script. If you define it in init.sqf and using it before that it will be undefined. Share this post Link to post Share on other sites
Tajin 349 Posted September 8, 2016 or just change your unit-inits to the following instead: participants = (missionNamespace getVariable ["participants",0]) + 1; Share this post Link to post Share on other sites
Moldisocks 1 Posted January 3, 2017 (edited) Hi, i am having the same "undefined variable" issue but slightly different. I am attempting to get the container "object" and the item values from the Put event handler and put it into the jettype and itemplaced variables respectively. this code is placed into the units init Code: this addeventhandler ["put",execVM "checkplaceCSAT.sqf"]; pilotnoCSAT = p4; jettype = this select 2; itemplaced = this select 3; this is the checkplaceCSAT,sqf file code: //checkplaceCSAT.sqf _pilot = pilotnoCSAT; if (jettype == Wipeout AND itemplaced == Chemlight_red) Then {_jet = createVehicle [B_PLANE_CAS_01_F,[24143.426,18891.764,2000],1],_pilot moveInDriver _jet }; if (jettype== Neo AND itemplaced == Chemlight_red) Then {_jet = createVehicle [O_PLANE_CAS_02_F,[24143.426,18891.764,2000],1],_pilot moveInDriver _jet}; if (jettype == BuzzCAS AND itemplaced == Chemlight_red) Then {_jet = createVehicle [I_PLANE_FIGHTER_03_CAS_F,[24143.426,18891.764,2000],1],_pilot moveInDriver _jet}; if (jettype == BuzzAA AND itemplaced == Chemlight_red) Then {_jet = createVehicle [I_PLANE_FIGHTER_04_AA_ F,[24143.426,18891.764,2000],1],_pilot moveInDriver _jet}; error is something like this: file checkplace.sqf line 5 if ( |#| jettype == wipeout AND itemplaced ==che.." Error undefined variable in expression: jettype Now i assume because "jettype" is undefined so are the rest as well. Im not sure why this is because i made a point of making sure that the variables were set globally in the units init, but in the sqf it has sent back that error. sorry for being a nub at scripting, and i appreciate any help i can get thanks. Also i realise there are probably a multitude of mistakes in the code, whether it be syntax errors or just code inefficiency. don't worry about trying to help fix those issues as much, i should be able to work them out on my own, its just that global variable thing that has had me stuck for a while. Edited January 3, 2017 by Moldisocks Share this post Link to post Share on other sites
davidoss 552 Posted January 3, 2017 Try this one: this addeventhandler ["Put",{ params [ ["_unit",objNull,[objNull]], ["_container",objNull,[objNull]], ["_item","",[""]] ]; null = [_unit,_container,_item] execVM "checkplaceCSAT.sqf"; }]; //checkplaceCSAT.sqf params [ ["_unit",objNull,[objNull]], ["_container",objNull,[objNull]], ["_item","",[""]] ]; private _evaluate = (_item == "Chemlight_red"); private _fnc_spawnAircraft = { params ["_pilot","_jetType"]; private _jet = createVehicle [_jetType, [24143.426,18891.764,2000], [], 0, "FLY"]; private _centPos = getPosASL _jet; _centPos set [2, 2000]; _pilot moveInDriver _jet; (vehicle _pilot) setPosASL _centPos; }; switch _container do { case Wipeout: {if (_evaluate) then {[_unit,"B_PLANE_CAS_01_F"] call _fnc_spawnAircraft}}; case Neo: {if (_evaluate) then {[_unit,"O_PLANE_CAS_02_F"] call _fnc_spawnAircraft}}; case BuzzCAS: {if (_evaluate) then {[_unit,"I_PLANE_FIGHTER_03_CAS_F"] call _fnc_spawnAircraft}}; case BuzzAA: {if (_evaluate) then {[_unit,"I_PLANE_FIGHTER_04_AA_F"] call _fnc_spawnAircraft}}; default {}; }; 1 Share this post Link to post Share on other sites
Moldisocks 1 Posted January 3, 2017 thanks for replying. this definitely looks great, but i have decided (once i found out how to make gui's) that i should use a GUI base menu rather than a menu that requires you to place an item in a container, as this is more polished. i feel like a tool now because i was actually going to take this reply down, when i saw that you replied back, i didn't expect someone to reply so quick. sorry for wasting you time, although this did help me alot with understanding how to use the event handlers better. again thanks alot, 10/10 reply Share this post Link to post Share on other sites