Hello everyone.
I'm developing some files for a game, and in this game there are NPC's (Non-playable-characters). These NPCs, you're able to talk and interact with. They all require scripts to perform (The scripts are representing their actions and what they'll say). My friend is also making the game files, in C#. He used the exact same method I'm using (I converted his..) to compile the scripts for the NPC's, and his scripts are in ".s" (C#). This is the function that loads the scripts.
So as you can see, it basically reads all the files named ".vb" (His were named ".s", I changed it to ".vb", thought it's the most logical thing to do since I'm converting it to VB.NET). It makes a new dictionairy of (String, INpcScript) called "mAvailableNPCScripts" (The scripts which are done compiling), and if there are errors - it writes them to the Logger.
Theres are the functions from my Scripting class (Also, used his).
So, I went to try it out and make a basic script. This was my result:
As you can see, it inherits the class mHost and INpcScript which have basic functions of Run, Init, SendOk, Stop, etc.. However, I'm getting the following error:
Is it ok that I converted it to .vb files and then compiling it that way? How exactly can I fix my error and make it a compileable script? Thank you everybody, I hope I provided enough information - if not, please tell me what to add.
Have a nice day!
Edit: I uploaded a .rar file containing 2 more classes: INpcScript and NpcChatSession, if anyone wants to to take a look at them, too.
http://hostr.co/5KcN87Z2DLPK
If anyone's not getting how it works: The script gets decompiled. When the player chooses a NPC, it assigns a new NpcChatSession of the Npc he chose and then it assigns all the functions of the compiled script (Run, Stop, etc)..
I'm developing some files for a game, and in this game there are NPC's (Non-playable-characters). These NPCs, you're able to talk and interact with. They all require scripts to perform (The scripts are representing their actions and what they'll say). My friend is also making the game files, in C#. He used the exact same method I'm using (I converted his..) to compile the scripts for the NPC's, and his scripts are in ".s" (C#). This is the function that loads the scripts.
vb Code:
Public Sub MakeAvailableScripts(ByRef pCharacter As Character) If mAvailableNPCScripts Is Nothing Then mAvailableNPCScripts = New Dictionary(Of String, INpcScript) Else mAvailableNPCScripts.Clear() End If Dim results As CompilerResults Dim FilesNeedingRecompiling As List(Of String) = ScriptDataChecker.GetFilesNeedingRecompiling() For Each filename As String In Directory.GetFiles("C:\Scripts", "*.vb") Dim fi As FileInfo = New FileInfo(filename) results = Scripting.CompileScript(filename) If results.Errors.Count > 0 Then If pCharacter IsNot Nothing Then MessagePackets.SendMessage(pCharacter, 1, "Couldn't compile the file (" & fi.Name & ") correctly.") For Each _error As CompilerError In results.Errors MessagePackets.SendMessage(pCharacter, 1, "Line " & _error.Line.ToString & ", Column " & _error.Column.ToString & ": " & _error.ErrorText & ".") Next Else Logger.writeLog(LogTypes.Error_, "Couldn't compile the file (" & fi.Name & ") correctly.") For Each _error As CompilerError In results.Errors Logger.writeLog(LogTypes.Error_, "Line " & _error.Line.ToString & ", Column " & _error.Column.ToString & ": " & _error.ErrorText & ".") Next End If Else If pCharacter IsNot Nothing Then MessagePackets.SendMessage(pCharacter, 1, "Compiled " & fi.Name & "!") Else Logger.writeLog(LogTypes.Info, "Compiled {0}!", fi.Name) End If mAvailableNPCScripts.Add(fi.Name.Replace(".vb", ""), CType(Scripting.FindInterface(results.CompiledAssembly, "INpcScript"), INpcScript)) End If fi = Nothing Next ScriptDataChecker.GenerateNewScriptHashes() End Sub
So as you can see, it basically reads all the files named ".vb" (His were named ".s", I changed it to ".vb", thought it's the most logical thing to do since I'm converting it to VB.NET). It makes a new dictionairy of (String, INpcScript) called "mAvailableNPCScripts" (The scripts which are done compiling), and if there are errors - it writes them to the Logger.
Theres are the functions from my Scripting class (Also, used his).
vb Code:
Public Shared Function CompileScript(Source As String) As CompilerResults Dim compiler As CodeDomProvider = CodeDomProvider.CreateProvider("CSharp") Dim parms As New CompilerParameters parms.GenerateExecutable = False parms.GenerateInMemory = True parms.IncludeDebugInformation = False parms.ReferencedAssemblies.Add("System.dll") parms.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location) Return compiler.CompileAssemblyFromFile(parms, Source) End Function Public Shared Function FindInterface(DLL As System.Reflection.Assembly, InterfaceName As String) As Object ' Loop through types looking for one that implements the given interface For Each t As Type In DLL.GetTypes() If t.GetInterface(InterfaceName, True) IsNot Nothing Then Return DLL.CreateInstance(t.FullName) End If Next Return Nothing End Function
So, I went to try it out and make a basic script. This was my result:
vb Code:
Public Class NpcScript Inherits INpcScript Public mHost As IHost Public Sub Init(host As IHost) mHost = host End Sub Public Sub Run(character As Character, State As Byte, Answer As Byte, StringAnswer As String, IntegerAnswer As Integer) If State = 0 Then mHost.SendOK("It is a fine day for laundry. Wouldn't you agree?") Else mHost.Stop_() End If End Sub End Class
As you can see, it inherits the class mHost and INpcScript which have basic functions of Run, Init, SendOk, Stop, etc.. However, I'm getting the following error:
Code:
Line 1, Coulmn 1: A namespace cannot directly contain members such as fields or methods.Have a nice day!
Edit: I uploaded a .rar file containing 2 more classes: INpcScript and NpcChatSession, if anyone wants to to take a look at them, too.
http://hostr.co/5KcN87Z2DLPK
If anyone's not getting how it works: The script gets decompiled. When the player chooses a NPC, it assigns a new NpcChatSession of the Npc he chose and then it assigns all the functions of the compiled script (Run, Stop, etc)..