Patterns

Debug logs

Messages logged to the DEBUG channel are visible in the CET console by default (without having to enable game logs).
1
LogChannel(n"DEBUG", "something")
Copied!

General purpose hash map

There are several hash map implementations available in the game. Most importantly, inkHashMap (Uint64 -> ref<IScriptable>) and inkWeakHashMap (Uint64 -> wref<IScriptable>). All custom classes extend IScriptable therefore they can be used as values in those hash maps.
1
let map = new inkHashMap();
2
hashMap.Insert(TDBID.ToNumber(t"key1"), MyClass.Create(1));
3
hashMap.Insert(TDBID.ToNumber(t"key2"), MyClass.Create(2));
4
let value: ref<MyClass> = map.Get(TDBID.ToNumber(t"key1")) as MyClass;
Copied!

Safe downcasting

The as operator returns null when a dynamic cast fails. You can use it combined with IsDefined to perform safe downcasts.
1
let manager = employee as Manager;
2
if IsDefined(manager) {
3
// employee is known to be Manager here
4
}
Copied!
Last modified 1mo ago