mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Some edits to documents
This commit is contained in:
@@ -20,4 +20,5 @@ Original description: A set of engine modifications for the classic game Fallout
|
||||
|
||||
---
|
||||
#### Fallout Engine IDA Database
|
||||
**[Download](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar "Download from Dropbox")** (comments are in Russian)
|
||||
[Download for IDA Pro 6.8](https://www.dropbox.com/s/tm0nyx0lnk4yui0/Fallout_1_and_2_IDA68.rar?dl=1 "Download from Dropbox")
|
||||
| [Download for IDA Pro 7.0](https://www.dropbox.com/s/61srq09pn8grfpu/Fallout_1_and_2_IDA70.rar?dl=1 "Download from Dropbox") (comments are in Russian)
|
||||
|
||||
@@ -11,7 +11,7 @@ When compiling global or hook scripts for sfall 3.4 or below, you _must_ include
|
||||
|
||||
This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions.
|
||||
|
||||
The original unmodified sslc source is over here: [http://www.teamx.ru/site_arc/utils/index.html](http://www.teamx.ru/site_arc/utils/index.html)
|
||||
The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html)
|
||||
|
||||
### Command line options
|
||||
|
||||
@@ -121,7 +121,7 @@ Syntax which requires sfall for compiled scripts to be interpreted is marked by
|
||||
```
|
||||
__NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors.
|
||||
|
||||
- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and A-F are allowed in the number. The number may not have a decimal point.
|
||||
- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point.
|
||||
- new:
|
||||
```
|
||||
a := 0x1000;
|
||||
|
||||
@@ -542,11 +542,13 @@
|
||||
- name: Audio
|
||||
items:
|
||||
- name: eax_available
|
||||
detail: int eax_available
|
||||
detail: int eax_available()
|
||||
opcode: 0x81a3
|
||||
doc: Obsolete since sfall 2.1a. Always returns 0.
|
||||
- name: set_eax_environment
|
||||
detail: void set_eax_environment(int environment)
|
||||
opcode: 0x81a4
|
||||
doc: Obsolete since sfall 2.1a. Has no effect.
|
||||
|
||||
- name: play_sfall_sound
|
||||
detail: int play_sfall_sound(string file, int mode)
|
||||
@@ -631,7 +633,7 @@
|
||||
doc: Arctangent of x. Pass 1 as y (don't ask...).
|
||||
opcode: 0x81f1
|
||||
- name: ceil
|
||||
detail: int ceil(float)
|
||||
detail: int ceil(float x)
|
||||
opcode: 0x8266
|
||||
doc: Round x to the nearest integer that is not less than x.
|
||||
- name: ^
|
||||
@@ -948,7 +950,7 @@
|
||||
- name: nb_create_char
|
||||
detail: int nb_create_char()
|
||||
opcode: 0x81f6
|
||||
doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided."
|
||||
doc: "`nb_*` functions are reserved for the brotherhood tactical training mod, and should be avoided. Not implemented, always returns 0."
|
||||
|
||||
- name: get_proto_data
|
||||
detail: int get_proto_data(int pid, int offset)
|
||||
|
||||
+2
-2
@@ -37,5 +37,5 @@ Pay special attention to the [best practices]({{ site.baseurl }}/best-practices/
|
||||
Next, proceed to discover new functions. They are categorized, use the menu to find the one you need. If you can't, check [uncategorized functions]({{ site.baseurl }}/other/) list and [sfall macros]({{ site.baseurl }}/sfall-funcx-macros/). Also, there's search at the top of the page.
|
||||
|
||||
## Questions and problems
|
||||
* Report bugs and suggest features on [Github](https://github.com/phobos2077/sfall/issues).
|
||||
* Ask questions and discuss on the [forum](https://nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/).
|
||||
* Report bugs and suggest features on [Github](https://github.com/sfall-team/sfall/issues).
|
||||
* Ask questions and discuss on the [forum](https://www.nma-fallout.com/threads/fo2-engine-tweaks-sfall.178390/).
|
||||
|
||||
+37
-23
@@ -16,41 +16,48 @@ The executation speed of scripts is not typically important in an unmodded game,
|
||||
|
||||
## sslc -O option
|
||||
|
||||
The sfall build of sslc supports a -O command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes define.h, whether you use them or not, and to do something about the additional variables that get created by foreach loops.
|
||||
The sfall build of sslc supports a `-O` command line option to perform an optimization pass over the generated code. This isn't a magic make-my-code-go-faster bullet; most of what it does is very limited in scope. It's primary purpose was to strip out the procedures and variables which get automatically pulled into every script that includes **define.h**, whether you use them or not, and to do something about the additional variables that get created by `foreach` loops.
|
||||
|
||||
There are several levels of optimization available:
|
||||
**There are several levels of optimization available:**
|
||||
- `-O1` - Basic, only removes unreferenced globals variables and procedures, code itself remains untouched.
|
||||
- `-O2` - Full, most code optimizations are on, but only those that were tested on complex scripts.
|
||||
- `-O3` - Experimental, provides most efficiency, but tend to break some complex code due to bugs.
|
||||
|
||||
The following optimizations are performed:
|
||||
**The following optimizations are performed:**
|
||||
|
||||
- constant expression folding: if an expression depends only on values which are known at compile time, then the expression is replaced by its result.
|
||||
`a:=2+2;` -> `a:=4;`
|
||||
```
|
||||
a := 2 + 2; -> a := 4;
|
||||
```
|
||||
|
||||
- constant variable initialization: All variables are initialised to some value, ('0', if you don't specify anything else,) so sslc attempts to make use of that fact to remove the first assignment to a variable if the first assignment is a constant expression.
|
||||
```
|
||||
variable a; -> variable a:=4;
|
||||
a:=4; ->
|
||||
variable a; -> variable a := 4;
|
||||
a := 4; ->
|
||||
```
|
||||
|
||||
- constant propagation: checks for values assigned to variables which can be computed at compile time, and replaces relevent references to the symbol by the constant. The original store is not removed by this optimization. Global variables are considered for this optimization only if they are not marked import or export, and are not assigned to anywhere in the script.
|
||||
```
|
||||
a:=4 -> a:=4
|
||||
a := 4; -> a := 4;
|
||||
foo(a); -> foo(4);
|
||||
```
|
||||
|
||||
- dead code removal: Checks for and removes code which cannot be reached, either because it is hidden behind a return or because the argument to an if statement can be computed at compile time.
|
||||
```
|
||||
if 1 then begin -> display_msg("foo");
|
||||
if (True) then begin -> display_msg("foo");
|
||||
display_msg("foo"); ->
|
||||
end else begin ->
|
||||
display_msg("bar"); ->
|
||||
end ->
|
||||
```
|
||||
- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export.
|
||||
|
||||
- unreferenced variable elimination: Checks for variables which are never referenced, and removes them. Also applies to global variables, as long as they are not marked for export.
|
||||
```
|
||||
variable i, j, k; -> variable i;
|
||||
i:=1; -> i:=1;
|
||||
i := 1; -> i := 1;
|
||||
return; -> return;
|
||||
```
|
||||
|
||||
- unreferenced procedure elimination: Checks for any procedures which are never called, and removes them.
|
||||
```
|
||||
procedure foo begin return "foo"; end -> procedure foo begin return "foo"; end
|
||||
@@ -59,31 +66,36 @@ The following optimizations are performed:
|
||||
display_msg(foo); -> end
|
||||
end ->
|
||||
```
|
||||
- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See 'pure' keyword)
|
||||
|
||||
- dead store removal: Removes variable assignments if the result of the variable is unused, and if the expression used to compute the value of the variable is provably free of side effects. (See `pure` keyword)
|
||||
```
|
||||
a:="moo"; -> a:="foo";
|
||||
a:="foo"; -> display_msg(a);
|
||||
a := "moo"; -> a := "foo";
|
||||
a := "foo"; -> display_msg(a);
|
||||
display_msg(a); ->
|
||||
a:="bar"; ->
|
||||
a := "bar"; ->
|
||||
```
|
||||
|
||||
- store combination: Where there are two stores in a row to the same variable, the two expressions are combined.
|
||||
```
|
||||
var1 := var2; -> var1 := var2 + var3;
|
||||
var1 += var3; ->
|
||||
```
|
||||
- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple foreach loops, which generate 2 or 3 hidden variables each.
|
||||
|
||||
- variable combination: Where usage regions of variables do not overlap, combine the variables to provide additional candidates for unreferenced variable elimination. Very useful for scripts containing multiple `foreach` loops, which generate 2 or 3 hidden variables each.
|
||||
```
|
||||
a:="foo"; -> a:="foo";
|
||||
a := "foo"; -> a := "foo";
|
||||
display_msg(a); -> display_msg(a);
|
||||
b:="bar"; -> a:="bar";
|
||||
b := "bar"; -> a := "bar";
|
||||
display_msg(b); -> display_msg(a);
|
||||
```
|
||||
|
||||
- namelist compression: Fallout stores the names of all file scope variables and procedures in a namelist which is saved into the .int. Any of these that are unreferenced can be removed, and the names of global variables can be modified to make them shorter.
|
||||
|
||||
## Writing your own code
|
||||
|
||||
- Don't have global scripts running any more often that you need them to. Not everything needs to be run every single frame.
|
||||
- Never concat constant strings with the '+' operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a +, which results in far more efficient code as the combination is done at lex time.
|
||||
|
||||
- Never concat constant strings with the `+` operator, as it forces the operation to be done at runtime. The compiler can cope with constant strings being placed next to each other without the need for a `+`, which results in far more efficient code as the combination is done at lex time.
|
||||
```
|
||||
#define GLOB_PREFIX "ts__" -> #define GLOB_PREFIX "ts__"
|
||||
|
||||
@@ -91,15 +103,17 @@ The following optimizations are performed:
|
||||
set_sfall_global(GLOB_PREFIX + "foo1", 0); -> set_sfall_global(GLOB_PREFIX "foo1", 0);
|
||||
end -> end
|
||||
```
|
||||
- Avoid function calls in while loops. function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable
|
||||
|
||||
- Avoid function calls in `while` loops. Function calls are expensive in comparison to variable lookups, so it's more efficient to move the function call out of the loop and store the result in a variable.
|
||||
```
|
||||
while i < len_array(array) do begin -> tmp:= len_array(array);
|
||||
while i < len_array(array) do begin -> tmp := len_array(array);
|
||||
... -> while i < tmp do begin
|
||||
end -> ...
|
||||
-> end
|
||||
```
|
||||
- Mark functions with pure or inline where relevent.
|
||||
|
||||
'pure' is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call <procedure>` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code.
|
||||
- Mark functions with `pure` or `inline` where relevent.
|
||||
|
||||
'inline' is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. inlined procedures cannot use the 'return' command, cannot be predefined, and cannot be used as part of an expression. inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code.
|
||||
* `pure` is a hint to the optimizer that a procedure has no side effects. (i.e. there's no way to tell that it's been called aside from its return value.) Pure procedures cannot modify global variables, or call any other procedure that isn't itself pure. Functions marked with pure can only be used in expressions (i.e. you cannot use the `call <procedure>` syntax to call them.) If there are non-pure terms in an expression, it prevents that expression being considered for dead store removal. Where no such optimizations can be performed, or if optimization is disabled, marking a procedure with pure will have no effect on the compiled code.
|
||||
|
||||
* `inline` is an instruction to the compiler to replace calls to the marked procedure with a copy of the procedures code instead of having a seperate call. Inlined procedures cannot use the `return` command, cannot be predefined, and cannot be used as part of an expression. Inlining if a procedure is only going to be called once is always a win, but if there are multiple calls to a procedure you will end up bloating the size of the generated code.
|
||||
|
||||
+46
-36
@@ -15,13 +15,13 @@ This is a modified copy of sslc, that has a few bugfixes from the original, that
|
||||
|
||||
Unlike the original script compiler, this has not been compiled as a dos program. When using this in place of the original compile.exe but still using p.bat, you need to either get rid of the dos4gw.exe reference from p.bat or replace the original dos4gw.exe with the one in this archive.
|
||||
|
||||
If you use fallout script editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible.
|
||||
If you use Fallout Script Editor, you can extract `compile.exe` and `dos4gw.exe` to its `\binary` folder, or extract them somewhere else and change your preferences in FSE to point there. FSE doesn't seem to be able to tell when errors occur when using this compiler though, so I'd recommend either using sfall's script editor instead or compiling by hand if possible.
|
||||
|
||||
When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include`s that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5)
|
||||
When compiling global or hook scripts for sfall 3.4 or below, you _must_ include the line `procedure start;` before any `#include` files that define procedures to avoid a few weird problems. (this is no longer required starting from 3.5)
|
||||
|
||||
This version of compiler was designed primarily for new sfall functions, but it can safely (and is recommended) to be used with non-sfall scripts as well, as long as you don't use any of the arrays syntax and any sfall script functions.
|
||||
|
||||
The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files/srcs/index.shtml](http://www.teamx.ru/eng/files/srcs/index.shtml).
|
||||
The original unmodified sslc source is over here: [https://teamx.ru/site_arc/utils/index.html](https://teamx.ru/site_arc/utils/index.html)
|
||||
|
||||
## Command line options
|
||||
|
||||
@@ -31,7 +31,9 @@ The original unmodified sslc source is over here: [http://www.teamx.ru/eng/files
|
||||
-b backward compatibility mode
|
||||
-l no logo
|
||||
-p preprocess source
|
||||
-O optimize code (full, see optimization.txt)
|
||||
-P preprocess only (don't generate .int)
|
||||
-F write full file paths in "#line" directives
|
||||
-O optimize code (full by default, see "Optimization" page)
|
||||
-O<N> set specific level of optimization (0 - off, 1 - basic, 2 - full, 3 - experimental)
|
||||
-d print debug messages
|
||||
-D output an abstract syntax tree of the program
|
||||
@@ -45,7 +47,7 @@ The original command line option `-w` to turn on warnings no longer has an effec
|
||||
|
||||
## Additional supported syntax
|
||||
|
||||
Syntax which requires sfall for compiled scripts to be interpreted, is marked by asterix (*).
|
||||
Syntax which requires sfall for compiled scripts to be interpreted is marked by asterisk (*).
|
||||
|
||||
- Optional arguments in user-defined procedures. You can only use constants for default values. It basically puts those constants in place of omitted arguments.
|
||||
|
||||
@@ -73,14 +75,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
|
||||
If `obj` is `null`, the second condition will not be checked and your script won't fail with "obj is null" error in debug.log
|
||||
|
||||
This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always 0 (`false`) or 1 (`true`):
|
||||
This also has an effect that a value of last computed argument is returned as a result of whole expressions, instead of always `false` (0) or `true` (1):
|
||||
```
|
||||
obj := false;
|
||||
display_msg(obj orElse "something"); // will print "something"
|
||||
```
|
||||
You can also use the `-s` option to enable short-circuit evaluation for all the `AND`, `OR` operators in the script.
|
||||
|
||||
NOTE: Be aware that it may break some old scripts because operators behavior is changed slightly.
|
||||
__NOTE:__ Be aware that it may break some old scripts because operators behavior is changed slightly.
|
||||
|
||||
- Conditional expressions (Python-inspired), also known as ternary operator:
|
||||
- new:
|
||||
@@ -94,7 +96,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
else
|
||||
X := value2;
|
||||
```
|
||||
- To assign values, you can use the alternative assignment operator from C/Java instead of Pascal syntax.
|
||||
|
||||
- To assign values, you can use the alternative assignment operator from **C/Java** instead of **Pascal** syntax.
|
||||
- new:
|
||||
```
|
||||
x = 5;
|
||||
@@ -103,7 +106,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
```
|
||||
x := 5;
|
||||
```
|
||||
- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style.
|
||||
|
||||
- Multiple variable declaration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style.
|
||||
- new:
|
||||
```
|
||||
variable a, b, c;
|
||||
@@ -112,6 +116,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
```
|
||||
variable begin a; b; c; end
|
||||
```
|
||||
|
||||
- Variable initialization with expressions: You can now initialize local variables with complex expressions instead of constants.
|
||||
- new:
|
||||
```
|
||||
@@ -122,9 +127,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
variable tile;
|
||||
tile := tile_num(dude_obj);
|
||||
```
|
||||
NOTE: if your expression starts with a constant (eg. `2+2`), enclose it in parentheses, otherwise compiler will be confused and give you errors.
|
||||
__NOTE:__ If your expression starts with a constant (eg. `2 + 2`), enclose it in parentheses, otherwise compiler will be confused and give you errors.
|
||||
|
||||
- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers `0` to `9` and `a-f` are allowed in the number. The number may not have a decimal point.
|
||||
- Hexadecimal numerical constants: Simply prefix a number with `0x` to create a hexadecimal. The numbers 0 to 9 and letters A to F are allowed in the number. The number may not have a decimal point.
|
||||
- new:
|
||||
```
|
||||
a := 0x1000;
|
||||
@@ -133,7 +138,8 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
```
|
||||
a := 4096;
|
||||
```
|
||||
- Increment/decrement operators: `++` and `--` can be used as shorthand for `+=1` and `-=1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+=1` would normally be allowed.
|
||||
|
||||
- Increment/decrement operators: `++` and `--` can be used as shorthand for `+= 1` and `-= 1` respectively. They are mearly a syntactic shorthand to improve readability, and so their use is only allowed where `+= 1` would normally be allowed.
|
||||
- new:
|
||||
```
|
||||
a++;
|
||||
@@ -143,7 +149,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
a += 1;
|
||||
```
|
||||
|
||||
- `break` & `continue` statements: they work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details).
|
||||
- `break` & `continue` statements: They work just like in most high-level languages. `break` jumps out of the loop. `continue` jumps right to the beginning of the next iteration (see `for` and `foreach` sections for additional details).
|
||||
- new:
|
||||
```
|
||||
while (i < N) begin
|
||||
@@ -187,18 +193,18 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
- new:
|
||||
```
|
||||
for (i := 0; i < 5; i++) begin
|
||||
display_msg("i = "+i);
|
||||
display_msg("i = " + i);
|
||||
end
|
||||
```
|
||||
- old:
|
||||
```
|
||||
i := 0;
|
||||
while (i < 5) do begin
|
||||
display_msg("i = "+i);
|
||||
display_msg("i = " + i);
|
||||
i++;
|
||||
end
|
||||
```
|
||||
NOTE: `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop.
|
||||
__NOTE:__ `continue` statement in a `for` loop will recognize increment statement (third statement in parentheses) and will execute it before jumping back to the beginning of loop. This way you will not get an endless loop.
|
||||
|
||||
- `switch` statements: A shorthand way of writing big `if then else if...` blocks
|
||||
- new:
|
||||
@@ -222,7 +228,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
end
|
||||
```
|
||||
|
||||
- empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition:
|
||||
- Empty statements in blocks are allowed: This is just a convenience to save scripters a bit of memory. Some of the macros in the Fallout headers include their own semicolons while others do not. With the original compiler you had to remember which was which, and if you got it wrong the script would not compile. Now it's always safe to include your own semicolon, even if the macro already had its own. For example, this would not compile with the original sslc, but will with the sfall edition:
|
||||
```
|
||||
#define my_macro diplay_msg("foo");
|
||||
|
||||
@@ -230,12 +236,9 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
my_macro;
|
||||
end
|
||||
```
|
||||
__NOTE:__ **Does not work currently.**
|
||||
|
||||
- Procedure stringify operator `@`: designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant.
|
||||
Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this:
|
||||
- optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure "critical")
|
||||
- you couldn't see all references of a procedure from a Script Editor
|
||||
- it was completely not obvious that you could do such a thing, it was a confusing syntax
|
||||
- Procedure stringify operator `@`: Designed to make callback-procedures a better option and allow for basic functional programming. Basically it replaces procedure names preceeded by `@` by a string constant.
|
||||
- old:
|
||||
```
|
||||
callbackVar := "Node000";
|
||||
@@ -246,7 +249,12 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
callbackVar := @Node000;
|
||||
callbackVar();
|
||||
```
|
||||
- *arrays: In vanilla fallout arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in []'s to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "arrays.txt" for more information)
|
||||
Not many people know that since vanilla Fallout you can call procedures by "calling a variable" containing it's name as a string value. There was a couple of problems using this:
|
||||
- optimizer wasn't aware that you are referencing a procedure, and could remove it, if you don't call it explicitly (can be solved by adding making procedure `critical`)
|
||||
- you couldn't see all references of a procedure from a Script Editor
|
||||
- it was completely not obvious that you could do such a thing, it was a confusing syntax
|
||||
|
||||
- (*) **Arrays**: In vanilla Fallout, arrays had to be constructed by reserving a block of global/map variables. Since sfall 2.7, specific array targeted functions have been available, but they are fairly messy and long winded to use. The compiler provides additional syntactic shorthand for accessing and setting array variables, as well as for array creation. When declaring an array variable, put a constant integer in `[]`` to give the number of elements in the array. (before sfall 3.4 you had to specify size in bytes for array elements, now it's not required, see "Arrays" page for more information)
|
||||
- new:
|
||||
```
|
||||
procedure bingle begin
|
||||
@@ -267,7 +275,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
end
|
||||
```
|
||||
|
||||
- *array expressions: sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible:
|
||||
- (*) **Array expressions**: Sometimes you need to construct an array of elements and you will probably want to do it in just one expression. This is now possible:
|
||||
- new:
|
||||
```
|
||||
list := ["A", "B", "C", "D"];
|
||||
@@ -280,14 +288,14 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
list[2] := "C";
|
||||
list[3] := "D";
|
||||
```
|
||||
Syntax specific for associative arrays is also available. (see "arrays.txt" for full introduction to this type of arrays).
|
||||
Syntax specific for associative arrays is also available. (see "Arrays" page for full introduction to this type of arrays).
|
||||
|
||||
- *map array expressions:
|
||||
- (*) **Map array expressions**:
|
||||
```
|
||||
map := {5: "five", 10: "ten", 15: "fifteen", 20: "twelve"};
|
||||
```
|
||||
|
||||
- * "dot" syntax to access elements of associative arrays. "dot" syntax allows to work with arrays like objects:
|
||||
- (*) The dot `.` syntax to access elements of associative arrays and allow to work with arrays like objects:
|
||||
```
|
||||
trap.radius := 3;
|
||||
trap.tile := tile_num(dude_obj);
|
||||
@@ -296,16 +304,15 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
```
|
||||
collectionList[5].objectList[5].name += " foo";
|
||||
```
|
||||
__NOTE:__ When using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of `get_array` calls twice.
|
||||
|
||||
NOTE: when using incremental operators like `+=`, `*=`, `++`, `--` compiler will use additional temp variable to get an array at penultimate level in order to avoid making the same chain of "get_array" calls twice.
|
||||
|
||||
- * `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach (<symbol> in <expression>)`.
|
||||
- (*) `foreach` loops: A shorthand method of looping over all elements in an array. Syntax is `foreach (<symbol> in <expression>)`.
|
||||
- new:
|
||||
```
|
||||
procedure bingle begin
|
||||
variable critter;
|
||||
foreach (critter in list_as_array(LIST_CRITTERS)) begin
|
||||
display_msg(""+critter);
|
||||
display_msg("" + critter);
|
||||
end
|
||||
end
|
||||
```
|
||||
@@ -322,6 +329,7 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
If you want an index array element (or key for "maps") at each iteration, use syntax: `foreach (<symbol>: <symbol> in <expression>)`
|
||||
```
|
||||
foreach (pid: price in itemPriceMap) begin
|
||||
@@ -329,15 +337,13 @@ Syntax which requires sfall for compiled scripts to be interpreted, is marked by
|
||||
itemPrice := price;
|
||||
end
|
||||
```
|
||||
|
||||
If you want to add additional condition for continuing the loop, use syntax: `foreach (<symbol> in <expression> while <expression>)`. In this case loop will iterate over elements of an array until last element or until "while" expression is true (whatever comes first).
|
||||
|
||||
NOTE: just like `for` loop, "continue" statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`.
|
||||
|
||||
## int2ssl note
|
||||
|
||||
int2ssl by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script.
|
||||
__NOTE:__ Just like `for` loop, `continue` statement will respect increments of a hidden counter variable, so you can safely use it inside `foreach`.
|
||||
|
||||
## Fixes
|
||||
|
||||
- `playmoviealpharect` was using the token for `playmoviealpha`, breaking both functions in the process.
|
||||
- `addbuttonflag` had an entry in the token table, and could be parsed, but was missing an entry in the emit list. This resulted in the compiler accepting it as a valid function, but not outputting any code for it into the compiled script.
|
||||
- The function `tokenize` was missing an entry in the token table, and so would not be recognised by the compiler.
|
||||
@@ -350,3 +356,7 @@ There are several changes in this version of sslc which may result in problems f
|
||||
- Missing a semicolon after a variable declaration is now a hard error. (Originally sslc would check for the semicolon, but would not complain if it was missing.)
|
||||
- The function `addbuttonflag` used to be recognised by the compiler, but would not emit any code into the int file.
|
||||
- The function `playmoviealpharect` compiled as `playmoviealpha`.
|
||||
|
||||
## int2ssl note
|
||||
|
||||
**int2ssl** by Anchorite (TeamX) is included in sfall modderspack package. It was updated to support all additional opcodes of sfall, along with some syntax features. You can use it to decompile any sfall or non-sfall script.
|
||||
|
||||
Reference in New Issue
Block a user