Author Topic: Inline C# function in a linked profile problem (include commands from another)  (Read 3624 times)

jonsky7

  • Newbie
  • *
  • Posts: 14
Hello,

I use Voice attack in DCS World, and have been experimenting with DCS-BIOS.

DCS-BIOS can send commands directly into the game rather than relying on keypresses, this means you can still do other things while voice attack is performing an action in DCS, and/or doesn't rely on the current view etc.

I'm not really very good at coding but I have borrowed an inline C# function from another users profile, which was modified from one written by Pfeil, and for the most part I can get it to do what I like.

However, I have several profiles that I link together, for the sake of organisation.

I have ran into a problem while trying to use the inline function in a linked profile. It doesn't seem to work and I get the error "unable to execute command - command not available".

If I use the command from the primary profile, there is no issue.

The inline function is as follows. I have this in both the main profile and the linked profile.

The command name is _DCS-BIOS Sender Command
Code: [Select]
using System;
using System.Text;
using System.Net.Sockets;
using System.Text.RegularExpressions;//for the regex

public class VAInline
{

    public void main()
    {
   
    //****************************************************//
    int portNumber = 7778;//you can change the Port number here
    string ipAddress = "127.0.0.1";//you can change the ip address here
    //****************************************************//
   
        try
        {
            UdpClient client = new UdpClient();
           
            client.Connect(ipAddress, portNumber);
           
            //string formatedInputStringForDcs = VA.GetText("formatedInputStringInVA");
            //https://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c-sharp
            //formatedInputStringForDcs = Regex.Replace(formatedInputStringForDcs, @"\r\n?|\n", "\n");
            //byte[] byteSend = Encoding.ASCII.GetBytes(formatedInputStringForDcs); 
            byte[] byteSend = Encoding.ASCII.GetBytes(VA.GetText("formatedInputStringInVA").Replace("\r\n", "\n"));
           
            client.Send(byteSend, byteSend.Length); 
            client.Close();
        }
        catch (Exception e)
        { 
            VA.WriteToLog(e.ToString(), "red");
        } 
    }
}

/* The orioginal code provided by Pfeil was:

using System;
using System.Text;
using System.Net.Sockets;

public class VAInline
{
    public void main()
    {
        try
        {
            TcpClient client = new TcpClient();
           
            client.NoDelay = true;
           
            client.Connect("localhost", 38502);
 
            NetworkStream ns = client.GetStream(); 
           
            byte[] byteSend = Encoding.ASCII.GetBytes("commandtoexecute"); 
           
            ns.Write(byteSend, 0, byteSend.Length); 
            ns.Close(); 
            client.Close(); 
 
        }
        catch (Exception e)
        { 
            VA.WriteToLog(e.ToString(), "red");
        } 
    }
}

Thank you Pfeil.
*/

and example of the command that uses this function is

Code: [Select]
Set text [formattedInputStringInVA] to 'NS430_ENT 1{NEWLINE}'

Execute command, '_DCS-BIOS Sender Command' (and wait until it completes)

Could anyone advise on what the issue is?

Is it that you simply cannot link a profile with an inline function like this?

Thank you




jonsky7

  • Newbie
  • *
  • Posts: 14
Nevermind

Just had to execute command by name  ;)