18.09.2015, 10:28
(
Последний раз редактировалось SkittlesAreFalling; 26.09.2015 в 19:45.
)
Quote:
Is it possible create a global variable to be accessible from another JS files? A kind of global variable accessible from any file
#edit I figured out that I can simply use include function to load some JS file with a global variable xD #another question Can I assign a value to a new attribute of player's object, eg player.test = 1, that when the player disconnect this object will be cleared? I noticed that when you use the function GameModeExit to reload the server, the changes made in source don't have any effect in the server until you close/open it again. It's quite bother... |
Код:
include("js/SomeFunction.js"); // Includes all global variables from the path into the script. SomeFunction();
Код:
var script = require("js/SomeFunction.js"); // Includes all exported variables into the script. script.SomeFunction();
Код:
var SomeFunction = function() { print("This is some function"); } exports = { SomeFunction : SomeFunction }
Use a global variable instead:
var PlayerData = [];
//PlayerConnect
PlayerData[player.id] = {};
PlayerData[player.id].test = 1;
//PlayerDisconnect
PlayerData[player.id] = null; // Or if you want it to free up memory do: delete PlayerData[player.id];