Help with Commendation points trigger

A forum to discuss custom scenarios, campaigns and modding in general.

Moderator: Panzer Corps 2 Moderators

Post Reply
Ezequiel1996
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Sat Jun 13, 2020 6:58 am

Help with Commendation points trigger

Post by Ezequiel1996 »

hello, i need help with commendation points trigger for my custom campaign, i've created the scripts following the AO lua files, but when i start my campaign i get the following error message 90: bad argument #2 to 'format' (number expected,got nil)
here are the scripts
  • current_cp_format = NSLOCTEXT("scenario_Poznan", "current_cp_format", "In this campaign, you can earn Commendation Points by completing bonus objectives. Opportunities to exchange Commendation Points for various rewards will be offered as the campaign progresses.\n\nYou begin this campaign with %d Commendation Points.")
    earned_cp_format2 = NSLOCTEXT("scenario_Poznan", "earned_cp_format2", "Secondary Objective to Destroy all Polish Aircraft completed.\nEarned Commendation Points: %d.\nTotal Commendation Points: %d.")
    earned_cp_format = NSLOCTEXT("scenario_Poznan", "earned_cp_format", "Secondary Objective to capture all Polish Aifields completed.\nEarned Commendation Points: %d.\nTotal Commendation Points: %d.")

    function AlwaysTrue()
    return true
    end

    function OnStartGame()
    local str = string.format(tostring(current_cp_format), campaign.comm_points) --here is where the error triggers
    MessageBox(str)
    end

    function OnObjective2(action)
    local comm = 0

    comm = 1

    campaign.comm_points = campaign.comm_points + comm

    local str2 = string.format(tostring(earned_cp_format2), comm, campaign.comm_points)
    MessageBox(str2)
    -- end
    end

    function Objective2Condition(action)
    return action.side == 0 and action.objective == 2 and action.status == ObjectiveStatus.Success
    end

    function OnObjective1(action)
    local comm = 0

    comm = 1

    campaign.comm_points = campaign.comm_points + comm

    local str1 = string.format(tostring(earned_cp_format), comm, campaign.comm_points)
    MessageBox(str1)
    -- end
    end

    function Objective1Condition(action)
    return action.side == 0 and action.objective == 1 and action.status == ObjectiveStatus.Success
    end
for extra information i will attach the lua file of the script
Attachments
PoznanLua file.rar
(1.7 KiB) Downloaded 46 times
Kerensky
Content Designer
Content Designer
Posts: 8649
Joined: Wed Jan 12, 2011 2:12 am

Re: Help with Commendation points trigger

Post by Kerensky »

Cross scenario global variables need to be initialized in the script.lua of the campaign itself, where the scenario tree is configured.

campaign.comm_points = 0
Ezequiel1996
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 231
Joined: Sat Jun 13, 2020 6:58 am

Re: Help with Commendation points trigger

Post by Ezequiel1996 »

thank you kerensky!
Post Reply

Return to “Panzer Corps 2 Scenario Design”