[WIP] GrimTK GUI Framework

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: [WIP] GrimTK GUI Framework

Post by Echoplex »

Here is what I received after walking over the dialogue trigger:

Game started

=== Software Failure ===

Code: Select all


[string "Gui.lua"]:0: File not found: mod_assets/ext/grimtk/samples/davion.dds
stack traceback:
	[C]: in function ''
	[string "Gui.lua"]: in function 'drawImage2'
	mod_assets/ext/grimtk/scripts/gtk/core.lua:587: in function 'drawImage'
	mod_assets/ext/grimtk/scripts/gtk/widgets.lua:553: in function 'doDraw'
	mod_assets/ext/grimtk/scripts/gtk/widgets.lua:284: in function 'draw'
	mod_assets/ext/grimtk/scripts/gtk/core.lua:867: in function 'visit'
	mod_assets/ext/grimtk/scripts/gtk/core.lua:872: in function 'visit'
	mod_assets/ext/grimtk/scripts/gtk/core.lua:839: in function 'update'
	mod_assets/ext/grimtk/scripts/hook.lua:2: in function <mod_assets/ext/grimtk/scripts/hook.lua:1>
	[string "Script.lua"]: in function 'sendMessage'
	[string "Component.lua"]: in function 'triggerConnectors'
	[string "Component.lua"]: in function 'callHook'
	[string "Gui.lua"]: in function 'draw'
	[string "GameMode.lua"]: in function 'update'
	[string "Grimrock.lua"]: in function 'display'
	[string "Grimrock.lua"]: in main chunk
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [WIP] GrimTK GUI Framework

Post by AndakRainor »

That means your file is not in this path (mod_assets/ext/grimtk/samples). Also, may be you should put it elsewhere in your mod directories for clarity, for example "mod_assets\textures".

Edit: oops, just saw you did not have the problem in editor mode. So one way or another your file extension is wrong and not exported as a result... Try .dds in mod_assets\textures and see if it works.
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: [WIP] GrimTK GUI Framework

Post by Echoplex »

Okay so some progress. When I change the extension in the script to dds it will stop crashing after importing and display the picture as intended. However it will print a console error stating the code does not end with .tga. My understanding is that the script had to end in .tga however now its causing issues for reasons I don't understand.

Code: Select all

function gtkDidLoad()
	GTK.Core.GUI:addImage({ name="davion", path="mod_assets/ext/grimtk/samples/davion.dds", size={192, 192} });
end
So either its .dds and the script works as intended not crashing with the hudprint error or its .tga and it just crashes to desktop. Thoughts?

Edit:

Food for thought in looking at the set portrait script for his custom portrait it reads .dds in the code which exports correctly when playing. I had a similiar problem getting custom portraits exported and I'm getting this itch it has to be placed in a particular folder with the script reading .tga(the file being .dds). My portraits wouldn't show up unless in the mod_assets/textures/portraits folder.

Code: Select all

function addparty2()
	party.party:getChampion(2):setEnabled(true)
	party.party:getChampion(2):setName("Davion")
	party.party:getChampion(2):setSex("male")
	party.party:getChampion(2):setRace("human")
	party.party:getChampion(2):setClass("knight")
	party.party:getChampion(2):removeTrait("aggressive")
	party.party:getChampion(2):removeTrait("head_hunter")
	party.party:getChampion(2):addTrait("endurance")
	party.party:getChampion(2):trainSkill("light_weapons",1,true)
	party.party:getChampion(2):trainSkill("armors",1,true)
	party.party:getChampion(2):trainSkill("dodge",-1,false)
	party.party:getChampion(2):levelUp()
	party.party:getChampion(2):setPortrait("mod_assets/textures/portraits/25_human_male.dds")
	party.party:getChampion(2):insertItem(1,spawn("rusty_long_sword").item)	
    party.party:getChampion(2):insertItem(2,spawn("worn_conscript_shield").item)	
    party.party:getChampion(2):insertItem(3,spawn("worn_dm_armor_steel_barbute").item)
    party.party:getChampion(2):insertItem(4,spawn("worn_ring_mail").item)
    party.party:getChampion(2):insertItem(5,spawn("worn_ring_cuisse").item)
    party.party:getChampion(2):insertItem(6,spawn("worn_ring_greaves").item)
    party.party:getChampion(2):insertItem(9,spawn("worn_ring_gauntlets").item)
    party.party:getChampion(2):insertItem(13,spawn("pitroot_bread").item) 
end
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: [WIP] GrimTK GUI Framework

Post by minmay »

JohnWordsworth wrote:Hmm, I hit this problem the other day with the ORRR3. I have yet to solve the issue (not that I've tried for long), but will have a think about it and post a solution. I'm hoping that a button will block mouse input to the game world, and then I could just place a big button behind every window automatically. Failing that, we might need to disable any surfaces / clickable entities in the spaces around the player and then re-enable them later.
Try GameMode.setEnableControls(false). It stops the player from picking up or throwing items with the mouse.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: [WIP] GrimTK GUI Framework

Post by Echoplex »

Solved the Image issue. When the image was simply placed in the mod_assets/textures/ folder with the script reading .tga it was able to pull it no issues. It seems any other location I had it resulted in a crash due to it not fitting criteria to export. Thanks for the help Min and AndakRainor
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: [WIP] GrimTK GUI Framework

Post by bongobeat »

Hello there, can you help me please?

I got this crash when testing my mod on a mac os x:
SpoilerShow

Code: Select all

=== System Info ===

Game Version:       2.2.6
Computer name:      
CPU Vendor:         
CPU Brand:          Intel(R) Core(TM) i5-3335S CPU @ 2.70GHz
OS Version:         10.8.5
OEM ID:             0
Physical CPUs:      4
Logical CPUs:       4
Page Size:          4096
Total Mem:          8192 MB
Free Mem:           5889 MB

=== GPUs ===

Intel HD Graphics 4000
NVIDIA GeForce GT 640M

=== Settings ===

Render Engine:      opengl
Audio Engine:       openal
Steam:              false
Resolution:         1920 x 1080
Display Mode:       fullscreen (1)
Vertical Sync:      enabled (2)
Texture Resolution: high (3)
Texture Filter:     anisotropic (3)
Shadow Quality:     high (3)
SSAO Quality:       high (3)
Rendering Quality:  high (2)
Max Draw Distance:  1000.000000
Difficulty:         normal
Oldschool Mode:     false
Touchscreen Mode:   false

Loading save game /Users/Bong/Library/Application Support/Almost Human/Legend of Grimrock 2/savegame01.sav
Loading dungeon Theareonan's Revenge by Bongobeat
Game loaded

=== Software Failure ===

mod_assets/grimtk/scripts/gtk/input.lua:280: bad argument #1 to 'keyDown' (string expected, got nil)
stack traceback:
	[C]: in function 'error'
	[string "ScriptInterface.lua"]: in function 'checkArg'
	[string "Gui.lua"]: in function 'keyDown'
	mod_assets/grimtk/scripts/gtk/input.lua:280: in function 'isKeyDown'
	mod_assets/grimtk/scripts/gtk/input.lua:245: in function 'commit'
	mod_assets/grimtk/scripts/gtk/core.lua:847: in function 'update'
	mod_assets/grimtk/scripts/hook.lua:2: in function <mod_assets/grimtk/scripts/hook.lua:1>
	[string "Script.lua"]: in function 'sendMessage'
	[string "Component.lua"]: in function 'triggerConnectors'
	[string "Component.lua"]: in function 'callHook'
	[string "Gui.lua"]: in function 'draw'
	[string "GameMode.lua"]: in function 'update'
	[string "Grimrock.lua"]: in function 'display'
	[string "Grimrock.lua"]: in main chunk
I tried the same thing on the windows pc, and the dialogue works very well, so I don't understand why the mod crash on a mac, or maybe it is a problem with the game version?
I ve downloaded both version on humble, and have the latest patch for the pc version, I did not found any patch for the mac version.

here is the sample involved in this crash (note that I tested another sample on the mac and I got the same crash)
SpoilerShow

Code: Select all

----
-- Simple Message Box Example
----

---- 
-- This code allows you to present a message box with up to two buttons.
----

isDone = false;


function textInputBoxCallback(text)
	if ( text == nil ) then
		hudPrint("You clicked cancel. Interesting...");
		return;
	end

	if ( text == "mushroom" ) or ( text == "Mushroom") then
		local e = findEntity("timer_pass_c2");

		if e then 
			e.timer:start();
			isDone = true;
		end
	else
		hudPrint("Wrong Answer");
	end
end


function showTextInputBox()
	if ( isDone == true ) then
		return
	end

	local title = "Who has a hat but no head, a foot but no shoe?";
	local fieldName = "Password:";
	
	GTKGui.Basic.showTextInputBox(title, fieldName, self.go.id..".script.textInputBoxCallback");
end


function dismissTextInputBox()
	GTKGui.Basic.dismissTextInputBox();
end
it's a message box showing itself when the party get in front of a beacon head, ask a riddles, and the player has to click in the input box, and type the answer of the riddle.

I activate a script related to an external lua file, with a hidden pressure plate:

Code: Select all

TriggeredByParty = yes
OnActivate -> showTextInputBox
OnDeactivate -> dismissTextInputBox
Unfortunately, I can't tell you exactly which Grim TK I use, I did not keep the readme in the directory, so it may be the version Alpha 007 or Alpha 008
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Cashpwns
Posts: 11
Joined: Tue Oct 11, 2016 4:19 am

Re: [WIP] GrimTK GUI Framework

Post by Cashpwns »

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.
SpoilerShow
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,
SpoilerShow
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.
Cashpwns
Posts: 11
Joined: Tue Oct 11, 2016 4:19 am

Re: [WIP] GrimTK GUI Framework

Post by Cashpwns »

Hey, I fixed it! Then it broke, again. my code being embedded, not external.
SpoilerShow
items = { name="lightning_blade", uiName="Here is the Vanguard.", 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);
local obj = spawn(item.name)
shop_altar.surface:addItem(obj.item)
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.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. Its on the altar to your left.",
responses = {
{ text = "Thank you for the gift." },
}
},
}
}

GTKGui.Dialogue.startDialogue(dialogue);
end

function hideDialogue()
GTKGui.Dialogue.hideDialogue();
end
So, yeah. How it broke this time? Its messed up at the part of
SpoilerShow
function buyItem(index)
local vanguard = countInventoryItem("vanguard")
local item = items[index]
With it saying "attempt to call global 'countInvetoryItem' (a nil value)" at local vanguard = countInventoryItem("vanguard")
So, yeah. It would be nice if someone could help me on this.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: [WIP] GrimTK GUI Framework

Post by zimberzimber »

I may be wrong, but I assume the reason behind the crashes is in the following segment (inside showDialogue) -

Code: Select all

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.uiName, onSelect=self.go.id..".script.buyItem" },
{ text = "Alright, I will get the shield for you. <Walk Away>" },
{ text = items.uiName, onSelect=self.go.id..".script.buyItem" }, calls the buyItem function, but it doesn't give it any data.
function buyItem(index) expects to receive data, but it doesn't.
Again, I may be wrong.
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: [WIP] GrimTK GUI Framework

Post by minmay »

I suggest that you review what commas and parentheses mean in Lua. Because this block:

Code: Select all

items = { name="lightning_blade", uiName="Here is the Vanguard.", cost=1
},

function ()countInventoryItem(name)
does NOT do what you wanted it to do. You wanted:

Code: Select all

items = { name="lightning_blade", uiName="Here is the Vanguard.", cost=1
}

function countInventoryItem(name)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply