set_menu_item and debug

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

set_menu_item and debug

Post by vghetto »

Hi,

I created a modification that allows the player to heal or harm any unit on the map with a right-click menu.
The idea is to show these menu items only when the player has typed in :debug

How do I make it appear only after the user switches to :debug?
I tried surrounding the event code with #ifdef DEBUG_MODE but that didn't work.

Also, when the user uses the regular debug commands, like Kill Unit (Debug!), it flashes something on the screen like "player has used a debug command on their turn".
How do I make my mod do the same thing? (have it fire the same event I'm expecting)

This is the code for the mod. It's very short
https://github.com/virtualghetto/Debug_ ... /_main.cfg

Final question, Is it allowed for me to upload this to the addons.wesnoth.org server?
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: set_menu_item and debug

Post by Ravana »

Check if viewtopic.php?t=44432 is suitable for your use case.

It is not against addon server rules, especially because you say it needs debug which allows all that anyways. I have my own debug addon, which I do not upload since I do not require debug mode there.


Specify whether this needs to work in SP or MP.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: set_menu_item and debug

Post by vghetto »

Thank you. I got the first part done with this little snippet

Code: Select all

[lua]
    code = << return wesnoth.game_config.debug >>
[/lua]
I still couldn't figure out the second part, the one that says that a debug command has been used on the players turn so it will appear in the replay. Is there a standard event name that I can fire? or is it more complicated than that?

Edit:
It appears I need to get to the cpp function called debug_cmd_notification, but how?
User avatar
Mathemagician
Posts: 39
Joined: March 24th, 2008, 10:42 pm
Location: Right behind you

Re: set_menu_item and debug

Post by Mathemagician »

A simpler solution might be to use [print]. Though getting the fonts and duration to match up might be finicky.
Formerly NeoPhile
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: set_menu_item and debug

Post by vghetto »

Mathemagician wrote: December 27th, 2019, 9:08 pm A simpler solution might be to use [print]. Though getting the fonts and duration to match up might be finicky.
Thanks I didn't know about the [print] command. I looked back at Gui Debug Tools and saw that [print] was used over there as well. Thank you for drawing my attention to it.

On the other hand debug_notification has some perks, not only is the position of the text different (announce in display.cpp), it interrupts the replay and asks if you'd like to save. And that is the feature that I was hoping for, but this is turning out to be more complicated for a simple basic little mod, so I'm dropping the idea and implemented a basic print tag and no current_player.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: set_menu_item and debug

Post by Ravana »

I am quite sure there is no way to fake debug notices.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: set_menu_item and debug

Post by Celtic_Minstrel »

In order to mimic the built-in debug command notifications, you'd need to define a custom synced command (which is possible with the wesnoth.custom_synced_commands table if I recall correctly), but you'd also need to be able to define the custom command as a debug command (which isn't currently possible). So your present solution is almost certainly the best that can be managed at this time.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply