SpaydCBR 11 Posted April 4, 2016 Please, for the love of all that is holy, somebody help with this. I've been racking my brain for days trying to figure this out. Basically I have a bit of code that works perfectly in one mission, but not in another, even though it was copy and pasted from the one that worked! :391: This is what I have. I have 2 groups of infantry squads, and 2 pairs of hunters. I want to assign each pair of hunters to one group, so that only members of that group can spawn at or drive that pair of hunters. Each pair of hunters is synced to a logic module, and both of those logic modules (one for each pair of hunters) are synced to one main logic module that has the following in it's init: [this, west] remoteExec ["CBR_fnc_assignVehicle",2] In CBR_fnc_assignVehicle I have the following, and as far as I can tell, it works fine but maybe the problem is here somewhere: //CBR_fnc_assignVehicle params ["_logic","_side"]; _logics = synchronizedObjects _logic; //Get all groups for side _groups = []; { if (side _x isEqualTo _side) then { _groups pushBack _x; } } forEach allGroups; //array for tracking in the debugger watch vehs = []; //Assign each group to a group of vehicles for "_i" from 0 to (count _groups) - 1 do { { if (typeOf _x isKindOf "AllVehicles") then { //set up respawn position _displayName = getText(configFile >> "CfgVehicles" >> typeOf _x >> "displayName"); _group = _groups select _i; [_group, _x, format["%1 - %2", _displayName, _group]] call BIS_fnc_addRespawnPosition; //save vehicle group in missionNamespace _name = format ["%1_grp", _x call BIS_fnc_objectVar]; //shouldn't objectVar create a unique variable name that always stays with the vehicle? missionNamespace setVariable [_name, _group]; publicVariable _name; vehs pushBack _name; //just for debugging, and returns a valid list of variable names //set up vehicle respawn [_x,5,0,-1, { params ["_newVeh", "_oldVeh"]; //attach marker to new vehicle _newVeh remoteExec ["CBR_fnc_marker", 0, true]; } ,0,2,1,true,true,0,false] call BIS_fnc_moduleRespawnVehicle; }; } forEach synchronizedObjects (_logics select _i); }; As far as I can tell, there's nothing wrong with this part. Now I also have some code in onPlayerRespawn.sqf //Start Arsenal on spawn ["Open",[nil, AmmoBox, player]] call BIS_fnc_Arsenal; //run crewCheck [] spawn CBR_fnc_crewCheck; So everytime the respawns I want him to run my crewcheck function, which I think is where I'm having the trouble //CBR_fnc_crewCheck //called from onPlayerRespawn //another array for debugging crewCheckVehs = []; while {alive player} do { //Check if player is the driver of a vehicle waitUntil {sleep 0.5; vehicle player != player && driver vehicle player == player}; //Eject player if not helicopter pilot if (vehicle player isKindOf "Helicopter") then { if (typeOf player != "B_Helipilot_F" && typeOf player != "O_Helipilot_F") then { player action ["GetOut", vehicle player]; waitUntil {sleep 0.5; vehicle player == player}; hint "You are not a helicopter pilot"; }; }; //Eject driver from car if wrong group if (vehicle player isKindOf "Car") then { //should be same one as created from the objectVar call in assignVehicle, but it's something else //also displaying in the form "B Alpha1-1:1 (SpaydCBR)(bis_o2_xxxx)" where bis_o2_xxxx is not in the vehs array ​ //should be in the form "bis_o2_xxxx" . Without the player info in the beginning and be in the vehs array _name = format ["%1_grp", vehicleVarName vehicle player]; crewCheckVehs pushBack _name; //says "_grp". WHY??? _group = missionNamespace getVariable [_name, grpNull]; //so this returns grpNull if (group player != _group) then { player action ["GetOut", vehicle player]; //vehicle player is returning waitUntil {sleep 0.5; vehicle player == player}; hint format ["Only members of %1 are allowed to drive this vehicle", _group]; }; }; }; I see where it's going wrong, but I don't know why? As I said, this same exact code works perfectly fine in my test mission, but not the main mission that I copied it to. I thought variable names generated by BIS_fnc_objectVar stay with the vehicle always, but it looks like it's changing (again only in the main mission. Works fine in my test mission). The only thing I can think of is that it's running these scripts at a different order than in the other mission, but it really shouldn't. Any ideas? Share this post Link to post Share on other sites
barbolani 198 Posted April 4, 2016 Honselty I haven't read deep your code, but, what .rpt drops? Share this post Link to post Share on other sites
Bnae 1431 Posted April 4, 2016 https://community.bistudio.com/wiki/getVariable Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 4, 2016 @barbolani I'm not sure. I don't use the .rpt I don't even know where it is haha. I just use the debug console :) @Bnae I'm not sure what it is I'm looking for in that link. I think I'm using getVariable fine. I think the problem is 'vehicleVarName vehicle player' is returning a different name than was set by 'BIS_fnc_objectVar', and again, it's working fine in my test mission :( Share this post Link to post Share on other sites
barbolani 198 Posted April 4, 2016 Oh well then, seeing you are getting deep in the scripting world let me tell you .rpt IS A MUST!!! Will change your life, for sure ;) Check it and you will see if something weird is happening. Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 4, 2016 how do I check it? I tried looking for it before. Never found it and soon just gave up haha Share this post Link to post Share on other sites
sarogahtyp 1105 Posted April 4, 2016 how do I check it? I tried looking for it before. Never found it and soon just gave up haha psst ... google told me its there ... but ... dont tell anyone ... bro ... %userprofile%\AppData\Local\Arma 3 just write that in the adress line of ur file browser ... but ... psst bro ... psst Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 5, 2016 I just checked the .rpt and found nothing useful :( Share this post Link to post Share on other sites
mrcurry 470 Posted April 5, 2016 Now I'm not at my desktop so I can't check this but are you sure BIS_fnc_objectVar sets the vehicleVarname?On top of my head I'd say try replacing:_name = format ["%1_grp", vehicleVarName vehicle player];with:_name = format ["%1_grp", player call BIS_fnc_objectVar];If that doesn't work shoot me a PM and I'll take a closer look tonight.Edit: You say it works fine in test mission? Please clarify, do you mean a different environment (server/client etc.) or a mission running just these scripts?Edit 2: Should be _name = format ["%1_grp", vehicle player call BIS_fnc_objectVar]; Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 5, 2016 From the Wiki, BIS_fnc_objectVar: "Return an unique object variable. The variable is preserved after unit respawn." By test mission I simply mean that while I am making a mission, I usually have 1 or 2 other missions where I test individual features before copying them into my main mission. These other test missions are under the same environment, or at least I assume so. Right now the problem is from _name = format["%1_grp", vehicleVarName vehicle player]; That statement is simply returning nothing, whereas in my test mission, it returns the correct name, which is the one set by the objectVar function call earlier. What I've been doing now is I've started a new clean mission, and one by one I'm copying features into it until I get the same problem and hopefully that'll give me a clue as to what's causing it. I'm at work right now, but so far everything is still working fine, including the part that this topic is about, so I'm guessing there's something with my other code that's messing things up. Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 6, 2016 So I grabbed my mission that worked and tested it in a dedicated environment. It's giving me the same wrong result as in the OP. The vehicles have no variable names, even though they did in the non-dedicated environment. So what's going wrong? :( Share this post Link to post Share on other sites
mrcurry 470 Posted April 7, 2016 So I grabbed my mission that worked and tested it in a dedicated environment. It's giving me the same wrong result as in the OP. The vehicles have no variable names, even though they did in the non-dedicated environment. So what's going wrong? :( I just tested the objectVar function and this is what I found: 1. BIS_fnc_objectVar uses setVehicleVarname. The effect of setVehicleVarname is local only to the machine which called BIS_fnc_objectVar (but is executed again when locality is changed.) 2. The variable name is stored in the object's variable space (set/getVariable) is transmitted to all clients but you need to call BIS_fnc_objectVar again to fetch it. Like I said in my previous post switch out: _name = format ["%1_grp", vehicleVarName vehicle player]; with: _name = format ["%1_grp", vehicle player call BIS_fnc_objectVar]; That should do the trick. If not you can upload the mission file and I can take a closer look. 1 Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 7, 2016 Thanks mrcurry :) I'm at work right now, but last night I did some dedicated environment tests. I used system chat to display the variable names of the vehicles at the start of the mission and they did in fact have valid names, but when I got IN them 'vehicleVarName vehicle player' returned an empty string, but ONLY when they're attached to the vehicle respawn module. If I remove the line that adds the vehicle respawn module, then everything seems to work fine. (Maybe not with posted code, the code has been slightly changed). I'll update the OP when I get home, as it can be much shorter now that I've narrowed down the problem. I will try your solution when I get home and let you know what happens. If it doesn't work I will upload the small test mission I'm using to demonstrate this problem. I realize that I could simply give all the vehicles names in the editor and that would probably fix my problem, but I would like to learn what's going on here :) Share this post Link to post Share on other sites
SpaydCBR 11 Posted April 8, 2016 I just tested the objectVar function and this is what I found: 1. BIS_fnc_objectVar uses setVehicleVarname. The effect of setVehicleVarname is local only to the machine which called BIS_fnc_objectVar (but is executed again when locality is changed.) 2. The variable name is stored in the object's variable space (set/getVariable) is transmitted to all clients but you need to call BIS_fnc_objectVar again to fetch it. Like I said in my previous post switch out: _name = format ["%1_grp", vehicleVarName vehicle player]; with: _name = format ["%1_grp", vehicle player call BIS_fnc_objectVar]; That should do the trick. If not you can upload the mission file and I can take a closer look. That worked! Everything seems to be working fine now. Thanks mrcurry! I guess I just assumed that if an object already had a name then BIS_fnc_objectVar and vehicleVarName did essentially the same thing. Share this post Link to post Share on other sites