WS: Language Guide
Basics
Comments
During the development of new scripts it is possible to add comments to make it easier to follow your code.
Single line comments can be added like so:
// This is a single line comment
Multi-line comments can be used for bigger blocks of text as well:
/*
This text is multiple lines long.
...
*/
Together they can be used to make your code more easily readable, for example:
/*
Example mod by Bob
Version 1.0
Created on 2024.05.01.
*/
exec function scripts_tutorial_test()
{
// Show the hello text so we can verify easily that the mod works.
GetWitcherPlayer().DisplayHudMessage('Hello');
}
Types
WitcherScript has a list of basic types that can be used inside the scripts to store data:
int
- Standard 32bit integer (value range from -2,147,483,648 to 2,147,483,647)String
- Standard string, use quotation marks to pass values, eg.: "This is a string"name
- Name type variable, essentially a string used for item names, tags, etc. Use apostrophes to pass values, eg.: 'this is an item name'float
- Standard float type, eg.: 1.0fVector
- 4 variable vector (Quaternion) ordered in XYZW order, eg.: Vector(100, 100, 100, 1)EulerAngles
- 3 variable rotation ordered in Pitch, Yaw, Roll order, eg.: EulerAngles(0, 180, 0)bool
- standard true/false boolean, also accepts 0 and 1 as inputs, however unlike Unreal Script does not accept Yes/No valuesMatrix
- Indicates matrix variable type.array< X >
- Indicates an array with X being the type of array, eg. array< int > being an array of integers
Global objects
The game exposes a list of global object that you can use from anywhere. They are always available and expose a lot of very useful functions.
For example if you want to do something with the player. You can simply write:
Instead of using GetWitcherPlayer()
and the game will know that you are referring to the player. These can be changed inside redscripts.ini
but it is not recommended to change them since your mod will not be compatible with others who have the default settings.
Variables
It is possible to define variables to store your data and you can use them to pass around your data.
Local variables
Inside a given function to process the data etc. it is possible to define variables that can be used throughout the function. They do have to be defined at the top of your function however.
Class variables
Classes can contain member variables as well. They are tied to the given class and can be used to store the data.
Function parameters
It is possible to pass parameters to functions which you can use to parameterise them. For example the code snippet bellow can help you change the weather in-game. Try running it in the debug console as RequestWeatherChangeTo('WT_Rain_Storm');
and observer that it has started raining
Functions
WitcherScript has different kinds of functions that you can set up. Check the list below.
Exec function
Executable functions are exposed to the game’s debug console and can be used to start functions or utility functions when developing your mods.
An example from the Mariska’s Wonderland demo mod, which was used to give the player the key ( item_sqmod1_canyon_hideout_key
) for the back room in the hidden dungeon during debugging:
Latent function
These are like Coroutines etc. in other engines basically they allow for passing time and slower execution. Bellow you can see the sleep call in the function which allows to wait X amount of seconds.
Timer function
These functions are real time based timer which can be attached to entities.
states.ws has some utility functions for this:
Setting up a function is really easy like so:
The dt parameter defines the “delta time” the amount of time that has passed.
Storyscene function
Special functions that can be used in scenes.
Quest function
Special functions that can be used in Quest nodes.
Reward function
These functions can be attached to a given reward inside the editor.
Cleanup function
They cannot return anything and have no parameters. They are used for cleaning up after something has finished.
Entry function
An entry function is a state entry function for which you can see an example below. These are rarely used in the game.
Summary
Possible function flags
Generic flags
Classes
A class in object-oriented programming (OOP) is a blueprint for creating objects. It encapsulates data for the object and methods to manipulate that data. Classes allow for the organization of code into reusable and modular components.
Regular class
Normal classes allow you to hold values and methods inside a common container which you can reuse.
Native class
These are classes defined in C++ and need to be imported to WitcherScript
Statemachine
These classes define a default state and then you can define states that it can transition to, think about it like a text like graph with transitions. Below you can see the statemachine for the Witches cage which has two state of being turned on and off.
You can check states.ws for reference on how to use these functions.
Summary
______________________________________
The Witcher 3: Wild Hunt Complete Edition © 2024 CD PROJEKT S.A. Published by CD PROJEKT S.A. Developed by CD PROJEKT RED. CD PROJEKT®, The Witcher®, REDengine® are registered trademarks of CD PROJEKT Capital Group. All rights reserved. The Witcher game is set in the universe created by Andrzej Sapkowski in his series of books. All rights reserved.