how do you debug and/or log message?
Moderator: Forum Moderators
how do you debug and/or log message?
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
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: how do you debug and/or log message?
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.
--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 starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: how do you debug and/or log message?
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?
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?
Re: how do you debug and/or log message?
You can press F5 (Control-F5 on a Mac) to reload the cache without having to exit and relaunch.
Re: how do you debug and/or log message?
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.8680 wrote:You can press F5 (Control-F5 on a Mac) to reload the cache without having to exit and relaunch.
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?
- Elvish_Hunter
- Posts: 1576
- Joined: September 4th, 2009, 2:39 pm
- Location: Lintanir Forest...
Re: how do you debug and/or log message?
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: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?
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)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?
Code: Select all
[lua]
code=<<wesnoth.dofile "~add-ons/The_Sojournings_of_Grog/lua/wml-tags.lua">>
[/lua]
By choosing Multiplayer -> Local game.salade wrote:Is there a way to start a non-network game to test an Era addon?
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)
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: how do you debug and/or log message?
Start the clients with the --debug switch from above and it will be enabled.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.")
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...)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.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign