Author Topic: Importing variables  (Read 5349 times)

Nico1854

  • Guest
Importing variables
« on: December 03, 2016, 06:01:07 AM »
I'm Trying to import variables into VA fom a VB pluggin. The pluggin does start in VA but I get an error saying :
"Plugin execution: Conversion from string "" to type "Integer" is not valid.

In fact, I have a txt file with 7 lines of data and would like to add each line of data to a variable that I could then use in VA.

My VB code looks like that :

Code: [Select]
    Dim FileNum As Integer = FreeFile()
        Dim FileOutput As Integer = FreeFile()
        Dim LuaRead1 As String = ""
        Dim LuaRead2 As String = ""
        Dim lines As String() = IO.File.ReadAllLines("C:\Test\Modules\TestBridge.txt")

        LuaRead1 = lines(0)
        LuaRead2 = lines(1)
        FileClose(FileNum)
        FileOpen(FileOutput, "C:\Test\Modules\Test.txt", OpenMode.Output)
        Write("LuaRead1", LuaRead1)
        FileClose(FileOutput)

Nico1854

  • Guest
Re: Importing variables
« Reply #1 on: December 03, 2016, 02:07:21 PM »
After some hours spent to find out how to do, I've managed to initiate the vars in the pluggin :

Code: [Select]
  Dim objStreamReader As System.IO.StreamReader
        objStreamReader = New System.IO.StreamReader("C:\P3D\Modules\P3DBridge.txt")

        Dim P3DDaytime As Integer
        P3DDaytime = objStreamReader.ReadLine()
        vaProxy.SetInt = ("P3DDaytime"(P3DDaytime))

        Dim P3DGround As Integer
        P3DGround = objStreamReader.ReadLine()

Now, I'm still stuck with the fact of using these vars in VA.
I would like to be able in VA to do a :

"if P3DDaytime = 0, say blabla
else if P3DDaytime = 1, say something else
else = say a third different thing
End if"

Can anybody help me with this last step ?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Importing variables
« Reply #2 on: December 03, 2016, 02:54:20 PM »
"if P3DDaytime = 0, say blabla
else if P3DDaytime = 1, say something else
else = say a third different thing
End if"

Can anybody help me with this last step ?

What do you need? you can use the "Begin a Conditional (If Statement) Block" action(And associated Conditional actions) to replicate that pseudocode nearly verbatim:
Code: [Select]
Begin Integer Compare : [P3DDaytime] Equals 0
    Say, 'blabla'
Else If Integer Compare : [P3DDaytime] Equals 1
    Say, 'something else'
Else
    Say, 'say a third different thing'
End Condition

Nico1854

  • Guest
Re: Importing variables
« Reply #3 on: December 04, 2016, 12:31:53 AM »
Oh, Sorry if I was not precise.

My problem is tha bility to read the variable Inside of VA. I'm not sure that I set it properly for that Inside of the plugin.

Code: [Select]
        Dim P3DDaytime As Integer
        P3DDaytime = objStreamReader.ReadLine()
        vaProxy.SetInt = ("VADaytime"(P3DDaytime))

From VA, I Execute the External Plugin and tried to insert VADaytime in the context field, or in the Integer Field but the value does not come back to VA. I now get the message : Plugin execution: Overload resolution failed because no accessible 'SetInt' accepts this number of arguments.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Importing variables
« Reply #4 on: December 04, 2016, 01:22:36 AM »

Code: [Select]
        Dim P3DDaytime As Integer
        P3DDaytime = objStreamReader.ReadLine()
        vaProxy.SetInt = ("VADaytime"(P3DDaytime))

From VA, I Execute the External Plugin and tried to insert VADaytime in the context field, or in the Integer Field but the value does not come back to VA. I now get the message : Plugin execution: Overload resolution failed because no accessible 'SetInt' accepts this number of arguments.
Am I correct in assuming you've placed that snippet of code under "If vaProxy.Context = "VADaytime" Then" within the "VA_Invoke1" section?


If that's the actual code, the "number of arguments" error comes from
Code: [Select]
vaProxy.SetInt = ("VADaytime"(P3DDaytime))
Look at this example:
Code: [Select]
vaProxy.SetInt("initializedInt1", 55)  'set some meaningless example integer valuesYou're trying to set the value as if it were a variable, but "vaProxy.SetInt" is a function, which you pass arguments.

You need to specify the name of the variable, and the value of the variable, separated by a comma, enclosed in parentheses:
Code: [Select]
vaProxy.SetInt("P3DDaytime", P3DDaytime)

Nico1854

  • Guest
Re: Importing variables
« Reply #5 on: December 04, 2016, 01:34:53 AM »
This is what my code looks like :

Code: [Select]
Public Shared Sub VA_Invoke1(vaProxy As Object)

        Dim objStreamReader As System.IO.StreamReader
        objStreamReader = New System.IO.StreamReader("C:\P3D\Modules\P3DBridge.txt")

        Dim P3DDaytime As Integer
        P3DDaytime = objStreamReader.ReadLine()
        vaProxy.SetInt = ("VADaytime", P3DDaytime)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Importing variables
« Reply #6 on: December 04, 2016, 02:04:05 AM »
This is what my code looks like :
Alright, so you don't need to pass "VADaytime" as context to the plugin from VoiceAttack as you're not actually doing anything with it.

However, if "P3DDaytime" is an Integer, you can't use it to store the output of "objStreamReader.ReadLine()", which returns a string.

Try something like this:
Code: [Select]
Public Shared Sub VA_Invoke1(vaProxy As Object)

        Dim objStreamReader As System.IO.StreamReader
        objStreamReader = New System.IO.StreamReader("C:\P3D\Modules\P3DBridge.txt")

        Dim P3DDaytime As String
        P3DDaytime = objStreamReader.ReadLine()
        vaProxy.SetText("VADaytime", P3DDaytime)

That should retrieve the first line of "P3DBridge.txt", and make it available within VoiceAttack as the text value named "VADaytime".

Nico1854

  • Guest
Re: Importing variables
« Reply #7 on: December 04, 2016, 02:13:14 AM »
Wondefull, it's working, You really made my day, Thank you so much.

Obviously, next question :

How can I changer a string into a value. In fact I'm reading speed, altitude and need to trigger actions such as say passing 10'000ft when the value is bigger than 10'000

Nico1854

  • Guest
Re: Importing variables
« Reply #8 on: December 04, 2016, 02:27:51 AM »
Stupid question, found the answer with Google is my friend