Re: Modding infodump
Posted: Sun Oct 23, 2016 5:37 am
Sorry, I haven't been looking into it.
Minmay: Thank you for the information. I understand the above and I'm wanting to build on it. Generically, what other conditions can be defined and how are they triggered? (Other conditions I've found are: onInitialActivate - appears to be run just once and NOT when the game is reloaded, onInitialDeactivate - I assume it runs only the first time it's deactivated, OnActivate, onDeactivate, and onToggle where I assume the last three are hit by scripts only.)minmay wrote: Detecting reloads
To detect when the dungeon is loaded, place a single instance of this object anywhere in your dungeon:]Code: Select all
defineObject{ name = "load_detector", placement = "floor", components = { { class = "Null", onInit = function(self) -- Whenever this function is called, the dungeon has -- been loaded; either a new game was started, or a -- saved game was loaded. end, }, }, editorIcon = 148, minimalSaveState = true, }
Code: Select all
defineObject{
name = "test_platform",
baseObject = "base_floor_decoration",
components = {
{
class = "Model",
model = "mod_assets/models/test_platform_01.fbx",
offset = vec(0,-3,-1.5),
staticShadow = true,
},
{
class = "Platform",
},
{
class = "Controller",
onInitialActivate = function(self)
self:activate()
local t = spawn("floor_trigger", self.go.level, self.go.x , self.go.y, self.go.facing, self.go.elevation, self.go.id .. "_trigger")
t.floortrigger:setTriggeredByParty(true)
t.floortrigger:setTriggeredByMonster(false)
t.floortrigger:setTriggeredByItem(false)
t.floortrigger:setTriggeredByDigging(false)
t.floortrigger:setDisableSelf(false)
t.floortrigger:addConnector("onActivate", self.go.id, "onDeactivate") --This line fails... is it even possible?
end,
onInit = function(self)
self.go.platform:enable()
end,
onInitialDeactivate = function(self)
self.go.platform:disable()
end,
onActivate = function(self)
print(self.go.id .. " onActivate raised.")
end,
onDeactivate = function(self)
self.go.platform:disable()
print(self.go.id .. " onDeactivate raised.")
end,
onToggle = function(self)
if self.go.platform:isEnabled() then
self:deactivate()
else
self:activate()
end
end,
},
},
minimalSaveState = true,
}
Code: Select all
defineObject{
name = "omnitool",
components = {
{
class = "Timer",
timerInterval = 120,
onActivate = function(self)
self.go.script:omnitoolFunction(self)
end,
},
{
class = "Controller",
onActivate = function(self)
self.go.timer:enable()
end,
onDeactivate = function(self)
self.go.timer:disable()
end,
onToggle = function(self)
if self.go.timer:isEnabled() then
self.go.timer:disable()
else
self.go.timer:enable()
end
end,
},
{
class = "Script",
source = [[
function omnitoolFunction(self)
hudPrint("Omnitool labled '"..self.go.id.."' activated at ("..self.go.x..","..self.go.y..")")
end
]]
},
},
placement = "floor",
editorIcon = 268,
tags = { "zim_assets" },
}
I think you're confused about the purpose of ControllerComponent. The ControllerComponent hooks have no inherent meaning. ControllerComponent exists so that you have a convenient, consistent way to handle connector messages, and has absolutely nothing to do with the passage you quoted. onActivate is only called when you call ControllerComponent:activate(), either from a script or by triggering a connector with the message "activate". onDeactivate is only called when you call ControllerComponent:deactivate(). onToggle is only called when you call ControllerComponent:toggle(), and so on.Lark wrote:Minmay: Thank you for the information. I understand the above and I'm wanting to build on it. Generically, what other conditions can be defined and how are they triggered? (Other conditions I've found are: onInitialActivate - appears to be run just once and NOT when the game is reloaded, onInitialDeactivate - I assume it runs only the first time it's deactivated, OnActivate, onDeactivate, and onToggle where I assume the last three are hit by scripts only.)
Code: Select all
defineObject{
name = "test_platform",
baseObject = "base_floor_decoration",
components = {
{
class = "Model",
model = "mod_assets/models/test_platform_01.fbx",
offset = vec(0,-3,-1.5),
staticShadow = true,
},
{
class = "Platform",
},
{
class = "FloorTrigger",
triggeredByMonster = false,
triggeredByItem = false,
triggeredByDigging = false,
onActivate = function(self)
self.go.controller:activate()
end,
},
{
class = "Controller",
onInitialActivate = function(self)
self:activate()
end,
onInitialDeactivate = function(self)
self.go.platform:disable()
end,
onActivate = function(self)
print(self.go.id .. " onActivate raised.")
end,
onDeactivate = function(self)
self.go.platform:disable()
print(self.go.id .. " onDeactivate raised.")
end,
onToggle = function(self)
if self.go.platform:isEnabled() then
self:deactivate()
else
self:activate()
end
end,
},
},
}
Zimber: I'm making progress and I have the internal script working because of your example, but I've found that when I change the script, I must delete and add the objects again - the old objects don't get the script change even on reloading the project. Can these scripts be external?zimberzimber wrote:You can call an internal function (from a script component) from any other function (onInit, onActivate, onAnimationEvent, etc...) by having it 'navigate' to the script component, and execute a script as you would normally trigger functions through scripts.
Code: Select all
{
class = "Script",
setSource = "External",
loadFile = "mod_assets/scripts/test07.lua",
},