[SOLVED] select hex
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.
Re: select hex
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]
Re: select hex
y like i said before... it gives errorRavana 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]
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..[string "..."]:7: attempt to call a nil value (upvalue 'old_callback') stack traceback: [string "..."]:7: in function <[string "..."]:3>
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.
Re: [SOLVED] select hex
Maybe for on_mouse_action saving old callback isnt needed then. For other callbacks it is needed.
Re: [SOLVED] select hex
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.
Re: [SOLVED] select hex
Yeah this one tested and 100% working. No error message. Thank you very much gfgtdf!gfgtdf wrote: ↑October 28th, 2018, 2:24 pmCode: 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]
Re: [SOLVED] select hex
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