5E Product Walkthrough Playlist

Thread: Debug examples

  1. #1

    Join Date
    Mar 2009
    Location
    Lidingö, Sweden, Europe
    Posts
    351

    Debug examples

    Hi all,

    I don't get the debug function to work. I've tried Debug.chat(variable) and Debug.console(variable) but I get no output. I've also tried printstack() but with the same result - no output. The print function does produce output but only in the top level of a function. Even though I now that a certain deeper level code will get executed the print statement doesn't produce any output. I can see the changes the code produces in the character sheet, but in the current case gets no printout of the calculations, it's quite frustrating. Anyhow, if anyone has any working examples of how to use the debug functions that they like to share, that would be appreciated.

    TIA,
    Peter

  2. #2
    I use these every day in my work.

    Debug.chat(...)
    Debug.console(...)
    Debug.printstack()

    The first one outputs the variables separated by pipe symbols to the chat window (if defined), otherwise to the console.
    The second one outputs the variables separated by pipe symbols to the console.
    The third one outputs the current Lua call stack.

    To access the console, type /console while FG is running. If the debug statements run before the console is open, they may not appear.
    All console messages are output to the console.log file located in the FG data folder.

    Regards,
    JPG

  3. #3
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    I use soooo many Debug statements when Im coding stuff.
    My best guess is that its either not running the code the way you think it is or its running from another copy of the ruleset (unpacked vs packed) etc?
    Debug.chat("onLanded", rRoll, rSource);

  4. #4
    LordEntrails's Avatar
    Join Date
    May 2015
    Location
    -7 UTC
    Posts
    17,147
    Blog Entries
    9
    Revising an old thread because the topic is perfect

    So some more info from Moon regarding Debug Statement:

    Debug.chat(window.control); will return the control information
    Debug.chat(window); will return the window information.
    Debug.chat(window.control.isVisible); will return "fn" because it's just a function variable.
    Debug.chat(window.control.isVisible()); will return the returned value from the execution of the isVisible function for that object. (Make sure you have not accidentally overriden the isVisible API inside the function.)
    Here is an example of returning the a couple of different values from within the script of a window that has a combobox used to show and hide sub windows (i.e. so that an Item window appears to have different fields depending upon the item type:

    Code:
         <rsw_combobox name="item_type">
            <frame>
              <name>fielddark</name>
              <offset>8,0,8,0</offset>
            </frame>
            <bounds>88,40,59,30</bounds>
            <empty textres="item_item_type_EmptyText" />
            <listdirection>down</listdirection>
            <script>function onInit()
        super.onInit();
        onValueChanged();    
    
    super.onInit();
    add("gear","Gear");
    add("weapon","Weapon");
    add("defense","Defense");
    add("scanner","Scanner");
    add("implant","Implant");
    end    
    
    function onValueChanged()
        Debug.chat(getValue());
        if getValue() == '' then
            setValue("gear");
        end
    
        getValue()
        if getValue() == 'Gear' then
            window.sub_gear.setVisible(true);
            window.sub_weapon.setVisible(false);
            window.sub_defense.setVisible(false);
            window.sub_scanner.setVisible(false);
            window.sub_implant.setVisible(false);
        elseif getValue() == 'Weapon' then
            window.sub_gear.setVisible(false);
            window.sub_weapon.setVisible(true);
            window.sub_defense.setVisible(false);
            window.sub_scanner.setVisible(false);
            window.sub_implant.setVisible(false);
        elseif getValue() == 'Defense' then
            window.sub_gear.setVisible(false);
            window.sub_weapon.setVisible(false);
            window.sub_defense.setVisible(true);
            window.sub_scanner.setVisible(false);
            window.sub_implant.setVisible(false);
        elseif getValue() == 'Scanner' then
            window.sub_gear.setVisible(false);
            window.sub_weapon.setVisible(false);
            window.sub_defense.setVisible(false);
            window.sub_scanner.setVisible(true);
            window.sub_implant.setVisible(false);
        elseif getValue() == 'Implant' then
            window.sub_gear.setVisible(false);
            window.sub_weapon.setVisible(false);
            window.sub_defense.setVisible(false);
            window.sub_scanner.setVisible(false);
            window.sub_implant.setVisible(true);
        end
            Debug.chat("Return sub Window statuses")
            Debug.chat(window.sub_gear.isVisible());
            Debug.chat(window.sub_weapon.isVisible());
            Debug.chat(window.sub_defense.isVisible());
            Debug.chat(window.sub_scanner.isVisible());
            Debug.chat(window.sub_implant.isVisible());
    end
    </script>
          </rsw_combobox>

    Problems? See; How to Report Issues, Bugs & Problems
    On Licensing & Distributing Community Content
    Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
    Note, I am not a SmiteWorks employee or representative, I'm just a user like you.

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    You can also put those variables/objects together in a single statement or combined with text (so you know which is which). For example:

    Code:
    Debug.chat("Is visible?  sub_window = ", (window.sub_gear.isVisible());
    You can have multiple variables:

    Code:
    Debug.chat("Is visible?  sub_gear, sub_weapon  = ", window.sub_gear.isVisible(), window.sub_gear.isVisible());
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  6. #6
    Xarxus's Avatar
    Join Date
    Mar 2019
    Location
    Rome (Italy)
    Posts
    244
    You can combine Debug with string.format, but you have to remember that Debug automatically converts
    every parameter to string, string.format doesn't, so you have to convert explicitly.
    Code:
    Debug.console(string.format("%s control: visibility is %s and readonly is %s", getName(), tostring(isVisible()), tostring(isReadOnly())));
    Output: RaceName control: visibility is true and readonly is true
    FGU ULTIMATE License
    Click here for RPG Music or here for Dwarves songs on Spotify

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in