' Save File System Inline-Function for VoiceAttack - Load Any/All Variables from File/List to Profile
' by SemlerPDX Mar2020
' VETERANS-GAMING.COM
' --Loads Variables from Text List Format into VA Variables of Appropriate Data Type (INT/DEC/TXT/BOOL)--
' **note: format for ALL variable names saved to file must start with same 4 character prefix i.e. AVCS_MyVar1, AVCS_MyVar2**
' ((below is example from VA command action list prior to calling this inline:))
'---------------------------------------------------------------------------------------------
'// Set variable to text contents of save file or text variable (list) depending on parameter(s) used
'Begin Boolean Compare : [AVCS_SFS_LOAD_list] Equals False
' Set text [~save_file] to [{TXT:AVCS_SFS_SaveFilePath}] (Trim)
'Else
' Set text [~save_file] to [AVCS_SFS_LOAD_contents] (Trim)
'End Condition
'//
'Begin Text Compare : [~save_file] Does Not Contain '{NEWLINE}'
' Set text [~save_file] to [~save_file] (Replace '{SPACE}{TXTSUBSTR:~save_file:0:4}' with '(/n){TXTSUBSTR:~save_file:0:4}')
'End Condition
'---------------------------------------------------------------------------------------------
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Drawing
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Linq
Imports System.Xml.Linq
Imports System.Threading.Tasks
Public Class VAInline
dim clearVariable as boolean
dim saveVariable as boolean
dim variableIndex as integer
dim countD as integer
dim countC as integer
dim contents() as string
dim entry() as string
Public Sub Main()
if VA.GetText("~save_file") IsNot nothing
'Check and Set Clear/Save Parameter Variables
if VA.GetBoolean("AVCS_SFS_LOAD_clear") IsNot nothing
clearVariable = VA.GetBoolean("AVCS_SFS_LOAD_clear")
end if
if VA.GetBoolean("AVCS_SFS_LOAD_save") IsNot nothing
saveVariable = VA.GetBoolean("AVCS_SFS_LOAD_save")
end if
'Split contents of save file into single lines separated by the newline or (/n)
if VA.GetText("~save_file").Contains(vbNewLine)
contents = VA.GetText("~save_file").Split(new string() {Environment.NewLine},StringSplitOptions.None)
else
contents = VA.GetText("~save_file").Split(new string() {"(/n)"},StringSplitOptions.None)
end if
'In each line, isolate Var Name/Val via '=' and Eval entry value for data type
for each line as string in contents
entry = line.Split("=")
if(entry(1).Contains ("."))
countD = entry(1).Split(".").Length -1
else
countD = 0
end if
if(entry(1).Contains (","))
countC = entry(1).Split(",").Length -1
else
countC = 0
end if
'Use Comma and Decimal Count to check data type for casting as Int or Dec
if((IsNumeric(entry(1))) and (((countD = 1) and (countC = 0)) or ((countD = 0) and (countC = 1)) or ((countD = 0) and (countC = 0))))
if(entry(1).Contains (".") or entry(1).Contains (","))
' Attempt to Handle International Decimal Separator
if(entry(1).Contains (","))
entry(1) = Replace(entry(1), ",", ".")
end if
' Entry is a DECIMAL Type
if((clearVariable) and (saveVariable))
' Prepare Decimal Var for SaveToProfile command, clearing from Profile completely
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "DEC")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
elseif(saveVariable)
' Prepare Decimal Var for SaveToProfile command
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "DEC")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
elseif(clearVariable)
' Clear Decimal Var directly from Profile
VA.SetDecimal(entry(0), nothing)
else
' Load Decimal Var directly to Profile
VA.SetDecimal(entry(0), entry(1))
end if
else
' Entry is an INTEGER Type
if((clearVariable) and (saveVariable))
' Prepare Integer Var for SaveToProfile command, clearing from Profile completely
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "INT")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
elseif(saveVariable)
' Prepare Integer Var for SaveToProfile command
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "INT")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
elseif(clearVariable)
' Clear Integer Var directly from Profile
VA.SetInt(entry(0), nothing)
else
' Load Integer Var directly to Profile
VA.SetInt(entry(0), entry(1))
end if
end if
'if entry(1) is NOT Numeric--------------------------
elseif((LCase (entry(1)) = "true") or (LCase (entry(1)) = "false"))
' Entry is a BOOLEAN Type
if((clearVariable) and (saveVariable))
' Prepare Boolean Var for SaveToProfile command, clearing from Profile completely
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "BOOL")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
elseif(saveVariable)
' Prepare Boolean Var for SaveToProfile command
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "BOOL")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
elseif(clearVariable)
' Clear Boolean Var directly from Profile
VA.SetBoolean(entry(0), nothing)
else
' Load Boolean Var directly to Profile
VA.SetBoolean(entry(0), entry(1))
end if
else
' Entry is a TEXT Type
if((clearVariable) and (saveVariable))
' Prepare Text Var for SaveToProfile command, clearing from Profile completely
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "TXT")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
elseif(saveVariable)
' Prepare Text Var for SaveToProfile command
variableIndex = variableIndex + 1
VA.SetText("~~varType" + variableIndex.ToString(), "TXT")
VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
elseif(clearVariable)
' Clear Text Var directly from Profile
VA.SetText(entry(0), nothing)
else
' Load Text Var directly to Profile
VA.SetText(entry(0), entry(1))
end if
end if
next 'loop around to the next entry value
if(variableIndex > 0)
' Set Max Count of Vars prepared for SaveToProfile command func, execute as sub-command, wait for completion
VA.SetInt("~~varIndex", variableIndex.ToString())
vaProxy.Command.Execute ("f_sfs_to_profile", true, true)
end if
end if
End Sub
End Class
' -- end of inline function --
' ((below is example from VA command action list for the 'f_sfs_to_profile' command executed at end of inline:))
'---------------------------------------------------------------------------------------------
'
'Start Loop : Repeat From 1 to [~~varIndex]
'Set text [~type] to '{TXT:~~varType{INT:~i}}'
'Begin Text Compare : [~type] Equals 'BOOL'
'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
'Set Boolean [{TXT:~~varName{INT:~i}}] to [Not Set] (save value to profile)
'Else
'Convert text [~~varValue{INT:~i}] to true/false (boolean) [{TXT:~~varName{INT:~i}}]
'Set Boolean [{TXT:~~varName{INT:~i}}] to [{TXT:~~varName{INT:~i}}] (save value to profile)
'End Condition
'Else If Text Compare : [~type] Equals 'TXT'
'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
'Set text [{TXT:~~varName{INT:~i}}] to [Not Set] (save value to profile)
'Else
'Set text [{TXT:~~varName{INT:~i}}] to '{TXT:~~varValue{INT:~i}}' (save value to profile)
'End Condition
'Else If Text Compare : [~type] Equals 'DEC'
'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
'Set decimal [{TXT:~~varName{INT:~i}}] value to [Not Set] (save value to profile)
'Else
'Set decimal [{TXT:~~varName{INT:~i}}] value to the converted value of {TXT:~~varValue{INT:~i}} (save value to profile)
'End Condition
'Else If Text Compare : [~type] Equals 'INT'
'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
'Set integer [{TXT:~~varName{INT:~i}}] value to [Not Set] (save value to profile)
'Else
'Set integer [{TXT:~~varName{INT:~i}}] value to the converted value of {TXT:~~varValue{INT:~i}} (save value to profile)
'End Condition
'End Condition
'End Loop
'//
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎