Accessing Lua Tables declared in other contexts

S3rgeus

Emperor
Joined
Apr 10, 2011
Messages
1,270
Location
London, United Kingdom
Currently, I'm wrestling with the notification system and I think I've got a starting point for how I can approach creating more flexible notifications that are more easily specified and can be called up nicely from either within the DLL or Lua. (I've seen Sneaks's Custom Notifications mod, but I believe that's limited by not being able to have notifications that open new Lua popups or notifications that prevent the player from ending their turn.)

One thing I would like to avoid is having to replace NotificationPanel.lua, which I believe I can work around doing if it's at all possible for me to access the "g_ActiveNotifications" table from another context aside from the one NotificationPanel itself is in. Is this possible?

I'm unfamiliar with the specifics of how Contextptr works, but I understand it can be used to call functions in other contexts. I'm hoping it can be used in a similar way to access (only actually need to write to) tables in a similar manner.
 
You can share a variable between files using the following method:
Code:
MapModData.g_ActiveNotifications	= MapModData.g_ActiveNotifications or {}
local g_ActiveNotifications		= MapModData.g_ActiveNotifications
At the top of all files that want to share the variable. The variable can be any type/any name.

That would require me to replace NotificationPanel.lua to move g_ActiveNotifications into the MapModData table though. I'm hoping to be able to access the instance declared in NotificationPanel.lua by default from a separate lua file without modifying the Notification Panel itself.
 
UI - Notification Options is extensible and can call user defined callbacks from clicking the notifications. It also has the extension to get my UI - City Extension end of turn blocking code in, so may be a better and more up-to-date place to start than the sneaks/alpaca code

It also keeps new events within the standard player notification queue, so they are saved and rebroadcast on load (and can also be managed via the standard CvNotification code)
 
UI - Notification Options is extensible and can call user defined callbacks from clicking the notifications. It also has the extension to get my UI - City Extension end of turn blocking code in, so may be a better and more up-to-date place to start than the sneaks/alpaca code

It also keeps new events within the standard player notification queue, so they are saved and rebroadcast on load (and can also be managed via the standard CvNotification code)

Awesome, that looks amazingly helpful. Thanks! I've already done some DLL-side coding for my notifications system but I'd say yours will be more robust. I'll take a good look through what you've done already, but at a glance it looks like you've already added all the functionality I was looking for in creating custom notifications for my mod.
 
Awesome, that looks amazingly helpful. Thanks! I've already done some DLL-side coding for my notifications system but I'd say yours will be more robust. I'll take a good look through what you've done already, but at a glance it looks like you've already added all the functionality I was looking for in creating custom notifications for my mod.
At least you found out before you wrote the mod :p I have not always been so lucky.
 
Back
Top Bottom