// redscript allows line comments
/* as well as block comments */
// it supports global functions
func add2(x: Int32, y: Int32) -> Int32 {
// functions without a type annotation default to Void return type
// compiler can infer types for local variables, y will be Int32
// it supports arithmetic
// numbers with decimal points default to type Float
// you can cast between some types
let uint: Uint8 = Cast(10);
// logging and string operations
Log("at " + ToString(item));
// you can define your own classes
// you can define static member functions
public static func Create(fst: Int32, snd: Int32) -> ref<IntTuple> {
let tuple = new IntTuple();
// you can replace existing in-game methods by specifying the class they belong to
@replaceMethod(CraftingSystem)
private final func ProcessCraftSkill(xpAmount: Int32, craftedItem: StatsObjectID) {
// instantiate a class using the new operator
let xpEvent = new ExperiencePointsEvent();
xpEvent.amount = xpAmount * 100;
xpEvent.type = gamedataProficiencyType.Crafting;
GetPlayer(this.GetGameInstance()).QueueEvent(xpEvent);
// you can add new methods to existing classes as well
// they are visible to other code using the class
@addMethod(BackpackMainGameController)
private final func DisassembleAllJunkItems() -> Void {
let items = this.m_InventoryManager.GetPlayerItemsByType(gamedataItemType.Gen_Junk);
ItemActionsHelper.DisassembleItem(this.m_player, InventoryItemData.GetID(item));
// some methods require CName literals, they need to be prefixed with the n letter
this.PlaySound(n"Item", n"OnBuy");