Comment on page
📗
Scripting API
Explaining how to create and run a custom mod
This page is still heavily WIP, and the headers are just placeholders
- What is this, what can you do with it, how does it work, redscript note
- Helpers make it easy, some listed below
- Where can we use it, difference to redscript thing
- What is it in reds, dont store it etc.
- Description
- What names to use
- .new, as constructor
- When to use, how to use
- When to use, how to use, use on member functions
- How to use, nativeDB link, enumInt
- Function to add CNames, string to cname
- Note on how powerful it is etc, link to seperate doc
Blackboard is a kind of shared data storage and a framework to access/notify/listen to the data in the storage. Similar to a real blackboard, game objects put their data on the board that then other objects can observe, react to or update the data. E.g. various game state values.
They require a handle (more on that later). Assuming you have a
player
handle:print(player:IsNaked())
print(player:IsMoving())
player:OnDied()
Handles are a way to pass an object to the function. For example
IsNaked
makes no sense without telling the engine for which object we want to know this information.These handles are static, there is only one in the game, for example the
gameTimeSystem
is a singleton so there is no need to tell the script engine which one you want. That being said you need a singleton handle so it knows you want to call a function on that system.Sample:
gameTime = GetSingleton("gameTimeSystem")
print(gameTime:GetGameTime())
gameTime:SetGameTimeByHMS(12,0,0) -- 12h0m0s
These handles are not unique, for example, the game contains multiple NPCs so there are as many handles as NPCs. Currently as far as I know we can only get the handle of the
player
by calling the global function Game.GetPlayer()
.Sample:
player = Game.GetPlayer()
if player:IsNaked() then
player:OnDied() -- kill the player if it's naked
end
player = Game.GetPlayer()
ts = Game.GetTransactionSystem()
tid = TweakDBID.new("Items.money")
itemid = ItemID.new(tid)
result = ts:GiveItem(player, itemid, 100000)
if result then
print("We added " .. tostring(itemid) .. " to the inventory!")
else
print("Failed to add " .. tostring(itemid))
end
They do not need a handle and are all located in the
Game
object. Sample:Game.PrintHealth()
-- or
Game.AddToInventory("Items.money", 500)
Last modified 1mo ago