Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2012, 05:55 AM
podvoxx podvoxx is offline
Approved Member
 
Join Date: Feb 2010
Posts: 190
Default The use of global variables

Is there a way to use the same variable in the host-mission and submission without using a .txt-file(for save variables)?

For example:
In host mission script I have count of planes
Code:
int countPlanes = 5;
In submission script I need to change this:
Code:
int countPlanes -= 1;
It is necessary to divide the script menu and script statistics, but they used to share data.

Now I now about this variant - http://www.sukhoi.ru/forum/showthrea...=1#post1766444

There are other alternatives a more simple than this? Maybe new class on dll help on it?
Reply With Quote
  #2  
Old 05-24-2012, 06:53 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Yes a Singleton Pattern in a DLL.
http://en.wikipedia.org/wiki/Singleton_pattern

Example Singleton (threadsafe)
Code:
   public sealed class Singleton
    {
        public int planeCount { get; set; }
        
        private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());

        public static Singleton GetInstance { get { return lazy.Value; } }

        private Singleton()
        { 
             // Initialisations
        }
    }
in Mis-C# you use for example

Code:
//$reference parts/core/MyDll.dll
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using MyNameSpace;

public class Mission : AMission
{
  
    Singleton s=Singleton.GetInstance;  // get access to the singleton or create it if not exist.


 public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

        s.planeCount += 1; // example
    }
}
use Singleton s=Singleton.GetInstance; in every Scriptfile you need acces to the singleton. There is always only one Singleton present.

Last edited by FG28_Kodiak; 05-24-2012 at 08:48 AM.
Reply With Quote
  #3  
Old 05-24-2012, 08:48 AM
podvoxx podvoxx is offline
Approved Member
 
Join Date: Feb 2010
Posts: 190
Default

Quote:
Originally Posted by FG28_Kodiak View Post
Yes a Singleton Pattern in a DLL.
Thank you, I hope it's help me.
Reply With Quote
  #4  
Old 05-26-2012, 10:31 AM
podvoxx podvoxx is offline
Approved Member
 
Join Date: Feb 2010
Posts: 190
Default

Great, it's work.
Reply With Quote
  #5  
Old 05-26-2012, 11:22 AM
podvoxx podvoxx is offline
Approved Member
 
Join Date: Feb 2010
Posts: 190
Default

My dll-file:
Code:
using System;

namespace smpcore
{    
    public static class SMPcore
    {
        public static int addNum(int x, int y)
        {
            return x + y;
        }
    }

    public sealed class Singleton
    {
        public int planeCount { get; set; }

        // Global side score
        public int redScore { get; set; }
        public int blueScore { get; set; }
        
        // Number dead units global statistic
        public int numberDeadRedPlanes { get; set; }  // aircraft unit
        public int numberDeadBluePlanes { get; set; } // aircraft unit

        public int numberDeadRedAAA { get; set; }  
        public int numberDeadBlueAAA { get; set; } 

        public int numberDeadRedTanks { get; set; }  // Tank unit
        public int numberDeadBlueTanks { get; set; } // Tank unit

        public int numberDeadRedArtillery { get; set; }  // Artillery unit
        public int numberDeadBlueArtillery { get; set; } // Artillery unit

        public int numberDeadRedCars { get; set; }  // Cars unit
        public int numberDeadBlueCars { get; set; } // Cars unit

        public int numberDeadRedShips { get; set; }  // Ships unit
        public int numberDeadBlueShips { get; set; } // Ships unit
       
        private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());

        public static Singleton GetInstance { get { return lazy.Value; } }

        private Singleton()
        {
            // Initialisations
            planeCount = 1;

            // Global side score
            redScore = 0;
            blueScore = 0;
           
            // Number dead units global statistic
            numberDeadRedPlanes = 0;  // aircraft unit
            numberDeadBluePlanes = 0; // aircraft unit

            numberDeadRedAAA = 0;
            numberDeadBlueAAA = 0; 

            numberDeadRedTanks = 0;  // Tank unit
            numberDeadBlueTanks = 0; // Tank unit

            numberDeadRedArtillery = 0;  // Artillery unit
            numberDeadBlueArtillery = 0; // Artillery unit

            numberDeadRedCars = 0;  // Cars unit
            numberDeadBlueCars = 0; // Cars unit

            numberDeadRedShips = 0;  // Ships unit
            numberDeadBlueShips = 0; // Ships unit            
        }
    }
}
My script:
Code:
//$reference "parts\core\smp.dll"
//$reference "parts\core\smpMessage.dll"
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using smpcore;
using smpmessage;

// HOST-MISSION Script
public class Mission : AMission
{
    // =========================HOST-MISSION PARAMETERS===========================
    // Setup file and folder path
    string setupMisMPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\1C SoftClub\\il-2 sturmovik cliffs of dover\\missions\\SMP\\Friday on my mind\\system\\mission_setup.ini";
      
    int unitPlanePrice = 10;
    int unitAAAPrice = 3;
    int unitTankPrice = 10;
    int unitArtilleryPrice = 2;
    int unitCarPrice = 2;
    int unitShipPrice = 10;

    // TESTTESTTESTTESTTESTTEST 
    Singleton stat = Singleton.GetInstance;  // get access to the singleton or create it if not exist.    

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionNumberListener = -1;

        smpSendMSG.MessageToAll("BATTLE STARTED!", "Chat");

        // LOAD SUBMISSIONS
        GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Test1\\Test1.mis");
        GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Test2\\Test2.mis");
    }

    // =========================OnActorDead=============================     
    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        base.OnActorDead(missionNumber, shortName, actor, damages);

        if (actor != null)
        {
            // AiGroundActor STATISTIC
            if (actor is AiGroundActor)
            {
                AiGroundActor groundActor = actor as AiGroundActor;
                if (groundActor != null)
                {
                    // AAArtillery points       
                    if (groundActor.Type() == AiGroundActorType.AAGun)
                    {
                        if (actor.Army() == 1)
                        {                            
                            stat.numberDeadRedAAA ++;
                            stat.blueScore += unitAAAPrice;
                        }
                        else if (actor.Army() == 2)
                        {
                            stat.numberDeadBlueAAA++;
                            stat.redScore += unitAAAPrice;
                        }
                        smpSendMSG.MessageToAll("Уничтожена зенитка [ Red/Blue ]:..." + stat.numberDeadRedAAA.ToString() + " / " + stat.numberDeadBlueAAA.ToString(), "Chat");
                    }                    
                } // null
            }
        } // null
    }
}
stat.redScore, stat.blueScore - no error
other stat. have error
Second stat. element in smpSendMSG.MessageToAll - no error.
I have error on VS, but script work fine in game.
Attached Images
File Type: jpg xxx.jpg (415.0 KB, 9 views)

Last edited by podvoxx; 05-26-2012 at 11:27 AM.
Reply With Quote
  #6  
Old 05-26-2012, 12:14 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

No problem by me, do you use a static class with name stat?
if you rename "stat" (singleton) the problem also exist?
Reply With Quote
  #7  
Old 05-26-2012, 02:31 PM
podvoxx podvoxx is offline
Approved Member
 
Join Date: Feb 2010
Posts: 190
Default

Quote:
Originally Posted by FG28_Kodiak View Post
No problem by me, do you use a static class with name stat?
if you rename "stat" (singleton) the problem also exist?
I don'n know why, but now I no have this problem. All work very good
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:28 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.