Jump to content
zapat

So what makes a variable undefined & how to define it?

Recommended Posts

Thanks deadfast, it fixed the first variable but now it fails on line 75 with the same error about camadm.

Line 75 is

else {
                   _spectateButton ctrlSetText "Spectate";
                   player commandchat format ["No Longer Viewing.", name _target];
                   player cameraEffect ["terminate","back"];
                   camDestroy _camadm;  <---------line 75

---------- Post added at 09:27 ---------- Previous post was at 09:21 ----------

Thanks for your comments Galzohar I can include the whole file for you to look at and tell me if the variable is undefined? I dont know what Im looking for.....

#define playerMenuDialog 55500
#define playerMenuPlayerList 55505
#define playerMenuSpectateButton 55506
#define playerMenuWarnMessage 55509

disableSerialization;

private ["_dialog","_playerListBox","_spectateButton","_switch","_index","_modSelect","_playerData","_target","_check","_spectating","_camadm","_rnum","_warnText","_targetUID","_playerName"];
_uid = getPlayerUID player;
if ((_uid in moderators) OR (_uid in administrators) OR (_uid in serverAdministrators)) then {
_dialog = findDisplay playerMenuDialog;
_playerListBox = _dialog displayCtrl playerMenuPlayerList;
_spectateButton = _dialog displayCtrl playerMenuSpectateButton;
_warnMessage = _dialog displayCtrl playerMenuWarnMessage;

_switch = _this select 0;
_index = lbCurSel _playerListBox;
_playerData = _playerListBox lbData _index;

{
	if (str(_x) == _playerData) then {
		_target = _x;
		_check = 1;
	};
}forEach playableUnits;

if (_check == 0) then {exit;};

switch (_switch) do
{
    case 0: //Spectate
       {
           if (!isNil "_target") then
           {
               _spectating = ctrlText _spectateButton;
               if (_spectating == "Spectate") then {
                   _spectateButton ctrlSetText "Spectating";
                   player commandChat format ["Viewing %1.", name _target];

                   if (!isNil "_camadm") then
                   {
                       camDestroy _camadm;
                   };
                   _camadm = "camera" camCreate ([(position vehicle _target select 0) - 5,(position vehicle _target select 1), (position vehicle _target select 2) + 10]);
                   _camadm cameraEffect ["external", "TOP"];
                   _camadm camSetTarget (vehicle _target);
                   _camadm camCommit 1;

                   _rnum = 0;
                   while {ctrlText _spectateButton == "Spectating"} do {
                       switch (_rnum) do
                       {
                           if (daytime > 19 || daytime < 5) then {camUseNVG true;} else {camUseNVG false;};
                           case 0: {detach _camadm; _camadm attachTo [(vehicle _target), [0,-10,4]]; _camadm setVectorUp [0, 1, 5];};
                           case 1: {detach _camadm; _camadm attachTo [(vehicle _target), [0,10,4]]; _camadm setDir 180; _camadm setVectorUp [0, 1, -5];};
                           case 2: {detach _camadm; _camadm attachTo [(vehicle _target), [0,1,50]]; _camadm setVectorUp [0, 50, 1];};
                           case 3: {detach _camadm; _camadm attachTo [(vehicle _target), [-10,0,2]]; _camadm setDir 90; _camadm setVectorUp [0, 1, 5];};
                           case 4: {detach _camadm; _camadm attachTo [(vehicle _target), [10,0,2]]; _camadm setDir -90; _camadm setVectorUp [0, 1, -5];};
                       };
                       player commandchat "Viewing cam " + str(_rnum) + " on " + str(name vehicle _target);
                       _rnum = _rnum + 1;
                       if (_rnum > 4) then {_rnum = 0;};
                       sleep 5;
                   };
               } else {
                   _spectateButton ctrlSetText "Spectate";
                   player commandchat format ["No Longer Viewing.", name _target];
                   player cameraEffect ["terminate","back"];
                   camDestroy _camadm; 
               };
           };
       };  
	case 1: //Warn
	{
		_warnText = ctrlText _warnMessage;
        _playerName = name player;
		[_target, format["if (name player == ""%2"") then {titleText [""Admin %3: %1"", ""plain""]; titleFadeOut 10;};",_warnText,name _target,_playerName], false] spawn fn_vehicleInit;
        // processInitCommands;
        // clearVehicleInit _target;
	};
    case 2: //Slay
    {
		[_target, format["if (name player == ""%1"") then {player setdamage 1; Endmission ""END1"";failMission ""END1"";forceEnd; deletevehicle player;};",name _target], false] spawn fn_vehicleInit;
		// processInitCommands;
		// clearVehicleInit _target;
    };
    case 3: //Unlock Team Switcher
    {      
		_targetUID = getPlayerUID _target;
        {
		    if(_x select 0 == _targetUID) then
		    {
		    	pvar_teamSwitchList set [_forEachIndex, "REMOVETHISCRAP"];
				pvar_teamSwitchList = pvar_teamSwitchList - ["REMOVETHISCRAP"];
		        publicVariableServer "pvar_teamSwitchList";

                [_target, format["if (name player == ""%1"") then {client_firstSpawn = nil;};",name _target], false] spawn fn_vehicleInit;
		        // processInitCommands;
		        // clearVehicleInit _target;

                [player, format["if isServer then {publicVariable 'pvar_teamSwitchList';};"], false] spawn fn_vehicleInit;
		        // processInitCommands;
		        // clearVehicleInit player;
		    };
		}forEach pvar_teamSwitchList;			
    };
	case 4: //Unlock Team Killer
    {      
		_targetUID = getPlayerUID _target;
        {
		    if(_x select 0 == _targetUID) then
		    {
		    	pvar_teamKillList set [_forEachIndex, "REMOVETHISCRAP"];
				pvar_teamKillList = pvar_teamKillList - ["REMOVETHISCRAP"];
		        publicVariableServer "pvar_teamKillList"; 

                [player, format["if isServer then {publicVariable 'pvar_teamKillList';};"], false] spawn fn_vehicleInit;
		        // processInitCommands;
		        // clearVehicleInit player;       
		    };
		}forEach pvar_teamKillList;       		
    };
       case 5: //Remove All Money
    {      
		_targetUID = getPlayerUID _target;
        {
		    if(getPlayerUID _x == _targetUID) then
		    {
 					_x setVariable["cmoney",0,true];
		    };
		}forEach playableUnits;       		
    };
       case 6: //Remove All Weapons
    {      
		_targetUID = getPlayerUID _target;
        {
		    if(getPlayerUID _x == _targetUID) then
		    {
 					removeAllWeapons _x;
		    };
		}forEach playableUnits;       		
    };
       case 7: //Check Player Gear
    {      
		_targetUID = getPlayerUID _target;
        {
		    if(getPlayerUID _x == _targetUID) then
		    {
 					createGearDialog [_x, "RscDisplayGear"];
		    };
		}forEach playableUnits;        		
    };
};
} else {
 exit;  
};

Share this post


Link to post
Share on other sites

Well, you can just do the same change there. But this suggests there might be a bigger problem. Perhaps post the full script so I can go over it?

Share this post


Link to post
Share on other sites
Well, you can just do the same change there. But this suggests there might be a bigger problem. Perhaps post the full script so I can go over it?

Have posted in the above comment :)

Thanks peeps, really appreciate your help.

Share this post


Link to post
Share on other sites
Have posted in the above comment :)

Thanks peeps, really appreciate your help.

I'm pretty sure the script isn't working correctly. I assume it can be called multiple times?

In that case, you're never going to get rid of the camera. You need to turn _camadm into a global variable (rename it to something like TAG_camadm).

Share this post


Link to post
Share on other sites

Can someone crack this for me please:confused:

more info on mission:

http://www.armaholic.com/page.php?id=20228

#include "globalDefines.hpp"

private ["_reviveInstruction", "_recvArray", "[color="#FF0000"]_recvCmd[/color]", "_unit", "_pidx", "_qridx", "_desiredSpawnLoc", "_playerQID", "_newQueue", "_arrPlayerTeams", "_spawnInstruction", "_spawnQueueUpdate", "_curSpawnTimer", "_cb", "_sQueue", "_info"];

if( (time - lastTime) >= 1 ) then
{
//------------------ handle spawn instructions -----------------------

array _reviveInstruction = [];

//diag_log format[hint typeName _var];
int _pidx=0;
for "_pidx" from 0 to ((count playableUnits) - 1) do
	{
	// process incoming transmission
	_unit = playableUnits select _pidx;
	string [color="#FF0000"]_recvCmd[/color] = "";
	if ( !(isNull _unit) ) then
		{
	     //TODO giving undefined errors variable _recvCmd @  array _recvArray = toArray _recvCmd; Find a work around	
		call compile format["[color="#FF0000"]_recvCmd[/color] = xmit%1;",_unit];
		array _recvArray = toArray [color="#FF0000"]_recvCmd[/color];


		if( count _recvArray > 0 ) then
			{
			DEBUG_LOG format["SRV updateSpawnQueues.sqf : RECV %1 = %2",_unit,_recvArray];
			};

		if( count _recvArray == 2 ) then
			{

			// player command to select a spawn location
			if( (_recvArray select 0) == CMD_PLAYERSPAWNSELECT ) then
				{
				// player wishes to spawn
				int _desiredSpawnLoc = _recvArray select 1;

				if( SRVBASECACHEA(_desiredSpawnLoc,CAPLEVEL) == 100 ) then
					{
					_playerQID = _unit call getPlayerQID;
					DEBUG_LOG format["SRV updateSpawnQueues.sqf : enqueuing %1 with QID %2",playableUnits select _pidx,_playerQID];

					// if player not already in the queue
					if (!(_playerQID in SRVBASECACHEA(_desiredSpawnLoc,SQUEUE))) then
					{
						// remove player from all queues
						int _qridx = 1;
						for [{_qridx = 1},{_qridx < count saas_baselist},{_qridx = _qridx + 1}] do
						{
							if (_playerQID in SRVBASECACHEA(_qridx,SQUEUE)) then
							{
								array _newQueue = SRVBASECACHEA(_qridx,SQUEUE) - [_playerQID];
								SETSRVBASECACHEA(_qridx,SQUEUE,_newQueue);
							};
						};
						// only add to queue, if not 'cancel' button
						if (_desiredSpawnLoc != AAS_CANCEL_RESPAWN_LOCATION) then
						{
							// add player to requested queue (at end)
							array _newQueue = SRVBASECACHEA(_desiredSpawnLoc,SQUEUE) + [_playerQID];
							SETSRVBASECACHEA(_desiredSpawnLoc,SQUEUE,_newQueue);
						};
					};
				};
			};

In the RPT.file

Error in expression <_recvCmd = xmitplayerWest1;>
 Error position: <xmitplayerWest1;>
 Error Undefined variable in expression: xmitplayerwest1
Error in expression <xmit%1;",_unit];

_recvArray = toArray _recvCmd;


if( count _recvArray > 0 ) t>
 Error position: <_recvCmd;


if( count _recvArray > 0 ) t>
 Error Undefined variable in expression: _recvcmd

Edited by Karmichael

Share this post


Link to post
Share on other sites

source:

the variable xmitplayerwest1 does not exist. most likely as there is no player for that slot

workaround:

if (!(isNil "_recvCmd")) then

fix:

proper code design

Share this post


Link to post
Share on other sites
;2492869']source:

the variable xmitplayerwest1 does not exist. most likely as there is no player for that slot

workaround:

if (!(isNil "_recvCmd")) then

fix:

proper code design

Thank you kju.

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

×