Everything you need to know about compiled client-side scripts!
It is posible since rel004 2017-05-24 Update (https://forum.vc-mp.org/?topic=4660.0)Quote from: StormeusAdded support for loading precompiled client-side scripts (i.e. .cnut files). These must be compiled on a 32-bit Squirrel instance.
In order to make it work, you have 2 options:[spoiler=1. Multiple scriptfiles]
1. Multiple scriptfiles - you must give up on calling constants/enums from other files except the ones they are used in.You are declaring const MAX_PLAYERS=50; in main.cnut and then later trying to call it from utils.cnut. The constant MAX_PLAYERS won't be recognized, and that's why it will throw the following error:AN ERROR HAS OCCURRED [the index '<constant name>' does not exist]
Also, don't forget to use :: prefix when you call global variables from different scriptfiles.[/spoiler]
[spoiler=2. One BIG main.cnut]
2. One BIG main file - merge all scriptfiles into oneDoing this way, you won't be needed to avoid constants/enums.
But, be aware of dofile/include functions. They will still call the files they are supposed to.
So I suggest you to create your own function, like I did, and just change a constant:const wayLoadScripts = 0;
function include2( path )
{
if( wayLoadScripts == 0 ) return 0;
else include( path );
}
[/spoiler]
@DizzasTeR 's worthy mention:Tools:to compile .nut into compiled .cnut (or whatever format you like)Note:When you use compiled scripts, you may notice the following warnings and error in debuglog.txt:
MSG: <filename> line = (1) column = (1) : error expression expected
Warning in CScriptFunctions::DoFile: (script/<filename>.cnut) expression expected
Warning in CScriptFunctions::DoFile: Attempting bytecode read of file.
Don't worry, it is not a problem. The client just tries to read the file as uncompiled first.
MSG: Scripts initialised.