PDA

View Full Version : Debug examples



peterb
April 5th, 2021, 18:20
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

Moon Wizard
April 6th, 2021, 16:28
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

damned
April 6th, 2021, 23:53
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);

LordEntrails
January 11th, 2023, 01:15
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:


<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>

Trenloe
January 11th, 2023, 08:20
You can also put those variables/objects together in a single statement or combined with text (so you know which is which). For example:


Debug.chat("Is visible? sub_window = ", (window.sub_gear.isVisible());

You can have multiple variables:


Debug.chat("Is visible? sub_gear, sub_weapon = ", window.sub_gear.isVisible(), window.sub_gear.isVisible());

Xarxus
January 15th, 2023, 11:22
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.

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