So... Yeah, this topic has seemingly been abandoned for awhile. Hopefully someone out there will see this and fix my problem, but until then, may aswell as put my problem.
I was doing some dialogue for a Gatekeeper who you had to give a shield, Me, being the most noobish Coder in the land, decided to use a heavily modified verison of dialogue_04.lua from the sample dungeon.
This is the code.
items = { name="gift", uiName="Here is the Vanguard, Gatekeeper.", cost=1 },
function countInventoryItem(name)
if name == nil then return 0 end
local count = 0
for idx=1,4 do
local champion = party.party:getChampion(idx)
for slot=1,ItemSlot.MaxSlots do
local item = champion:getItem(slot)
if (item and (item.go.name == name)) then
count = count + item:getStackSize()
end
end
end
return count
end
--
-- Remove "count" of object "name" from the player's inventory.
--
function removeInventoryItem(name, count)
if name == nil then return false end
if count == nil then count = 0 end
local remaining = count
if countInventoryItem(name) < count then
return false
end
for idx=1,4 do
local champion = party.party:getChampion(idx)
for slot=1,ItemSlot.MaxSlots do
local item = champion:getItem(slot)
if (item and (item.go.name == name)) then
if item:getStackSize() <= remaining then
remaining = remaining - item:getStackSize()
champion:removeItemFromSlot(slot);
else
item:setStackSize(item:getStackSize() - remaining)
remaining = 0
end
end
if remaining <= 0 then
return true
end
end
end
print("ERROR: Should never get here - items lost but function failed!")
return false
end
function gtkDidLoad()
end
function buyItem(index)
local vanguard = countInventoryItem("vanguard")
local item = items[index]
if item == nil then
Console.warn("[GTK] Attempted to buy invalid item.");
return
end
if vanguard < item.cost then
-- Can either do GTKGui.Dialogue.showDialoguePage("next_page") or return "next_page"
GTKGui.Dialogue.showDialoguePage("no_vanguard")
return
end
removeInventoryItem("vanguard", item.cost);
return "purchase_complete"
end
function showDialogue(sender)
local storeKeeperName = "The Gatekeeper"
local championName = party.party:getChampion(1):getName();
local dialogue = {
lockParty = true,
pages = {
{
id = "welcome",
speakerName = storeKeeperName,
speakerMessage = "Hello, " .. championName .. " and party. What do you want??",
responses = {
{ text = "Who are you?", nextPage = "who_are_you" },
{ text = "I know you're the Gatekeeper, how can I get passage?", nextPage = "show_wares" },
{ text = "<Walk Away>" },
}
},
{
id = "who_are_you",
speakerName = storeKeeperName,
speakerMessage = "I am the Gatekeeper, I protect the entrance and exit to Grokham Volcano, None shall pass without proper invitation, or a trial.",
responses = {
{ text = "Okay then, good to know.", nextPage = "welcome" },
{ text = "<Walk Away>" },
}
},
{
id = "show_wares",
speakerName = storeKeeperName,
speakerMessage = "I require an item if you wish to pass, I need a new shield, named the Vanguard. Get it for me and you can pass. Its in Zeonguard Cave.",
responses = {
{ text = items[1].uiName, onSelect=self.go.id..".script.buyItem" },
{ text = "Alright, I will get the shield for you. <Walk Away>" },
}
},
{
id = "no_vanguard",
speakerName = storeKeeperName,
speakerMessage = "You dont have the Vanguard with you! I wont let you pass!",
responses = {
{ text = "Sorry! Let me go get it!. <Walk Away>" },
}
},
{
id = "purchase_complete",
speakerName = storeKeeperName,
speakerMessage = "Thank you, also, have a gift, It may come in handy.",
responses = {
{ text = "Thank you." },
}
},
}
}
GTKGui.Dialogue.startDialogue(dialogue);
end
function hideDialogue()
GTKGui.Dialogue.hideDialogue();
end
Unfortunately, unlike my previous tests, I got an error, that said this about the dialogue,
mod_assets/Grimtk tests/Dialogue Gatekeeper.lua:120: attempt to index a nil value
stack traceback:
mod_assets/Grimtk tests/Dialogue Gatekeeper.lua:120: in function <mod_assets/Grimtk tests/Dialogue Gatekeeper.lua:89>
[string "Script.lua"]: in function 'sendMessage'
[string "Component.lua]: in function 'triggerConnectiors'
[string "Compoenent.lua]: in function 'callHook'
[string "FloorTrigger.lua"]: in function 'activate'
[string "FloorTrigger.lua"]: in function 'update'
[string "Map.lua"]: in function 'updateComponents'
[string "Map.lua"]: in function 'updateEntities'
[string "Dungeon.lua"]: in function 'updateLevels'
[string "GameMode.lua"]: in function 'update'
[string "DungeonEditor.lua"]: in main chunk
[C]: in function 'xpcall'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk
So, I'm in quite a pickle, and would love if someone would help me find the problem to this. And because this was abandoned, Bump.