Jump to content

Need help with a custom item


Recommended Posts

I'm trying to add a sword item to a character I'm making for their starting item that functions similarly to Lucy in the sense that it has dialgue. But I keep getting errors claiming that its say function is nil even after I defined the strings in the mainmod.lua. My dialogue code is basically just a mismatched version of Lucy's.

-- KAJ: TODO MP_TALK - there's a lot of Say() in here-- KAJ: TODO Strings assume woodielocal SentientAxe = Class(function(self, inst)    self.inst = inst    self.time_to_convo = 10    self.inst:ListenForEvent("equipped", function(_, data) self:OnEquipped(data.owner) end)	self.inst:ListenForEvent("onpickup", function(_, data) self:OnPickedUp(data.owner) end)    local dt = 5    self.inst:DoPeriodicTask(dt, function() self:OnUpdate(dt) end)    self.warnlevel = 0	self.OnDroppedClosure = function() self:OnDropped() end	self.OnFinishedWorkClosure = function(_,data) self:OnFinishedWork(data.target, data.action) endend)function SentientAxe:SetOwner(owner)	if owner then		if owner ~= self.owner then		    self.inst:ListenForEvent("ondropped", self.OnDroppedClosure)		    self.inst:ListenForEvent("finishedwork", self.OnFinishedWorkClosure, owner)		end	else		if self.owner then			-- remove owner specific listeners		    self.inst:RemoveEventCallback("ondropped", self.OnDroppedClosure)		    self.inst:RemoveEventCallback("finishedwork", self.OnFinishedWorkClosure, self.owner)		end	end	self.owner = ownerendfunction SentientAxe:OnHaunted()    local snd = {"dontstarve/characters/woodie/lucy_warn_1", "dontstarve/characters/woodie/lucy_warn_2"}    self:Say(STRINGS.ECHO.on_haunted, snd[math.random(#snd)])endfunction SentientAxe:OnPickedUp(owner)	self:SetOwner(owner)endfunction SentientAxe:OnFinishedWork(target, action)        --self:Say(STRINGS.ECHO.on_chopped)    if action == ACTIONS.CHOP and         self.inst.components.inventoryitem.owner and self.inst.components.inventoryitem.owner:HasTag("player") and         self.inst.components.equippable:IsEquipped() then        self:Say(STRINGS.ECHO.on_chopped)    end	endfunction SentientAxe:OnDropped()	assert(self.owner)	if self.owner and self.owner.prefab == "elizabeth" then		self:Say(STRINGS.ECHO.on_dropped)		--end		self:SetOwner(nil)	endendfunction SentientAxe:OnEquipped(picked_up_by)	self:SetOwner(picked_up_by)    if picked_up_by:HasTag("player") then		if picked_up_by.prefab == "elizabeth" then        self:Say(STRINGS.ECHO.on_pickedup)		else		self:Say(STRINGS.ECHO.other_owner)		end    endendfunction SentientAxe:OnUpdate(dt)    self.time_to_convo = self.time_to_convo - dt    if self.time_to_convo <= 0 then        self:MakeConversation()    endendfunction SentientAxe:MakeConversation()        local grand_owner = self.inst.components.inventoryitem:GetGrandOwner()    local owner = self.inst.components.inventoryitem.owner    local quiplist = nil    if owner and owner:HasTag("player") then        if self.inst.components.equippable:IsEquipped() and owner.prefab == "elizabeth" and owner.components.beaverness:GetPercent() < .25 then            --currently equipped            quiplist = STRINGS.ECHO.equipped        elseif self.inst.components.equippable:IsEquipped() and owner.prefab == "elizabeth" then        elseif self.inst.components.equippable:IsEquipped() then            --in player inventory            quiplist = STRINGS.ECHO.other_owner        end    elseif owner == nil then        --on the ground        quiplist = STRINGS.ECHO.on_ground    elseif grand_owner and grand_owner ~= owner and grand_owner:HasTag("player")  then        --in a backpack        quiplist = STRINGS.ECHO.in_container    elseif owner and owner.components.container then        --in a container        quiplist = STRINGS.ECHO.in_container    else        --owned by someone else        quiplist = STRINGS.ECHO.other_owner    end    if quiplist then        self:Say(quiplist)    endendreturn SentientAxe

am I doing it wrong?

Link to comment
Share on other sites

Here's my error message if it helps. 

[string"../mods/Elizabeth/scripts/components/sentie..."]:137: attempt to call method 'Say'(a nil value)LUA ERROR stack traceback:  ../mods/Elizabeth/scripts/components/sentientaxe/lua:137 in (method) OnEquiped(Lua)<133-142>  ../mods/Elizabeth/scripts/components/sentientaxe/lua:78 in (local) fn (Lua) <78-78>  scripts/entityscript.lua:935 in (method) PushEvent (Lua) <929-952>  scripts/components/equippable.lua:72 in (method) epuip(Lua) <62-74>  scripts/components/inventory.lua:815 in () ? (Lua) <752-829>  =tail call):-1 in () (tail) <-1--1>  scripts/bufferedaction.lua:22 in (method) Do (Lua) <19-35>	
Link to comment
Share on other sites

@synthmilieu Do you have a function called Say in that script?

 

(copied from sentientaxe.lua)

function SentientAxe:Say(list, sound_override)    self.sound_override = sound_override    self.inst.components.talker:Say(list[math.random(#list)])    self.time_to_convo = math.random(60, 120)end
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...