Jump to content
Sign in to follow this  
ben_sherman

[Issue] Error Local variable in global space

Recommended Posts

Hello!

I've ran in to a issue here which is causing lagg on my mission, anyhow I get this error which I have clearly no clue how to fix any ideas? btw this is all I get in the logs, before I had it in my ini.sqf file but it happens when one of my scripts is executed. Everything works correct in the script besides that once it gets executed it causes massive lag and in order to loose it you have to reconnect and go in again, like that's not a pain in the ass to do that each 2 minutes?

Haha enough said, any ideas what it could be?

Error in expression <>
 Error position: <>
 Error Local variable in global space

Script: (using iniDB)

while {true} do 
{	
sleep 120;

if(playerSide == west) then
{
	_saveWeapon = ["Data", getPlayerUID player, "WeaponsWest", weapons player] call iniDB_write;
	_saveMagazine = ["Data", getPlayerUID player, "MagazinesWest", magazines player] call iniDB_write;
	publicVariableServer '_saveWeapon';
	publicVariableServer '_saveMagazine';
};

player sideChat "DATA SAVED! ";
};	

Edited by Ben_Sherman

Share this post


Link to post
Share on other sites

hi

you'r using publicVariableServer to send local variable over the network. i think the command wants only global variables.

so change _saveWeapon to: saveWeapon . then it's a global variable.

Share this post


Link to post
Share on other sites
hi

you'r using publicVariableServer to send local variable over the network. i think the command wants only global variables.

so change _saveWeapon to: saveWeapon . then it's a global variable.

I see, I got one other question, how is it possible to make the this script server side and not client side as it want to store the data on the clients PC and not on the server local machine...?

Share this post


Link to post
Share on other sites
I see, I got one other question, how is it possible to make the this script server side and not client side as it want to store the data on the clients PC and not on the server local machine...?

i guess you want to make it server side so that the saved data cannot be edited (player can't cheat). But if you are in fact saving it to client side then there's no point making the script server side. so to make it non hackable you should have both the script running in server and as well the database in server and send the publicvariable to the other way around (maybe you don't need public variable if it's all in server).

(when player logs in read the DB in server , equip the player and when game progresses save player's weapons in server script again to the DB)

Share this post


Link to post
Share on other sites
i guess you want to make it server side so that the saved data cannot be edited (player can't cheat). But if you are in fact saving it to client side then there's no point making the script server side. so to make it non hackable you should have both the script running in server and as well the database in server and send the publicvariable to the other way around (maybe you don't need public variable if it's all in server).

(when player logs in read the DB in server , equip the player and when game progresses save player's weapons in server script again to the DB)

I see, well thats not really what happening, when it stores the data it never save the other players besides mine since I'm hosting it, it's the same if I turn it on dedicated. The problem is the server thinks it's client side and not server side, how can I make it execut it server side? Like what the server thinks it have to do is to save it on the players PC and not on the server aka my PC atm, and since those who join my server well for now my friend he must have @inidb on his PC in order to store the data and when it does it stores the data on his PC and not on the server. Thats the issue I'm having right now.

EDIT: The lagg problem is solved which was the point of the topic, but if you could help me out with the script executing it server side would be great, thanks for all help!

Edited by Ben_Sherman

Share this post


Link to post
Share on other sites

the http://community.bistudio.com/wiki/isServer command is what you need.

like this:


// code below this line will get executed only in server
if (!isServer) exitWith {}; // clients exit the script in here


// Load player weapons here
// & Save in here to database file located in the server

while {true} do 
{    
   sleep 120;

   if(playerSide == west) then
   {
       _saveWeapon = ["Data", getPlayerUID player, "WeaponsWest", weapons player] call iniDB_write;
       _saveMagazine = ["Data", getPlayerUID player, "MagazinesWest", magazines player] call iniDB_write;
   };

   player sideChat "DATA SAVED! ";
};  

Share this post


Link to post
Share on other sites

Working like a charm for me but it's not executing the script for other players besides me as I'm the host. Tried it on dedicated same there. So it's never getting executed and saving other players data.

Share this post


Link to post
Share on other sites
Working like a charm for me but it's not executing the script for other players besides me as I'm the host. Tried it on dedicated same there. So it's never getting executed and saving other players data.

yes only server is supposed to save the data.

and to save all the players you just need have handle to the other player units. the player variable is only used in client scripts. so you need to find other way to save all the players in server.

you could use initPlayerServer.sqf (http://community.bistudio.com/wiki/Event_Scripts) for example to get the players joining the server. store the players in array and you can handle all the players gear with script in the server.

Share this post


Link to post
Share on other sites
yes only server is supposed to save the data.

and to save all the players you just need have handle to the other player units. the player variable is only used in client scripts. so you need to find other way to save all the players in server.

you could use initPlayerServer.sqf (http://community.bistudio.com/wiki/Event_Scripts) for example to get the players joining the server. store the players in array and you can handle all the players gear with script in the server.

Well isn't that script only for ArmA III?

Anyhow the thing that annys me as hell is this here that the rest of the players gets

Error in expression <erUID player, "WeaponsWest", weapons player] call iniDB_write;
["Data", getPlayerUID p>
 Error position: <iniDB_write;
["Data", getPlayerUID p>
 Error Undefined variable in expression: inidb_write
File mpmissions__CUR_MP.cherarusScriptssaveData.sqf, line 5

Like it's so annying that I just wanna kill my PC or something it's driving me nuts. I've even checked an other catched server using kinda same system we're both are executing the scripts the exact same ways and his is working perfect. Thats what bugging me :S

Share this post


Link to post
Share on other sites
Well isn't that script only for ArmA III?

oh yes you'r right. but the point is you need to get the players in the server scripts. try using initJIPcompatible.sqf for the server.

Anyhow the thing that annys me as hell is this here that the rest of the players gets

Error in expression <erUID player, "WeaponsWest", weapons player] call iniDB_write;
["Data", getPlayerUID p>
 Error position: <iniDB_write;
["Data", getPlayerUID p>
 Error Undefined variable in expression: inidb_write
File mpmissions__CUR_MP.cherarusScriptssaveData.sqf, line 5

Like it's so annying that I just wanna kill my PC or something it's driving me nuts. I've even checked an other catched server using kinda same system we're both are executing the scripts the exact same ways and his is working perfect. Thats what bugging me :S

inidb_write needs to be defined. i guess client is running the save script only server should run..... so simply don't run the script for client. use the isServer command in if statement to determine which scripts should be run on server only and which on client...

hope that helps...

Share this post


Link to post
Share on other sites

I got most of the examples out from google some where as I googled for a saving system using iniDB. Re-wrote alot of it, and cleaned it up to make it look better. From my point of view I cant figure it out as if the client is not executing the script it wont save their data but if it executes it server side then it doesn't know what data to save or am I incorrect? if I use "if (!isServer) exitWith {};" then the script never gets executed for players besides me as I'm hosting the server. I'm willing to pay if someone gets it to work thats how far It's gone right now.

In my ini.sqf

if(isServer) then 
{
_initServer = execVM "init\InitServer.sqf";
[] execVM "loadclient.sqf";
[] execVM "saveVars.sqf";
};
if(isServer) then
{
call compile preProcessFile "\iniDB\init.sqf";
};
if(!isDedicated) then
{
_initClient = execVM "init\InitClient.sqf"; //Executes the load data
execVM "Scripts\saveToServer.sqf"; //Some functions not in use right now as I never figure it out.
execVM "Scripts\saveLoop.sqf"; //Saving the data which is the one I have problems with.
execVM "Scripts\loadStats.sqf"; //Using functions to spawn wepons and after the data is loaded to the player.
};

loadData.sqf (I've tried without if (local server) statement as well gives the same issues) call broadcast is like calling it to the server, tried with and without same issue

sleep 5;
titletext["Stat Save\nConnecting to Database", "PLAIN DOWN"];
sleep 2;
titletext["Stat Save\nLoading Stats (0%)", "PLAIN DOWN"];
sleep 2;
titletext["Stat Save\nLoading Stats (24%)", "PLAIN DOWN"];
//=========================================================ALL DATA=========================================================
(format ['if (local server) then {moneyAccount = ["Data", getPlayerUID player, "moneyAccount", "NUMBER"] call iniDB_read;};']) call broadcast;
publicVariableServer 'moneyAccount';
if(playerSide == west) then
{
sleep 1;
titletext["Stat Save\nLoading Stats (35%)", "PLAIN DOWN"];
//=========================================================COP DATA=========================================================
(format ['if (local server) then {WeaponsPlayerWest = ["Data", getPlayerUID player, "WeaponsPlayerWest", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {MagazinesPlayerWest = ["Data", getPlayerUID player, "MagazinesPlayerWest", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {LicensesWest = ["Data", getPlayerUID player, "LicensesWest", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {InventoryWest = ["Data", getPlayerUID player, "InventoryWest", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedVehCop = ["Data", getPlayerUID player, "savedVehCop", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedAirCop = ["Data", getPlayerUID player, "savedAirCop", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedBoatCop = ["Data", getPlayerUID player, "savedBoatCop", "ARRAY"] call iniDB_read;};']) call broadcast;
};
if(playerSide == civilian) then
{
sleep 2;
titletext["Stat Save\nLoading Stats (52%)", "PLAIN DOWN"];
//=========================================================CIV DATA=========================================================
(format ['if (local server) then {WeaponsPlayerCiv = ["Data", getPlayerUID player, "WeaponsPlayerCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {MagazinesPlayerCiv = ["Data", getPlayerUID player, "MagazinesPlayerCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {LicensesCiv = ["Data", getPlayerUID player, "LicensesCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {InventoryCiv = ["Data", getPlayerUID player, "InventoryCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedVehCiv = ["Data", getPlayerUID player, "savedVehCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedAirCiv = ["Data", getPlayerUID player, "savedAirCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedBoatCiv = ["Data", getPlayerUID player, "savedBoatCiv", "ARRAY"] call iniDB_read;};']) call broadcast;
};
if(playerSide == resistance) then
{
sleep 2;
titletext["Stat Save\nLoading Stats (63%)", "PLAIN DOWN"];
//=========================================================RES DATA=========================================================
(format ['if (local server) then {WeaponsPlayerRes = ["Data", getPlayerUID player, "WeaponsPlayerRes", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {MagazinesPlayerRes = ["Data", getPlayerUID player, "MagazinesPlayerRes", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {LicensesRes = ["Data", getPlayerUID player, "LicensesRes", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {InventoryRes = ["Data", getPlayerUID player, "InventoryRes", "ARRAY"] call iniDB_read;};']) call broadcast;
(format ['if (local server) then {savedVehRes = ["Data", getPlayerUID player, "savedVehRes", "ARRAY"] call iniDB_read;};']) call broadcast;
};
sleep 2;
titletext["Stat Save\nLoading Stats (71%)", "PLAIN DOWN"];
//=========================================================ALL DATA=========================================================
if(isNil "_moneyAccount") then { } else {[getPlayerUID player, "moneyAccount", moneyAccount] spawn loadFromDBClient;};
if(playerSide == west) then
{
sleep 1;
titletext["Stat Save\nLoading Stats (73%)", "PLAIN DOWN"];
//=========================================================COP DATA=========================================================
if(isNil "WeaponsPlayerWest") then { } else  {[getPlayerUID player, "WeaponsPlayerWest", WeaponsPlayerWest] spawn loadFromDBClient;};
if(isNil "MagazinesPlayerWest") then { } else  {[getPlayerUID player, "MagazinesPlayerWest", MagazinesPlayerWest] spawn loadFromDBClient;};
if(isNil "LicensesWest") then { } else  {[getPlayerUID player, "LicensesWest", LicensesWest] spawn loadFromDBClient;};
if(isNil "InventoryWest") then { } else  {[getPlayerUID player, "InventoryWest", InventoryWest] spawn loadFromDBClient;};
if(isNil "savedVehCop") then { } else  {[getPlayerUID player, "savedVehCop", savedVehCop] spawn loadFromDBClient;};
if(isNil "savedAirCop") then { } else  {[getPlayerUID player, "savedAirCop", savedAirCop] spawn loadFromDBClient;};
if(isNil "savedBoatCop") then { } else  {[getPlayerUID player, "savedBoatCop", savedBoatCop] spawn loadFromDBClient;};
};
if(playerSide == civilian) then
{
sleep 2;
titletext["Stat Save\nLoading Stats (81%)", "PLAIN DOWN"];
//=========================================================CIV DATA=========================================================
if(isNil "WeaponsPlayerCiv") then { } else  {[getPlayerUID player, "WeaponsPlayerCiv", WeaponsPlayerCiv] spawn loadFromDBClient;};
if(isNil "MagazinesPlayerCiv") then { } else  {[getPlayerUID player, "MagazinesPlayerCiv", MagazinesPlayerCiv] spawn loadFromDBClient;};
if(isNil "LicensesCiv") then { } else  {[getPlayerUID player, "LicensesCiv", LicensesCiv] spawn loadFromDBClient;};
if(isNil "InventoryCiv") then { } else  {[getPlayerUID player, "InventoryCiv", InventoryCiv] spawn loadFromDBClient;};
if(isNil "savedVehCiv") then { } else  {[getPlayerUID player, "savedVehCiv", savedVehCiv] spawn loadFromDBClient;};
if(isNil "savedAirCiv") then { } else  {[getPlayerUID player, "savedAirCiv", savedAirCiv] spawn loadFromDBClient;};
if(isNil "savedBoatCiv") then { } else  {[getPlayerUID player, "savedBoatCiv", savedBoatCiv] spawn loadFromDBClient;};
};
if(playerSide == resistance) then
{
sleep 2;
titletext["Stat Save\nLoading Stats (92%)", "PLAIN DOWN"];
//=========================================================RES DATA=========================================================
if(isNil "WeaponsPlayerRes") then { } else  {[getPlayerUID player, "WeaponsPlayerRes", WeaponsPlayerRes] spawn loadFromDBClient;};
if(isNil "MagazinesPlayerRes") then { } else  {[getPlayerUID player, "MagazinesPlayerRes", MagazinesPlayerRes] spawn loadFromDBClient;};
if(isNil "LicensesRes") then { } else  {[getPlayerUID player, "LicensesRes", LicensesRes] spawn loadFromDBClient;};
if(isNil "InventoryRes") then { } else  {[getPlayerUID player, "InventoryRes", InventoryRes] spawn loadFromDBClient;};
if(isNil "savedVehRes") then { } else  {[getPlayerUID player, "savedVehRes", savedVehRes] spawn loadFromDBClient;};
};
sleep 2;
titletext["Stat Save\nLoading Stats (100%)", "PLAIN DOWN"];
sleep 1;
titletext["Welcome\nEnjoy your stay!", "PLAIN DOWN"];

saveLoop.sqf (Same issue here tried with same statement from above gives the same issue doesn't matter if it's iniDB_write or iniDB_load) call broadcast is like calling it to the server, tried with and without same issue

while {true} do
{
sleep 120;
(format ['["Data", getPlayerUID player, "moneyAccount", Kontostand] call iniDB_write;']) call broadcast;

_pistol = primaryWeapon player;
if(isNil "_pistol") then {_pistol = "";};
_rifle = secondaryWeapon player;
if(isNil "_rifle") then {_rifle = "";};
if(playerSide == west) then
{
	(format ['["Data", getPlayerUID player, "WeaponsPlayerWest", (weapons player) + [_pistol] + [_rifle]] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "MagazinesPlayerWest", magazines player] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "LicensesWest", INV_LizenzOwner] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "InventoryWest", INV_InventarArray] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedVehCop", INV_SavedVehCop] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedAirCop", INV_SavedAirCop] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedBoatCop", INV_SavedBoatCop] call iniDB_write;']) call broadcast;
};
if(playerSide == resistance) then
{
	(format ['["Data", getPlayerUID player, "WeaponsPlayerRes", (weapons player) + [_pistol] + [_rifle]] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "MagazinesPlayerRes", magazines player] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "LicensesRes", INV_LizenzOwner] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "InventoryRes", INV_InventarArray] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedVehRes", INV_SavedVehRes] call iniDB_write;']) call broadcast;
};
if(playerSide == civilian) then
{
	(format ['["Data", getPlayerUID player, "WeaponsPlayerCiv", (weapons player) + [_pistol] + [_rifle]] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "MagazinesPlayerCiv", magazines player] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "LicensesCiv", INV_LizenzOwner] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "InventoryCiv", INV_InventarArray] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedVehCiv", INV_SavedVehCiv] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedAirCiv", INV_SavedAirCiv] call iniDB_write;']) call broadcast;
	(format ['["Data", getPlayerUID player, "savedBoatCiv", INV_SavedBoatCiv] call iniDB_write;']) call broadcast;
};

player sideChat " DATA SAVED! ";
};

loadStats.sqf (Working like a charm, has some few functions which is not useful as I never figured them out)

_loadFromDBClient =
"
_array = _this;
_uid = _array select 0;
if((getPlayerUID player) != _uid) exitWith {};
_varName = _array select 1;
_varValue = _array select 2;
if(isNil '_varValue') exitWith {};
if(_varName == 'moneyAccount') then {Kontostand = _varValue;};

if(playerSide == west) then
{
	if(_varName == 'WeaponsPlayerWest') then {{player addWeapon _x} forEach _varValue;};	
	if(_varName == 'MagazinesPlayerWest') then {{player addMagazine _x} forEach _varValue;};	
	if(_varName == 'LicensesWest') then {INV_LizenzOwner = _varValue;};
	if(_varName == 'InventoryWest') then {INV_InventarArray = _varValue;};
	if(_varName == 'savedVehCop') then {INV_SavedVehCop = _varValue;};
	if(_varName == 'savedAirCop') then {INV_SavedAirCop = _varValue;};
	if(_varName == 'savedBoatCop') then {INV_SavedBoatCop = _varValue;};
};
if(playerSide == civilian) then
{
	if(_varName == 'WeaponsPlayerCiv') then {{player addWeapon _x} forEach _varValue;};	
	if(_varName == 'MagazinesPlayerCiv') then {{player addMagazine _x} forEach _varValue;};	
	if(_varName == 'LicensesCiv') then {INV_LizenzOwner = _varValue;};
	if(_varName == 'InventoryCiv') then {INV_InventarArray = _varValue;};
	if(_varName == 'savedVehCiv') then {INV_SavedVehCiv = _varValue;};
	if(_varName == 'savedAirCiv') then {INV_SavedAirCiv = _varValue;};
	if(_varName == 'savedBoatCiv') then {INV_SavedBoatCiv = _varValue;};
};
if(playerSide == resistance) then
{
	if(_varName == 'WeaponsPlayerRes') then {{player addWeapon _x} forEach _varValue;};	
	if(_varName == 'MagazinesPlayerRes') then {{player addMagazine _x} forEach _varValue;};	
	if(_varName == 'LicensesRes') then {INV_LizenzOwner = _varValue;};
	if(_varName == 'InventoryRes') then {INV_InventarArray = _varValue;};
	if(_varName == 'savedVehRes') then {INV_SavedVehRes = _varValue;};
};
";

loadFromDBClient = compile _loadFromDBClient;

_sendToServer =
"
accountToServerLoad = _this;
publicVariableServer 'accountToServerLoad';
";

sendToServer = compile _sendToServer;

"accountToClient" addPublicVariableEventHandler 
{
(_this select 1) spawn loadFromDBClient;
};

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  

×