Jump to content

[LE] help with console function


irswat

Recommended Posts

 

 

;console and GetDXScanCode functions borrowed from
;http://www.gamesas.com/way-run-bat-from-script-t259754.html
;thanks Roberta Obrien, leigh stewart, and Allison Sizemore

Function Console(String asCommand, Int aiCharIndex = 0, Int aiStringLength = 0)
	Input.TapKey(41) 	; '~' 
	aiStringLength = StringUtil.GetLength(asCommand)	
	
	While (aiCharIndex < aiStringLength) 
		Input.TapKey(GetDXScanCode(StringUtil.GetNthChar(asCommand, aiCharIndex)))	
		aiCharIndex += 1	
	EndWhile 
	
	Input.TapKey(28) 	; 'Enter'	
	Input.TapKey(41) 	; '~'
EndFunction

Int Function GetDXScanCode(String asCharacter) 
	If StringUtil.IsLetter(asCharacter)	
		If asCharacter == "Q"	
			Return 16	
		ElseIf asCharacter == "W"	
			Return 17	
		ElseIf asCharacter == "E"	
			Return 18	
		ElseIf asCharacter == "R"	
			Return 19	
		ElseIf asCharacter == "T"
			Return 20	
		ElseIf asCharacter == "Y"	
			Return 21	
		ElseIf asCharacter == "U"
			Return 22	
		ElseIf asCharacter == "I"	
			Return 23	
		ElseIf asCharacter == "O"	
			Return 24	
		ElseIf asCharacter == "P"
			Return 25	
		ElseIf asCharacter == "A"
			Return 30	
		ElseIf asCharacter == "S"	
			Return 31	
		ElseIf asCharacter == "D"	
			Return 32	
		ElseIf asCharacter == "F"	
			Return 33	
		ElseIf asCharacter == "G"	
			Return 34	
		ElseIf asCharacter == "H"	
			Return 35	
		ElseIf asCharacter == "J"	
			Return 36	
		ElseIf asCharacter == "K"
			Return 37	
		ElseIf asCharacter == "L"	
			Return 38	
		ElseIf asCharacter == "Z"
			Return 44	
		ElseIf asCharacter == "X"	
			Return 45	
		ElseIf asCharacter == "C"
			Return 46	
		ElseIf asCharacter == "V"	
			Return 47	
		ElseIf asCharacter == "B"	
			Return 48	
		ElseIf asCharacter == "N"
			Return 49	
		ElseIf asCharacter == "M"
			Return 50	
		EndIf 
	ElseIf StringUtil.IsDigit(asCharacter)
		If asCharacter == "1"	
			Return 2	
		ElseIf asCharacter == "2"
			Return 3	
		ElseIf asCharacter == "3"
			Return 4	
		ElseIf asCharacter == "4"	
			Return 5	
		ElseIf asCharacter == "5"
			Return 6	
		ElseIf asCharacter == "6"
			Return 7	
		ElseIf asCharacter == "7"
			Return 8	
		ElseIf asCharacter == "8"
			Return 9	
		ElseIf asCharacter == "9"
			Return 10	
		ElseIf asCharacter == "0"
			Return 11	
		EndIf	
	ElseIf asCharacter == " "
		Return 57
	ElseIf asCharacter == "-"
		Return 12
	ElseIf asCharacter == "="
		Return 13
	ElseIf asCharacter == "["
		Return 26 
	ElseIf asCharacter == "]"
		Return 27
	ElseIf asCharacter == ";"
		Return 39
	ElseIf asCharacter == "'"
		Return 40 
	ElseIf asCharacter == "~"
		Return 41
	ElseIf asCharacter == ","
		Return 51	
	ElseIf asCharacter == "."
		Return 52
	ElseIf asCharacter == "/"
		Return 53	
	ElseIf asCharacter == " "
		Return 57	
	EndIf
EndFunction

bool function DumpLog()

	float time
	string log
	string timeLogFileName
	string filePath
	time=Utility.GetCurrentRealTime()
	timeLogFileName=(time as string)
	string sDatafileName
		
	;gets My documents location
	Console("Bat GetPath.bat")	
	sDatafileName = "SVCE/filePath.txt"
	if MiscUtil.FileExists(sDatafileName)
		debug.trace("File found: reading file.")
		filePath = MiscUtil.ReadFromFile(sDatafileName)
	endif
	
	;sets path to papyrus trace log
	sDatafileName = filePath + "/My Games/Skyrim/Logs/Script/Papyrus.0.log"
	
	;dumps contents of tracelog to a string
	if MiscUtil.FileExists(sDatafileName)
		debug.trace("File found: reading file.")
		log = MiscUtil.ReadFromFile(sDatafileName)
	endif
	
	;sets write file path to current time stamp
	debug.trace("dumping from " + sDatafileName + " to " + "/logs/" + time + ".txt")
	sDatafileName = "SVCE/logs/" + timeLogFileName + ".txt"
	
	;writes log to timstamped file in SVCE folder
	MiscUtil.WriteToFile(sDatafileName, log, false, false)
	
	return true
endFunction

 




Now it opens the console. And i've seen it type letters, but for some reason using the console command to run the bat file doesn't work. The bat file itself works. It simply retrieves the documents path from registry and saves it to a text file. If I run the bat manually using bat "GetPath.bat" before executing this LogDump function, the log function works perfect. Something about the console function isn't working, but others have reported success with it.

Edited by irswat
Link to comment
Share on other sites

consider using ConsoleUtil to run the bat with one line of code, without opening the console

; Execute command in console silently.
;function ExecuteCommand(string text) global native


ConsoleUtil.ExecuteCommand("Bat GetPath")

It's bad luck MiscUtil doesn't run a bat since 2.9, since you have it. :ermm: (Had too Check, I haven't use it since 2.8 so was having a What The (F) Moment, while reading your post. :confused: )

 

Good luck on your Mod.

 

ConsoleUtil is by Meh321 the original author of PapyrusUtil. Cheers

Link to comment
Share on other sites

it seems the console command bat does not do what it suggests. My bat file is supposed to check a registry key to find the location of the documents folder, in order to copy the papyrus log. The bat command seems to only support bat files that contain skyrim console commands.

Link to comment
Share on other sites

I assumed batch files are executed by windows. Apparently these are not batch files, but simply text files that get read into skyrim. Would be so cool if there were a way to execute batch files from console. So many possibilities. Maybe via an skse plugin

Edited by irswat
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...