[unsolvable] Access event content
Moderator: Forum Moderators
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[unsolvable] Access event content
Hi,
How to access event content via Lua?
How to access event content via Lua?
Last edited by ZombieKnight on May 16th, 2024, 7:17 am, edited 1 time in total.
- Celtic_Minstrel
- Developer
- Posts: 2340
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Access event content
There's no official way. If
wesnoth.scenario.__cfg
exists, you might be able to get them from there.- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Access event content
Double checked I can't do it.
Re: [unsolvable] Access event content
It probably does not catch everything, but you can overwrite wesnoth.wml_actions.event to save what is given to it.
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: [unsolvable] Access event content
True... but how to notice when it's fired?
- Celtic_Minstrel
- Developer
- Posts: 2340
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [unsolvable] Access event content
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?
-
- Posts: 1444
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: [unsolvable] Access event content
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.
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: [unsolvable] Access event content
... 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)?
Can I use wesnoth.game_events.on_event and wesnoth.current.event_context to re-create all those events (right after I erase them)?
-
- Posts: 1444
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: [unsolvable] Access event content
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.
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.
- ZombieKnight
- Posts: 337
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: [unsolvable] Access event content
Hmm
... I see
I wanted to save and load anything at any time.
... I see
I wanted to save and load anything at any time.