-
Notifications
You must be signed in to change notification settings - Fork 0
ThpsQScriptEd\Syntax Reference
- Scripts
- Range values
- Comments
- Numeric types
- Vectors
- Escape sentences
- Passing arguments/parameters
- Operators
- Class property and methods
- Random
- Random range
- NodeArray specific stuff
A function, procedure or script is defined as follows:
script <scriptname> [params]
[some code]
endscript
There are various range values defined using various brackets
someStruct = { value0 = 0 value1 = 1 value2 = 2 }
someArray = [ { struct1 } { struct2 } ]
someVector = (0.1, 0.2, 0.3)
random ( @val1 @val2)
commenting is supported:
;this is a comment
//this is a comment too
/*
multi line comments
are not supported yet, unfortunately
*/
Comments are only saved in q source file and completely discarded in compiled qb. Keep in mind that if you don't tick the "remove trailing new lines" checkbox, qb file will contain an extra newline opcode for every comment line.
Trivia: Neversoft used a variant of crc32 hashing algorithm to create a kind of hash map of every single object name in the game. This allows to find objects by just comparing 2 uint values instead of entire strings. This, however, is vulnerable to unintended collisions, when 2 different strings generate same checksum.
Every string that was not recognized as a keyword or operator will be turned into a "hash symbol".
Generally you should use no spaces in your variable names, however, if you'd want to include a space there, a special hash operator exists for those:
#"string to hash"
For words without spaces it doesn't matter whether you'll write it or not, anything not validated as being an opcode/param/etc becomes a hash symbol in the end, hence writing testword
is equal to #"testword"
.
-
1 is parsed as int
-
-2 is parsed as int
-
.5 is parsed as float
-
-1.5 is parsed as float too
-
90° is an angle in degrees. it is converted to float value in radians. rad = deg / 180 * Pi.
By default all float values decompile with at least 1 decimal zero, which means 1 was int in the original QB and 1.0 is originally float
Vectors are defined as 2 or 3 embraced comma separated numeric values:
- (0, 0)
- (640, 480)
- (1.0, -1.0)
- (255.0, 255.0, 255.0)
- (45°, -90°, 180°)
Keep in mind there is no vector4 and above. (0, 0, 0, 0) will be converted as is: open bracket, num, comma, num, comma, etc.
Used in strings, these are supported: ' " \ Basically means that 'Razor's Edge' will be presented as 'Razor's Edge' in script.
you can pass a param using <>: SomeFunc myparam = <someparam>
to pass everything given, use <...>: SomeFunc <...>
note that <...>
is a keyword, you can't write < . . . >
.
be careful, minus sign will only work with spaces.
i--5
- incorrect. will compile into symbol "i--5"
i - -5
- correct. will compile to symbol "i", opcode minus, int -5
other math operators work without spaces just fine i+5 aka i + 5 aka i+ 5 aka i +5
and/or requires space as well. x and y aka x && y, but not x&&y x or y aka x || y , but not x||y
not x aka !x , this one works without space Be careful, if Not is present in the game as a function. This may break the intended logic.
introduced in THPS4
Skater:GetPosition
Skater.Position
please note that due to these operators your symbols can't include : and . this requires thorough testing since this is not supported in THPS3 and possibly can break things.
Random code is executed using this syntax:
dostuff somepram = random( @1 @2 @3 )
There are more random functions including random, randomnorepeat, randompermute, (someotherrandom)
! currently you can't use random inside another random, it won't compile correctly. !
randomrange
is a different type of random.
it simply generates a random float value within the range.
It's being followed by a vector2 value instead of randomjumps @.
randomRange (0.5, 10.5)
Angle
node param can be optionally visualized in degrees.
The original vector value stores angles in radians.
So basically, while the code will look like: Angles = (180°, -180°, 180°)
It will compile into: Angles = (~3.1415, ~-3.1415, ~3.1415)
see numeric types for radian math explanation.
!!! ATTENTION !!!
This tool replaces link indices in NodeArray with the actual node name.
for this to work correctly, every node must have a name, and the same
file should contain TriggerScripts
array defined AFTER NodeArray
, which is true for any original nodeArray.
This feature allows you to easily reorder nodes in the array as you don't have to care about the correct indices anymore.
NodeArray = [
{ Position = (0,10,0) Name = Node01 Class = RailNode }
{ Position = (0,20,0) Name = Node02 Class = RailNode Links = [ Node01 ] }
//will actually compile to { Position = (0,20,0) Name = Node02 Class = RailNode Links = [ 0 ] }
//cause Node01 index is 0 in this array
]