enclave's Lua thread

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

Moderator: Forum Moderators

Post Reply
shrieker1
Posts: 21
Joined: August 7th, 2017, 5:53 pm

Re: enclave's Lua thread

Post by shrieker1 »

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.
User avatar
Pentarctagon
Project Manager
Posts: 5527
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: enclave's Lua thread

Post by Pentarctagon »

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
shrieker1
Posts: 21
Joined: August 7th, 2017, 5:53 pm

Re: enclave's Lua thread

Post by shrieker1 »

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

Re: enclave's Lua thread

Post by enclave »

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

Re: enclave's Lua thread

Post by enclave »

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

Re: enclave's Lua thread

Post by Ravana »

helper is needed for some functions (helper.*), T is just shortcut.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

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

Re: enclave's Lua thread

Post by enclave »

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

Re: enclave's Lua thread

Post by enclave »

Hi,
Anyone knows what variables I could access with wesnoth.game_events.on_load for replays?

Mainly, could I possible find out the number of total turns replay has on_load? Or could it get the variable value from eg. turn 10 on_load?

Secondly, could I modify any kind of global variable with wesnoth.game_events.on_save that it could be used when loading replay?

What I'm trying to achieve is to display a different replay depending on some variable that happened on save (somewhere late in game).
Or in details I want to disable loading game AND replay depending on turn number.

This would have extreme value for ladder games, cheating then would require more advanced skills than just saving/reloading game to look enemy recruits or positions.

So far I have managed to:
1) disable saving game (for example until turn 3) by corrupting the savefile, but saving replay is still possible. Therefore you can not reload game (success), but can watch the replay (failure).
2) saving game or replay works no problem, but on loading game (before turn 3) it stucks in a neverending loop, so you cannot reload saved game (success).
The replay does the same, but it doesnt care about turn number, so it's just always in a loop, no matter at which turn number it was saved (failure).

The best I can do with my knowledge is to TRY to create some 5-10 minutes delay for replay to start loading. It would fix the problem in an ugly way.
But Maybe there is a nice way? I really need very advanced knowledge here...
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

Maybe just corrupt the replay and create your secret script to fix it that could run in ladder server.
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: enclave's Lua thread

Post by Choicerer »

How would you go on about corrupting the replay, though? I'm interested myself, because I've been trying to help enclave with this.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

2) saving game or replay works no problem, but on loading game (before turn 3) it stucks in a neverending loop, so you cannot reload saved game (success).
The replay does the same, but it doesnt care about turn number, so it's just always in a loop, no matter at which turn number it was saved (failure).
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Ravana wrote: July 6th, 2018, 1:36 pm Maybe just corrupt the replay and create your secret script to fix it that could run in ladder server.
I guess you mean to create some code using separate software (like PHP, javascript, c++, excel VBA, delphi, python etc), to be able to modify the replay file directly myself to fix the neverending loop on turn 1 just by modifying the preload variable, by modifying the savefile via third party programm code..
But I don't have any affect on ladder webpage, i have no influence over ladder. I just want to make a modification to give players an option to protect themselves from basic cheating..
For that I need a lua/WML solution...
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: enclave's Lua thread

Post by Choicerer »

enclave wrote: July 6th, 2018, 7:25 pm
Ravana wrote: July 6th, 2018, 1:36 pm Maybe just corrupt the replay and create your secret script to fix it that could run in ladder server.
I guess you mean to create some code using separate software (like PHP, javascript, c++, excel VBA, delphi, python etc), to be able to modify the replay file directly myself to fix the neverending loop on turn 1 just by modifying the preload variable, by modifying the savefile via third party programm code..
But I don't have any affect on ladder webpage, i have no influence over ladder. I just want to make a modification to give players an option to protect themselves from basic cheating..
For that I need a lua/WML solution...
That would actually work, yeah. You can write a program that would "heal" every single replay, but yeah... It's not the most convenient solution. While fixing the team chat bug, I took a look at replay.cpp, maybe if I dive in some more, I could come up with some way to break it? I could try later on, although I don't have high hopes.
One should probably start with examining the replay files themselves, perhaps there is some variable you could retrieve that stores the last turn.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Choicerer wrote: July 6th, 2018, 8:06 pm One should probably start with examining the replay files themselves, perhaps there is some variable you could retrieve that stores the last turn.
when i looked I couldn't find anything useful with my level of knowledge.
I hope gfgtdf or somebody with highest level of Wesnoth knowledge could confirm that there is no known way to do it...
Post Reply