on_event context

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

Moderator: Forum Moderators

white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: on_event context

Post by white_haired_uncle »

You want to use on_event to create a preload event? I really don't think that will work, since on_event would need to be in preload. You'd be creating an event after it has already started, or just hoping your new one would be called once the current one is done. Even if it worked, I'm missing the point (though that happens a lot).
Speak softly, and carry Doombringer.
User avatar
hermestrismi
Posts: 730
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: on_event context

Post by hermestrismi »

white_haired_uncle wrote: July 21st, 2024, 5:31 am You want to use on_event to create a preload event? I really don't think that will work, since on_event would need to be in preload. You'd be creating an event after it has already started, or just hoping your new one would be called once the current one is done. Even if it worked, I'm missing the point (though that happens a lot).
it is just a theoric approach. I was thinking that all I need is the table (potion_location) and the image file. so, I thought of two solutions: either create a wml variables (x,y,pot,image) and then a wml event (turn refresh ..) to check and redraw. or stick with lua and pass the table as a parameter or condition (if #potion_location ~= 0 then..) to a 'on_event preload'.
well, the second option is not possible from the wiki. preload events can't handle such lua code
User avatar
Ravana
Forum Moderator
Posts: 3313
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: on_event context

Post by Ravana »

on_event has to run during preload, you can just do what you need instead of creating new preload event that will never be used.
white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: on_event context

Post by white_haired_uncle »

hermestrismi wrote: July 21st, 2024, 5:38 am
it is just a theoric approach. I was thinking that all I need is the table (potion_location) and the image file. so, I thought of two solutions: either create a wml variables (x,y,pot,image) and then a wml event (turn refresh ..) to check and redraw. or stick with lua and pass the table as a parameter or condition (if #potion_location ~= 0 then..) to a 'on_event preload'.
well, the second option is not possible from the wiki. preload events can't handle such lua code
I looked at the persistent_tags wiki entry and couldn't make much sense of it.

Personally, I would just use wml.array_access.get and wml.array_access.set to keep potion_location in sync with a WML array, and then create my events with
wesnoth.add_event_handler.

I suspect wml.array_access.get_proxy would be preferable to wml.array_access.get and wml.array_access.set, but I've never played with it.
Speak softly, and carry Doombringer.
gnombat
Posts: 892
Joined: June 10th, 2010, 8:49 pm

Re: on_event context

Post by gnombat »

hermestrismi wrote: July 21st, 2024, 5:24 am thank you for details. I should know that, really. I get much time to code it. I tried to use persistent tags but I m not familiar with and looks hard for me (I need much time of try and lose).
is there any exemple (commented for steps and details) that can help other than the one in the wiki?
There appears to be a working example of persistent tags in the tutorial campaign.
User avatar
hermestrismi
Posts: 730
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: on_event context

Post by hermestrismi »

gnombat wrote: July 21st, 2024, 10:41 am
hermestrismi wrote: July 21st, 2024, 5:24 am thank you for details. I should know that, really. I get much time to code it. I tried to use persistent tags but I m not familiar with and looks hard for me (I need much time of try and lose).
is there any exemple (commented for steps and details) that can help other than the one in the wiki?
There appears to be a working example of persistent tags in the tutorial campaign.
thank you. I am surprised that it is easier than I thought with this tutorial 😅 😳 I should not have prejudices
User avatar
Celtic_Minstrel
Developer
Posts: 2371
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: on_event context

Post by Celtic_Minstrel »

hermestrismi wrote: July 21st, 2024, 5:24 am is there any exemple (commented for steps and details) that can help other than the one in the wiki?
There are some examples in core, I believe
hermestrismi wrote: July 21st, 2024, 5:24 am and what if I on_event to create a preload_event just like the move to one?
I think there's mostly no point in doing that. It probably works if you put it in a global Lua tag, but at that point, what's the difference from just putting your code there without using an event? There may be some cases where that's useful, but this isn't one of them.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply