Results 1 to 12 of 12

Thread: Help me get simple sub-mission script to work at all?

  1. #1
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Help me get simple sub-mission script to work at all?

    Hi,

    I'm trying to understand sub-mission scripts but I can't get past the first hurdle.

    I know my paths etc. are correct because if I put a syntax error in the following sub-mission script then I get a corresponding error log message. Otherwise, there are no log errors.

    When I start the mission, I see the on-screen message from the first script but not from the sub-script.

    Here is the main script:
    Code:
    public class Mission : AMission
    {
        public override void OnBattleStarted()
        {
            GamePlay.gpHUDLogCenter("Main Mission Loaded");
            MissionNumberListener = -1;
            Timeout(15, () =>{
            GamePlay.gpPostMissionLoad("missions/Single/Dover_Attack MC/Submission/mission1.mis");
    	});
        }
    }

    Here is the sub-mission script:

    Code:
    public class Mission : AMission
    {
        public override void OnBattleStarted()
        {   
          GamePlay.gpHUDLogCenter("Mission1.mis loaded!");
        }
    }
    What am I doing wrong? Are there any special 'using' requirements at the top of the script? Maybe settings elsewhere, in conf.ini for example?

    Thanks in advance,

    M

  2. #2
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Help me get simple sub-mission script to work at all?

    MissionNumberListener = -1;

    This is the key. Your first mission is mission 0. Subsequent missions are numbered 1, 2, 3, etc.

    A value of -1 means, 'send me all events from all missions code'. Or you can specify a specific mission to receive only those events.

    Just use -1 for now.

  3. #3
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Help me get simple sub-mission script to work at all?

    Hi Oskar,

    Thanks for the reply.

    I don't quite understand - I already have MissionNumberListener = -1 in the main script, so why isn't it receiving the commands from the sub-mission?

    Regards

  4. #4
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Help me get simple sub-mission script to work at all?

    OnBattleStarted is only called once, when the Battle starts. Only the base mission gets this event.

  5. #5
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Help me get simple sub-mission script to work at all?

    Ok thanks, so I replaced OnBattleStarted with OnAircraftTookOff in the sub-script but still get no message from the sub-script when the aircraft takes off. Works fine in the main mission.

    Regards

  6. #6
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Help me get simple sub-mission script to work at all?

    Salmo say this "What I found was that console, log, HUD display type commands in sub-mission scripts do not work, but most other script methods do work. So C# commands like GamePlay.gpHUDLogCenter or Console.WriteLine don't work from subscripts."

  7. Likes Marcost liked this post
  8. #7
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Help me get simple sub-mission script to work at all?

    I think I need to concentrate on making one mega script with everything I want in it!

  9. #8
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Help me get simple sub-mission script to work at all?

    Quote Originally Posted by Marcost View Post
    I think I need to concentrate on making one mega script with everything I want in it!
    Better to make self contained scripts that just do one thing well and include them in your base script.

    Mega scripts are mega headaches to debug.

  10. Likes N/A liked this post
  11. #9
    varrattu
    Guest

    Re: Help me get simple sub-mission script to work at all?

    Hello Marcost,

    even if you have experience with scripting/csharp it helps a lot reading in these threads:

    FMB, Mission & Campaign builder Discussions

    The more we share the more we get.

    ~V~


    Quote Originally Posted by Marcost View Post
    I think I need to concentrate on making one mega script with everything I want in it!

  12. #10
    varrattu
    Guest

    Re: Help me get simple sub-mission script to work at all?

    Hello Oskar,

    what is the difference between "OnBattleInit" and "OnBattleStarted"?

    ~V~

    Quote Originally Posted by ATAG_Oskar View Post
    OnBattleStarted is only called once, when the Battle starts. Only the base mission gets this event.

  13. #11
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Help me get simple sub-mission script to work at all?

    Quote Originally Posted by varrattu View Post
    what is the difference between "OnBattleInit" and "OnBattleStarted"?
    The only difference I know of is that the OnBattleInit event is received before the static objects are loaded. Not sure what you'd use it for.

    After the static objects are loaded the OnBattleStarted event is received. This only happens when the base mission is loaded, subsequent loads of sub-missions do not generate an OnBattleStarted event.

  14. #12
    Supporting Member
    Join Date
    Sep 2019
    Location
    Yorkshire
    Posts
    138
    Post Thanks / Like
    Total Downloaded
    1.39 GB

    Re: Help me get simple sub-mission script to work at all?

    Quote Originally Posted by ATAG_Oskar View Post
    Better to make self contained scripts that just do one thing well and include them in your base script.

    Mega scripts are mega headaches to debug.
    Thanks Oskar, that is what I meant - I have self-contained working scripts and will merge them to get what I want.

    Regards

    M

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •