Scroll of showing/hiding Console.warn() messages

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!
Post Reply
Zo Kath Ra
Posts: 829
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Scroll of showing/hiding Console.warn() messages

Post by Zo Kath Ra » Tue Jan 22, 2019 11:11 pm

warning! game object property not saved: scope_camera.camera.camera
viewtopic.php?p=117051#p117051

Workaround:

Code: Select all

-- Scroll that lets you toggle Console.warn() messages
-- Usage:
-- 1) Place a counter named "console_warnings_counter"
-- 2) Place a "console_warnings" object (name doesn't matter)
-- 3a) To show Console.warn() messages by default: Place a "console_warnings_show" object and set "console_warnings_counter" to 1
-- 3b) To hide Console.warn() messages by default: Place a "console_warnings_hide" object and set "console_warnings_counter" to 0

-- This invisible object sets Console.setSuppressWarnings() when you start a new game or load a savegame
-- Necessary because Console.setSuppressWarnings() is reset to "false" when you start LoG2, but remembered across saves while LoG2 is running
defineObject{
    name = "console_warnings",
    baseObject = "base_item",
    components = {
        {
            class = "Null",
            onInit = function(self)
                local console_warnings_counter = findEntity("console_warnings_counter")
                
                if console_warnings_counter then
                    if console_warnings_counter.counter:getValue() == 0 then
                        --print("console_warnings: hide")
                        Console.setSuppressWarnings(true)
                    elseif console_warnings_counter.counter:getValue() == 1 then
                        --print("console_warnings: show")
                        Console.setSuppressWarnings(false)
                    else
                        print("console_warnings: console_warnings_counter is neither 0 nor 1")
                    end
                else
                    print("console_warnings: console_warnings_counter doesn't exist")
                end
            end,
        },
    },
    minimalSaveState = true,
}

defineObject{
    name = "console_warnings_show",
    baseObject = "base_item",
    components = {
        {
            class = "Model",
            model = "assets/models/items/waxseal_note.fbx",
        },
        {
            class = "Item",
            uiName = "Console Warnings are shown",
            description = "Use this item to toggle showing/hiding of Console.warn() messages",
            gfxIndex = 454,
            weight = 0.1,
        },
        {
            class = "UsableItem",
            emptyItem = "console_warnings_hide",
            sound = "spell_fizzle",
            onInit = function(self)
                --print("console_warnings_show: init")
                console_warnings_counter.counter:setValue(1)
                Console.setSuppressWarnings(false)
            end,
        },
    },
}

defineObject{
    name = "console_warnings_hide",
    baseObject = "base_item",
    components = {
        {
            class = "Model",
            model = "assets/models/items/waxseal_note.fbx",
        },
        {
            class = "Item",
            uiName = "Console Warnings are hidden",
            description = "Use this item to toggle showing/hiding of Console.warn() messages",
            gfxIndex = 454,
            weight = 0.1,
        },
        {
            class = "UsableItem",
            emptyItem = "console_warnings_show",
            sound = "consume_potion",
            onInit = function(self)
                --print("console_warnings_hide: init")
                console_warnings_counter.counter:setValue(0)
                Console.setSuppressWarnings(true)
            end,
        },
    },
}

Pompidom
Posts: 476
Joined: Sun May 06, 2018 9:42 pm

Re: Scroll of showing/hiding Console.warn() messages

Post by Pompidom » Wed Jan 23, 2019 1:36 am

Exactly what I was looking for! Thanx!

Post Reply