Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
custom:javascript [2018/12/05 01:56] – [output] digital man | custom:javascript [2019/02/21 03:50] – [Output] Clarify that only console.putmsg() will expand extra attribute (e.g. Wildcat, PCBoard, Renegade) codes digital man |
---|
The Synchronet JavaScript object model includes a global method: ''load()'' (a closely-related ''require()'' method was added in v3.17). | The Synchronet JavaScript object model includes a global method: ''load()'' (a closely-related ''require()'' method was added in v3.17). |
| |
The ''load'' method is used to compile and execute an external script from within a //parent// script. It is most often used to load numeric constants and object definitions from files in the ''[[dir:exec]]/load'' directory as these definitions (e.g. ''sbbsdefs.js'') and object libraries (e.g. ''graphic.js'') enable code re-use and sharing among modules, saving us JS programmers and lot of typing and redundancy. | The ''load'' method is used to compile and execute an external script from within a //parent// script. It is most often used to load numeric constants and object definitions from files in the ''[[dir:exec]]/[[dir:load]]'' directory as these definitions (e.g. ''sbbsdefs.js'') and object libraries (e.g. ''graphic.js'') enable code re-use and sharing among modules, saving us JS programmers and lot of typing and redundancy. |
| |
There are 3 primary ways to use the ''load'' method: | There are 3 primary ways to use the ''load'' method: |
var queue = load(true, 'myscript.js', 1, 2, 3); | var queue = load(true, 'myscript.js', 1, 2, 3); |
var value = queue.read(1000); | var value = queue.read(1000); |
print(value); | writeln(value); |
</code> | </code> |
| |
lib.do_thing(); | lib.do_thing(); |
if(lib.status_good == true) | if(lib.status_good == true) |
print('good'); | writeln('good'); |
else | else |
alert('bad'); | alert('bad'); |
This usage expressly places all items created by the loaded script into the scope of the passed variable (in this case, a newly created empty //Object//, just for this purpose). This means there should be no naming conflicts between the parent script and the loaded script (e.g. they may have methods or variables defined with the **same name** and there will be [[https://www.youtube.com/watch?v=2CifYWxJXaI|no confrict]]). | This usage expressly places all items created by the loaded script into the scope of the passed variable (in this case, a newly created empty //Object//, just for this purpose). This means there should be no naming conflicts between the parent script and the loaded script (e.g. they may have methods or variables defined with the **same name** and there will be [[https://www.youtube.com/watch?v=2CifYWxJXaI|no confrict]]). |
| |
==== output ==== | ==== Output ==== |
There are many different text output methods supported by the Synchronet JavaScript Object Model and knowing which method (function) to use in what situation can be confusing. The following table should help: | There are many different text output methods supported by the Synchronet JavaScript Object Model and knowing which method (function) to use in what situation can be confusing. The following table should help: |
| |
^ Method ^ BBS((Terminal Server)) ^ JSexec ^ Prints newline ^ Expands/Decodes ^ Multiple Values((as function arguments)) ^ Notes ^ | ^ Method ^ BBS((Terminal Server)) ^ JSexec ^ Prints newline ^ Expands/Decodes ^ Multiple Values((as function arguments)) ^ Notes ^ |
| ''write()'' | Yes | Yes | No | Telnet-IAC, Ctrl-A | Yes | If user not online, same as ''log(LOG_INFO, ...)'' | | | ''write()'' | Yes | Yes | No | Telnet-IAC, [[custom:ctrl-a_codes|Ctrl-A]] | Yes | If user not online, same as ''log(LOG_INFO, ...)'' | |
| ''write_raw()'' | Yes | No | No | Telnet-IAC | Yes | Value may contain NULs, no charset translation | | | ''write_raw()'' | Yes | No | No | Telnet-IAC | Yes | Value may contain NULs, no charset translation | |
| ''writeln()'' | Yes | Yes | Yes | Telnet-IAC, Ctrl-A | Yes | aka ''print()'' | | | ''writeln()'' | Yes | Yes | Yes | Telnet-IAC, Ctrl-A | Yes | aka ''print()'' | |
| ''console.write()'' | Yes | No | No | Telnet-IAC | Yes | | | | ''console.write()'' | Yes | No | No | Telnet-IAC | Yes | | |
| ''console.writeln()'' | Yes | No | Yes | Telnet-IAC | Yes | | | | ''console.writeln()'' | Yes | No | Yes | Telnet-IAC | Yes | | |
| ''console.putmsg()'' | Yes | No | No | Telnet-IAC, Ctrl-A, @-Codes | No | | | | ''console.putmsg()'' | Yes | No | No | Telnet-IAC, Ctrl-A, [[custom:atcodes|@-Codes]], [[custom:colors|Extra Attributes]] | No | Typically used for displaying text/menu files | |
| ''console.center()'' | Yes | No | Yes | Telnet-IAC, Ctrl-A | No | Text centered on screen | | | ''console.center()'' | Yes | No | Yes | Telnet-IAC, Ctrl-A | No | Text centered on screen | |
| ''console.mnemonics()'' | Yes | No | No | Telnet-IAC, Ctrl-A, @-Codes, ~ | No | Hotkey highlights | | | ''console.mnemonics()'' | Yes | No | No | Telnet-IAC, Ctrl-A, @-Codes, ~ | No | Hotkey highlights | |
===== See Also ===== | ===== See Also ===== |
* [[http://synchro.net/docs/jsobjs.html|Synchronet JavaScript Object Model]] | * [[http://synchro.net/docs/jsobjs.html|Synchronet JavaScript Object Model]] |
* [[:util:jsexec]] | * [[http://nix.synchro.net/jsobjs.html|Synchronet JavaScript Object Model (preliminary for v3.17a)]] |
* [[:util:baja]] | * [[:util:JSexec]] |
| * [[:util:Baja]] |
| * [[:custom:javascript:lib:|JavaScript Libraries]] |
* [[:custom:index|Customization]] | * [[:custom:index|Customization]] |
| |
{{tag>javascript}} | {{tag>javascript}} |
| |