1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[GS] Notification every turn

Discussion in 'Mod Creation Help' started by Revolutionist_8, Feb 25, 2019.

  1. Revolutionist_8

    Revolutionist_8 Prince

    Joined:
    Jan 30, 2016
    Messages:
    470
    Location:
    Hungary, Earth, M.W. Galaxy
    My dear friends!

    I've been trying to get a method that would give the human player a notification every turn. I have this template that if I understand correctly would put a notification above the "Next turn" button with an exclamation mark every turn with the text 'Summary' inside it. But there is something I'm clearly missing here as this doesn't want to work :sad:

    Spoiler code :

    Code:
    function NotifEachTurn()
       NotificationID                    =   NotificationID  and NotificationID +1 or 50000
        pNotification                     = {};
        pNotification.GetTypeName         = function() return "NOTIFICATION_CUSTOM_NAME"; end
        pNotification.GetPlayerID         = function() return Game:GetLocalPlayer(); end
        pNotification.GetID               = function() return NotificationID; end
        pNotification.GetGroup            = function() return NotificationGroups.NONE; end
        pNotification.GetIconName         = function() return "ICON_NOTIFICATION_GENERIC"; end
        pNotification.GetType             = function() return 888888; end
        pNotification.GetEndTurnBlocking  = function() return EndTurnBlockingTypes.NO_ENDTURN_BLOCKING; end
        pNotification.IsIconDisplayable   = function() return true; end
        pNotification.IsValidForPhase     = function() return true; end
        pNotification.IsAutoNotify        = function() return false; end
        pNotification.GetMessage          = function() return "Message"; end
        pNotification.GetSummary          = function() return "Summary"; end
        pNotification.CanUserDismiss      = function() return true; end
        pNotification.IsLocationValid     = function() return false; end
        pNotification.GetLocation         = function() return 0, 0; end
        pNotification.IsTargetValid       = function() return false; end
        pNotification.GetTarget           = function() return ; end
        pNotification.IsVisibleInUI       = function() return true; end
        pNotification.Activate            = function(Boolean) end
        pNotification.GetCount            = function() return 1; end
        pNotification.GetAddTurn          = function() return  Game.GetCurrentGameTurn(); end
        pNotification.EraseOnStartTurn    = true;
        pNotification.DissmissOnActivate  = false;
        pNotification.GetEventOnActivate  = "Default_Event"
    
    
        LuaEvents.CustomNotification_OnDefaultAddNotification(pNotification);
    end
    
    GameEvents.PlayerTurnStarted.Add(NotifEachTurn); 

    Could someone please enlighten me?

    Also any idea why
    Spoiler code :

    Code:
    function Script(playerID)
        local pPlayer = Players[playerID]
        local gov = pPlayer:GetCulture():GetCurrentGovernment()  <---- function expected instead of nil
        ...
    GameEvents.PlayerTurnStarted.Add(Script)

    gives error 'function expected instead of nil' ? I tried with . instead of : in case it's a scoping issue, but same error :confused:

    Any help, advice, suggestion is greatly appreciated! Thank you very much!
     
  2. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,036
    Location:
    Illinois, USA
    The first question in Civ6 is always: what context are you running your code from?

    Player:GetCulture():GetCurrentGovernment() is only valid in a UI context and cannot be used in a GameplayScript.

    As I understand from JFD, Gathering Storm removed the ability of LuaEvents to share data cross-context, so any LuaEvent defined in a UI file can only "talk" to other UI files as I understand the new limitation.

    Notifications are by definition UI
     
    Revolutionist_8 and Infixo like this.
  3. Revolutionist_8

    Revolutionist_8 Prince

    Joined:
    Jan 30, 2016
    Messages:
    470
    Location:
    Hungary, Earth, M.W. Galaxy
    Thank you very much @LeeS for your reply, I really appreciate your help!

    I just want to create a simple Lua script that calculates some stuffs and sometimes calls a couple ingame lua functions (for example ChangeGoldBalance) then represents that data to the player via a simple notification box (cuz it seemed to be that this is the easiest).

    What does UI context mean precisely? Do I need to take the base game UI scripts and "override" it with my changes? Or it's something I configure in modinfo?

    Yeah, I know that GS messes up with many of His modding plans...

    Does this mean that I can't have a basic simple function that calculates stuffs, makes some changes then sends a simple notification (or any visual representation that the player can read) in any shape or form to the Player? I'm pretty sure that's not the case because it sounds absurd :undecide:
     
    Last edited: Feb 26, 2019
  4. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,036
    Location:
    Illinois, USA
    UI means User Interface. You would have to either add a new UI panel (even if you always hide it from the player) or you would have to re-write one of the game's base UI files and override the standard version of the entire file with your custom one that would be loaded from your mod.

    It's the sending the notification to the player where the issue comes in, since most lua functions that allow you to change stuff (such as a player's treasury) are only valid in a GameplayScript and are not valid in a UI file.

    There are two computer-processing threads in Civ6: Gameplay and User Interface. Lua that runs from an <AddGameplayScripts> action in a modinfo file (and Modbuddy) is by definition running on the Gameplay processing thread. Lua that runs from an <UserInterface> action in a modinfo file (and Modbuddy) is by definition running on the User Interface processing thread. The functions that are available on the gameplay side are distinct and different from those available on the UI side because Firaxis only coded the game's controlling DLL to include certain lua functions on one side or the other, whereas other functions are included in both. For Civ6 they concentrated on the Modifiers and Effects systems rather than a more-complete lua system, since their thinking was that the Modifiers system would be accessible to a greater width of mod-makers, and would process much faster than complicated lua scripts because the implementation of the Modifiers is done directly by the DLL engine.

    From what I understand GS disabled the ability of luaevents to send data back and forth between the two systems (gameplay and UI). The ExposedMembers system I believe is still available to shove info back and forth between the Gameplay and UI sides of the game.

    --------------------

    and while NotificationManager and its methods are valid in both states, all NotificationManager really allows you to do is "Manage" the notifications that have been created rather than create new notifications to the player.
     
    Last edited: Feb 26, 2019
  5. Revolutionist_8

    Revolutionist_8 Prince

    Joined:
    Jan 30, 2016
    Messages:
    470
    Location:
    Hungary, Earth, M.W. Galaxy
    I see. I suspected I can't get away without some UI overriding... :D

    Interesting. Thank you for your detailed clarification and background info, I truly appreciate it :)

    Hmmm, that's a shame. Did firaxis have a reason for such a move?

    How can I access or work with that ExposedMembers system? Could it allow to reach what I have in mind? (simple calculations / changes, simple representation of those on the UI)
     
  6. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,036
    Location:
    Illinois, USA
    @Gedemon knows more about the ExposedMembers system than I do.

    the lua file you need most to look at is NotificationPanel.lua to see how Firaxis deals with notifications. But as I recall from looking at it a long time ago the NotificationPanel.lua does not create notifications so much as implement the actions needed when the human player clicks a notification.
     
  7. Revolutionist_8

    Revolutionist_8 Prince

    Joined:
    Jan 30, 2016
    Messages:
    470
    Location:
    Hungary, Earth, M.W. Galaxy
    Thank you very much for your help @LeeS :) I will see if I can cook something meaningful out from all of this :) (fairly good chance that it will just end in waiting for skilled modders' mods :D )
     
  8. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    9,439
    Location:
    France
    ExposedMembers is a table shared between the two contexts, you can use it to pass data and methods from one to another.

    for example at the beginning of your first loaded Gameplay script (all gameplay scripts are loaded before all UI scripts, and you can put a load order for each file in each context too)
    Code:
    ExposedMembers.Revolutionist = {}
    in an UI script
    Code:
    function GetCurrentGovernment(playerID)
       local pPlayer = Players[playerID]
       return pPlayer:GetCulture():GetCurrentGovernment()
    end
    ExposedMembers.Revolutionist.GetCurrentGovernment = GetCurrentGovernment
    
    then in any Gameplay script :
    Code:
    function GetCurrentGovernment(playerID)
       return ExposedMembers.Revolutionist.GetCurrentGovernment(playerID)
    end
    
    To work you need to make sure that you'll never call the GetCurrentGovernment function in the Gameplay script before the game has finished loading all files
     
  9. Revolutionist_8

    Revolutionist_8 Prince

    Joined:
    Jan 30, 2016
    Messages:
    470
    Location:
    Hungary, Earth, M.W. Galaxy
    Ahh, I see. Thank you Gedemon for your help, really appreciate it :) Now I just need to make that notification every turn :D

    Edit: it's probably not a good place to say this, but I hope you're making good progress with that big project of yours :D (I've tried it like 4 months ago, it has a great potential)
     
    Last edited: Feb 26, 2019

Share This Page