[SOLVED] select hex

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.
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: select hex

Post by Ravana »

Just saving old function and calling it after you have done what you need.

Code: Select all

[event]
	name=preload
	first_time_only=no
	[lua]
		code = <<
			local old_callback = wesnoth.game_events.on_mouse_action
			function wesnoth.game_events.on_mouse_action(x,y)       	
				wesnoth.message("You clicked your mouse on hex with coordinates ("..tostring(x)..","..tostring(y)..")")
				return old_callback(x,y)
			end
		>>
	[/lua]
[/event]
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: select hex

Post by enclave »

Ravana wrote: October 28th, 2018, 1:45 am Just saving old function and calling it after you have done what you need.

Code: Select all

[event]
	name=preload
	first_time_only=no
	[lua]
		code = <<
			local old_callback = wesnoth.game_events.on_mouse_action
			function wesnoth.game_events.on_mouse_action(x,y)       	
				wesnoth.message("You clicked your mouse on hex with coordinates ("..tostring(x)..","..tostring(y)..")")
				return old_callback(x,y)
			end
		>>
	[/lua]
[/event]
y like i said before... it gives error
[string "..."]:7: attempt to call a nil value (upvalue 'old_callback') stack traceback: [string "..."]:7: in function <[string "..."]:3>
but this time it also shows message unlike in my trials yesterday.. not sure if i fail to copy/paste your code.. ill try that now..
Yeah with your code copy/pastied it's same error just string 3 not 7.

PS. adamant maybe try if you can attack a unit on that hex which is displaying the message or try if you can select your own unit standing on that hex that displays message... maybe Ravana means you will suppress anything else by displaying the message... for experiments use command line ":" , type there "debug" and then you can put or delete units with right click of mouse. You can also use "fog" and "shroud" to remove fog or shroud.
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [SOLVED] select hex

Post by Ravana »

Maybe for on_mouse_action saving old callback isnt needed then. For other callbacks it is needed.
gfgtdf
Developer
Posts: 1431
Joined: February 10th, 2013, 2:25 pm

Re: [SOLVED] select hex

Post by gfgtdf »

Ravana wrote: October 28th, 2018, 2:06 pm Maybe for on_mouse_action saving old callback isnt needed then. For other callbacks it is needed.
while it is not strictly needed here, it's still better to do it, for example to be compatible with other addons that might also use on_mouse_action as the error message suggests the old callback might be nil though so you have to take care of that :

Code: Select all

	[lua]
		code = <<
			local old_callback = wesnoth.game_events.on_mouse_action or (function() end)
			function wesnoth.game_events.on_mouse_action(x,y)       	
				wesnoth.message("You clicked your mouse on hex with coordinates ("..tostring(x)..","..tostring(y)..")")
				return old_callback(x,y)
			end
		>>
	[/lua]
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: [SOLVED] select hex

Post by enclave »

gfgtdf wrote: October 28th, 2018, 2:24 pm

Code: Select all

	[lua]
		code = <<
			local old_callback = wesnoth.game_events.on_mouse_action or (function() end)
			function wesnoth.game_events.on_mouse_action(x,y)       	
				wesnoth.message("You clicked your mouse on hex with coordinates ("..tostring(x)..","..tostring(y)..")")
				return old_callback(x,y)
			end
		>>
	[/lua]
Yeah this one tested and 100% working. No error message. Thank you very much gfgtdf!
User avatar
Adamant14
Posts: 962
Joined: April 24th, 2010, 1:14 pm

Re: [SOLVED] select hex

Post by Adamant14 »

The code works fine, I thank you very much. You all.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Post Reply