Sudipta's WML questions

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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Sudipta's WML questions

Post by enclave »

Sudipta wrote: June 15th, 2018, 12:14 pm Uhh, i used the commands u provided but both of them set turn number or turn limit number to 1 regardless of what value i put in it. :?
for example i use turn [8] in debug mode but it sets turn number to 1. using turn_limit [50] sets turn limit to 1.
@enclave thanks for the alternate method but i find ravana's lua suggestions simpler. I'm just starting out so set_menu_item stuff goes over my head for now ;)
try this then :lua wesnoth.fire("modify_turns", { add=5 })
User avatar
Ravana
Forum Moderator
Posts: 2952
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Sudipta's WML questions

Post by Ravana »

You can call every actionwml tag from lua with wesnoth.wml_actions.tag_name{key=value,key2=value2}. But using Lua to call WML to do something that Lua can do directly is not really useful.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Sudipta's WML questions

Post by enclave »

Ravana wrote: June 15th, 2018, 1:37 pm You can call every actionwml tag from lua with wesnoth.wml_actions.tag_name{key=value,key2=value2}. But using Lua to call WML to do something that Lua can do directly is not really useful.
You mean that instead of :lua wesnoth.fire("modify_turns", { add=5 })
Sudipta could just write this: :lua wesnoth.wml_actions.modify_turns { add=5 }
and it would be massively shorter and more simple? ;)
I will actually try to compare performance of these 2 methods with 5k cycle :) just for curiosity.

Ps. i only offered to try this method since there seems to be a problem with proper lua method for Sudipta..
User avatar
Sudipta
Posts: 217
Joined: June 10th, 2015, 6:37 pm
Location: Meditating under a waterfall, Heartfangs, Wesnoth

Re: Sudipta's WML questions

Post by Sudipta »

Both Ravana's and enclave's code works. I'm not gonna argue theory since it's results i care about :D
It is the mark of an educated mind to be able to entertain a thought without accepting it.
Playing Wesnoth since 2010, still there is so much left to play
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Sudipta's WML questions

Post by enclave »

Sudipta wrote: June 15th, 2018, 5:25 pm Uhh, i used the commands u provided but both of them set turn number or turn limit number to 1 regardless of what value i put in it.
for example i use turn [8] in debug mode but it sets turn number to 1. using turn_limit [50] sets turn limit to 1.

Both Ravana's and enclave's code works. I'm not gonna argue theory since it's results i care about :D
Do you mean the example above is working fine now, or did you have to modify it somehow?
User avatar
Sudipta
Posts: 217
Joined: June 10th, 2015, 6:37 pm
Location: Meditating under a waterfall, Heartfangs, Wesnoth

Re: Sudipta's WML questions

Post by Sudipta »

Okay, let me break it down and dissolve whatever confusion there is.

The two lua commands Ravana posted first worked perfectly for me and got the job done. Then Shiki gave me a link of the CommandsWiki(thanks for that) and at first those debug commands didn't work because i included the [ ]. It was later pointed out to me where i was making a mistake and now that works perfectly too. Then enclave posted Lua+WML commands and those work too. So now i know 3 fundamentally different ways of changing turns and turn_limits :D

Now i'm a believer of the KISS principle, so i prefer using the shortest debug commands, but its good to know the alternate techniques. Hopefully that clears it up.
It is the mark of an educated mind to be able to entertain a thought without accepting it.
Playing Wesnoth since 2010, still there is so much left to play
User avatar
Sudipta
Posts: 217
Joined: June 10th, 2015, 6:37 pm
Location: Meditating under a waterfall, Heartfangs, Wesnoth

Re: Sudipta's WML questions

Post by Sudipta »

I need help... again :whistle:

I'm trying to use a Thunder macro to damage all units of the players side, but it doesn't work properly. Short version- the player fights a powerful elf lord, and when you reduce the Lord's hp to 0, he uses a powerful magic to almost kill all the player's units. It triggers in a last breath event. the code of the Thunder macro is

Code: Select all

{THUNDER (
		
		[harm_unit]
			[filter]
				side=1
			[/filter]
			
			amount="($this_unit.hitpoints - 1)"
			kill=no
			
		[/harm_unit]
		
 )}
Basically it leaves all units alive with 1 hp left. But when i run it, i get some lua error messages, and then the scenario ends triggering the victory event. In the previous coding style, i used a modify unit tag to set all unit HP to 1 and that worked. But since harm_unit's looks a lot cooler i wanna use this instead. 8)

i think the error is in the amount attribute. Please advise.
Attachments
this is what shows when the event occurs
this is what shows when the event occurs
It is the mark of an educated mind to be able to entertain a thought without accepting it.
Playing Wesnoth since 2010, still there is so much left to play
User avatar
Pentarctagon
Project Manager
Posts: 5531
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Sudipta's WML questions

Post by Pentarctagon »

Should be "$($this_unit.hitpoints - 1)".
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Sudipta
Posts: 217
Joined: June 10th, 2015, 6:37 pm
Location: Meditating under a waterfall, Heartfangs, Wesnoth

Re: Sudipta's WML questions

Post by Sudipta »

Pentarctagon wrote: June 20th, 2018, 12:49 pm Should be "$($this_unit.hitpoints - 1)".
Silly mistake. :doh: Thanks for pointing it out.

Another thing. How do i stop a unit from dying after its last breath event is triggered? In the above example, after the magic sequence the Elf Lord dies but he shouldn't. I tried using modify unit and and changing the HP but that doesn't prevent his death. I could use a
store_unit tag and kill attribute but i wonder if there's a more elegant solution ?
It is the mark of an educated mind to be able to entertain a thought without accepting it.
Playing Wesnoth since 2010, still there is so much left to play
Smok
Posts: 53
Joined: June 14th, 2016, 11:52 am

Re: Sudipta's WML questions

Post by Smok »

store_unit with kill, then unstore_unit is the most elegant way.
Post Reply