how do you debug and/or log message?

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
salade
Posts: 50
Joined: January 3rd, 2011, 5:48 am

how do you debug and/or log message?

Post by salade »

hi, I'm new to Lua development in Wesnoth. Just trying to write some simple lua code for a task, and I wonder how to log and debug lua. e.g. if i want to print the value of a variable on screen or in a log file or whatever console if there is one, how to do so? i heard that Wesnoth client could be started in a debug mode, where can i find information about that? tyvm
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: how do you debug and/or log message?

Post by Anonymissimus »

Launch wesnoth with command line arguments
--debug --log-debug=scripting/lua
and put wesnoth.message(var)
into your code (without --log ... it outputs only a chat message).
You may find the "dbms" function in the wesnoth lua pack interesting.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
salade
Posts: 50
Joined: January 3rd, 2011, 5:48 am

Re: how do you debug and/or log message?

Post by salade »

thx. i'm able to print out a message in chat now. with --log-debug=scripting/lua (and i also tried --log-info=scripting/lua), i'm not sure where the log file go. where is the default log path? or what is the log file name? (so i could do a full search to look for it) there is a blank stdout.txt (it maybe because i've started 2 wesnoth client from the same installation, not sure)

another question about lua development. whenever i make a change, i need to restart the wesnoth client for the change to take effect. is there any better way to develop? like any parameter to disable cache or sth like that?
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: how do you debug and/or log message?

Post by 8680 »

You can press F5 (Control-F5 on a Mac) to reload the cache without having to exit and relaunch.
salade
Posts: 50
Joined: January 3rd, 2011, 5:48 am

Re: how do you debug and/or log message?

Post by salade »

8680 wrote:You can press F5 (Control-F5 on a Mac) to reload the cache without having to exit and relaunch.
thx. just to add that we have to exit to the Wesnoth main menu for the F5 key to work. Tried it and it isn't the thing I'm looking for, as the reload still take too long.

I think what I want is to run lua in command mode. The problem i got now is, I'm trying to develop/modify an Era that is for multiplier games. If I start a multi-player game, the debug mode is disabled. (wiki: DebugMode: "Debug mode is disabled when you play a network multiplayer game.") Is there a way to start a non-network game to test an Era addon?
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: how do you debug and/or log message?

Post by Elvish_Hunter »

salade wrote:if i want to print the value of a variable on screen or in a log file or whatever console if there is one, how to do so?
Another option, other than those already said by Anonymissimus, is to use the print() command: the output will be printed on the console, or on stderr.txt on Windows.
salade wrote:whenever i make a change, i need to restart the wesnoth client for the change to take effect. is there any better way to develop?
Reloading is necessary only if you embed your Lua code inside a cfg file. You can place a [lua] tag with a wesnoth.dofile inside your _main.cfg, and place all your Lua code inside a .lua file (example)

Code: Select all

[lua]
	code=<<wesnoth.dofile "~add-ons/The_Sojournings_of_Grog/lua/wml-tags.lua">>
[/lua]
Or you can place the [lua] wesnoth.dofile inside an [event] name=preload first_time_only=no in each scenario where you need it. In both ways, you'll need only to reload a savegame to have changes taking effect. You can also try placing a [lua] wesnoth.dofile inside a [set_menu_item] [command], to reload Lua code using the right-click menu - although I never tried this way.
salade wrote:Is there a way to start a non-network game to test an Era addon?
By choosing Multiplayer -> Local game.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: how do you debug and/or log message?

Post by Anonymissimus »

salade wrote:If I start a multi-player game, the debug mode is disabled. (wiki: DebugMode: "Debug mode is disabled when you play a network multiplayer game.")
Start the clients with the --debug switch from above and it will be enabled.
Elvish_Hunter wrote:You can also try placing a [lua] wesnoth.dofile inside a [set_menu_item] [command], to reload Lua code using the right-click menu - although I never tried this way.
Quickest way - you don't even need to reload a savegame. See in the era mentioned above for an example (which I updated just yesterday). Another way is to place the same command in the :lua command line (I tend to misspell at least 3 times when doing that...)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Post Reply