enclave's Lua thread

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

Re: enclave's Lua thread

Postby shrieker1 » September 14th, 2017, 8:23 pm

enclave wrote:Sorry I found answer to my question.. for some reason wesnoth.delay(500) after message has worked very well! I guess if i decrease it from 500 into 1 it will work same well.. Thanks everyone for attention.. However I'm not sure if this way it is the most efficient, so if anyone knows better way? Then please reply.


Most of stuff that scripts can do without blocking are simple modifying wesnoth internal state without triggering rending code. Good examples of similar behavior are adding overlays and placing units. Both simple modify the state and one has to request redraw explicitly using the redraw tag.

wesnoth.delay actually could be called with delay 0 and it would still inform core Wesnoth to act on the state changes. I don't know any better method to tell Wesnoth core to render the updated state.

If you call delay with nonzero parameter it looks like minimum wait is 10 milliseconds with current implementation. It is a loop calling calling core game to update display every 10 ms until requested time has happened. It needs to keep calling core because there might be some network data to process and update to the screen.

Alternative to wesnoth.message (same as wml [chat] tag in practice) would be using [print] that has long enough duration so you can update it with a new progress value before it disappears. It is about same as wesnoth.float_label but I don't think there is anyway to make float_label appear in middle of playing area. wesnoth.fire or wml_action_metatable are easy way to access wml tags.
shrieker1
 
Posts: 21
Joined: August 7th, 2017, 5:53 pm

Re: enclave's Lua thread

Postby Pentarctagon » September 15th, 2017, 12:12 am

What about [redraw]?
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
Pentarctagon
Forum Administrator
 
Posts: 2972
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: enclave's Lua thread

Postby shrieker1 » September 15th, 2017, 2:22 pm

Pentarctagon wrote:What about [redraw]?


I don't know all details of difference But following at least applies
* wesnoth.delay(0) process input events and then updates only invalidate areas of the map (It would allow user to scroll around)
* redraw invalidates renders whole map again but delay would only run default rendering without invalidating the map

[redraw] of course has advantages for others cases. Example it allows updating shroud and fog after placing new units or modifying movement or vision of a unit. Invalidate is also required if changing unit look (like halos/overlays) because without invalidate Wesnoth might skip rendering that part of map.
shrieker1
 
Posts: 21
Joined: August 7th, 2017, 5:53 pm

Re: enclave's Lua thread

Postby enclave » September 18th, 2017, 8:14 pm

Thank you Shrieker! I had the delay on 1 but I will keep in mind that 0 is also an option, doesn't make much difference, but when you summ all the 1.. may become a significant total delay :) my loop is quite small so I will not even change it probably.. but will definitly do 0 in future.
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » October 3rd, 2017, 5:30 pm

Hi everyone, simple question.. Thanks in advance!
I remember the following code below was needed to use lua.. but things like wesnoth.set_terrain and other terrain lua functions worked fine without it..
Could somebody clarify, what exactly the code below does?
Looks to me now that is something to do with tables and possibly dialogs.. or just to shorten some kind of functions.. no clue to be honest..
Code: Select all
[lua]
code = <<
helper = wesnoth.require "lua/helper.lua"
T = helper.set_wml_tag_metatable {}
>>
[/lua]
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby Ravana » October 3rd, 2017, 5:41 pm

helper is needed for some functions (helper.*), T is just shortcut.
User avatar
Ravana
Moderator
 
Posts: 1477
Joined: January 29th, 2012, 12:49 am
Location: Estonia

Re: enclave's Lua thread

Postby enclave » October 9th, 2017, 7:02 am

Thx Ravana for your reply!

A new question:
If I have a unit with [variables] tag, which also has [ranged] tag inside..
Code: Select all
[unit]
...
[variables]
...
[ranged]
damage=2
[/ranged]
...
[/variables]
..
[/unit]

And then I would need to access the ranged array from lua... how would I do that?
Code: Select all
local wunit = wesnoth.get_displayed_unit()
if (wunit.variables.ranged.damage==2) then
this way it says "attempt to index field 'ranged' (a nil value)
I tried ranged[0].damage, ranged[1].damage but obviously no luck.. so I'm asking here =] Thanks in advance!
I don't have to necessarily use ranged array inside variables.. but it looks better this way and I would like to know if there is a way to keep things like that..?
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Postby enclave » October 13th, 2017, 2:00 am

A few new questions.. wesnoth 1.12
I have the following code:
Spoiler:

It places village overlay to the tile.. so that I could filter terrains using "*^V*" terrain filter and so that hex was treated as village..
Then it sets the village owner to current side.. then it places village picture on the hex and then it places flag halo image on hex..

I have few problems..
1) halo is displayed for all teams.. it doesn't care about "team_name" tag at all.. can it be fixed? really tragic..
2) really minor, but still.. there is no fog overlay on top of halo when it is covered in fog.. it stays same bright and clear and colorful as if there was no fog.. fix in 1.13?
PS. I tried to use [item] tag in WML and halo still displayed for all teams. It's sad, second time I'm trying to code something using halo and it turns to be useless again :(
PPS. visible_in_fog also has no affect on halo? :((((
If it does not follow most of the [item] keys, then maybe it should be moved into separate WML tag to avoid confusions? [halo]
enclave
 
Posts: 533
Joined: December 15th, 2007, 8:52 am

Previous

Return to Lua Labs

Who is online

Users browsing this forum: No registered users and 3 guests