Vice City: Multiplayer

Server Development => Scripting and Server Management => Client Scripting => Topic started by: Sebastian on March 15th, 2021, 01:17 AM

Title: About compiled scripts
Post by: Sebastian on March 15th, 2021, 01:17 AM
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 Stormeus
Added 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:
(click to show/hide)
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:
Code: [Select]
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.
(click to show/hide)
2. One BIG main file - merge all scriptfiles into one

Doing 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:

Code: [Select]
const wayLoadScripts = 0;
function include2( path )
{
          if( wayLoadScripts == 0 ) return 0;
          else include( path );
}

@DizzasTeR 's worthy mention:
(https://imgur.com/so228in.png)

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:
Code: [Select]
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.