[unsolvable] Access event content

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

Moderator: Forum Moderators

Post Reply
User avatar
ZombieKnight
Posts: 337
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

[unsolvable] Access event content

Post by ZombieKnight »

Hi,
How to access event content via Lua?
Last edited by ZombieKnight on May 16th, 2024, 7:17 am, edited 1 time in total.
User avatar
Celtic_Minstrel
Developer
Posts: 2340
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Access event content

Post by Celtic_Minstrel »

There's no official way. If wesnoth.scenario.__cfg exists, you might be able to get them from there.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 337
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Access event content

Post by ZombieKnight »

Double checked I can't do it.
User avatar
Ravana
Forum Moderator
Posts: 3189
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [unsolvable] Access event content

Post by Ravana »

It probably does not catch everything, but you can overwrite wesnoth.wml_actions.event to save what is given to it.
User avatar
ZombieKnight
Posts: 337
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [unsolvable] Access event content

Post by ZombieKnight »

Ravana wrote: May 16th, 2024, 8:18 am It probably does not catch everything, but you can overwrite wesnoth.wml_actions.event to save what is given to it.
True... but how to notice when it's fired?
User avatar
Celtic_Minstrel
Developer
Posts: 2340
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [unsolvable] Access event content

Post by Celtic_Minstrel »

Maybe queue a second event with the exact same conditions? Or insert extra code at the start of the event that does whatever you need it to do?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
white_haired_uncle
Posts: 1444
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [unsolvable] Access event content

Post by white_haired_uncle »

ZombieKnight wrote: May 7th, 2024, 10:53 am Hi,
How to access event content via Lua?
I'm pretty sure I don't understand what you are asking, but if you mean you want to access (read) events you've written in WML from lua, could the answer be as simple as just writing them in lua in the first place?

Or some combination of wesnoth.game_events.on_event and wesnoth.current.event_context ?
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 337
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [unsolvable] Access event content

Post by ZombieKnight »

... hmm not sure
Can I use wesnoth.game_events.on_event and wesnoth.current.event_context to re-create all those events (right after I erase them)?
white_haired_uncle
Posts: 1444
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [unsolvable] Access event content

Post by white_haired_uncle »

I don't know, I've never used them. But for those I was thinking about your question about 'how to notice when it's fired'.

If you want to erase them (the events) and recreate them, you could:

1) Since you want to do this from lua, just write them in lua in the first place, save them as variables, and delete (fire remove_event) and re-create them as you please.

2) Just have all of your events check a variable $disable_all_events (or something) so you don't delete them, just disable them.

3) If you want to write the events in WML, use Ravana's neat trick to keep them in a separate file so you can (re-)load them from lua. I think it's just a tiny bit more complicated than I have described, since you'd need to load an action which creates them (you want to create them, not execute them), but I doubt that's too tricky.

Now, if you don't know the id's (I assume you'll have to have id's on all your events) ahead of time for some reason, you'd have to be able to get a list of them dynamically. No idea there.
Speak softly, and carry Doombringer.
User avatar
ZombieKnight
Posts: 337
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [unsolvable] Access event content

Post by ZombieKnight »

Hmm
... I see
I wanted to save and load anything at any time.
Post Reply