对不起,标题有点令人困惑,但这是我可以在不占用太多空间的情况下解释它的最佳方式。请原谅我的格式,我对stackoverflow很陌生。这是问题所在,我为 C++ SDK 的 C# 包装器找到了一些示例代码。使用 SDK 的程序称为 ActiveWorlds。代码在这里:
using System;
using AW;
namespace GreeterBotCSharp
{
class GreeterBot
{
/// <summary>
/// Main entry point into the GreeterBot program.
/// </summary>
/// <param name="args">Command line arguments.</param>
static void Main(string[] args)
{
//Prompt the user for their citizen number.
Console.Write("Enter citizen number: ");
int citizenNumber = int.Parse(Console.ReadLine());
//Prompt the user for their privilege password.
Console.Write("Enter privilege password: ");
string privilegePassword = Console.ReadLine();
//Prompt the user for a world to enter.
Console.Write("Enter a world name: ");
string world = Console.ReadLine();
//Create a new copy of the GreeterBot and run it.
GreeterBot bot = new GreeterBot();
bot.Run(citizenNumber, privilegePassword, world);
}
/// <summary>
/// Runs a new GreeterBot with the specified owner and privilege password.
/// </summary>
/// <param name="owner">The citizen number of the person who owns the bot.</param>
/// <param name="password">The privilege password of the person who owns the bot.</param>
/// <param name="world">The name of the world to greet in.</param>
private void Run(int owner, string password, string world)
{
try
{
//Create a new instance and set events
Instance greeterBot = new Instance();
greeterBot.EventAvatarAdd += new Instance.Event(greeterBot_EventAvatarAdd);
//Log the instance into the ActiveWorlds universe
try
{
greeterBot.SetInt(Attributes.LoginOwner, owner);
greeterBot.SetString(Attributes.LoginPrivilegePassword, password);
greeterBot.SetString(Attributes.LoginName, "GreeterBot");
greeterBot.Login();
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to login (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
//Enter a world and attempt to go to ground zero.
try
{
greeterBot.Enter(world);
greeterBot.StateChange();
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to enter world at ground zero (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
//Event dispatch loop. This is important, without it events would not be dispatched appropriately.
while (Utility.Wait(-1) == 0) ;
}
catch (InstanceException ex)
{
Console.WriteLine("Unexpected Error (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
return; //Application failed, quit.
}
}
/// <summary>
/// Event handler for avatars entering the proximity of the bot.
/// </summary>
/// <param name="sender">The instance that received the event. This is extremely important,
/// especially if instances share common event handlers. We use it here to control the instance.</param>
void greeterBot_EventAvatarAdd(Instance sender)
{
try
{
//Store the session and name of the avatar, and the name of the world.
int userSession = sender.GetInt(Attributes.AvatarSession);
string userName = sender.GetString(Attributes.AvatarName);
string worldName = sender.GetString(Attributes.WorldName);
//Greet the user via a whisper. Whisper makes use of a session number to target a user
//Session numbers are an extremely important concept in the SDK and are used to identify
//users when certain events occur or when sending some command to a specific user.
sender.Whisper(userSession, "Welcome to {0}, {1}! Enjoy your stay.", worldName, userName);
//Show that the user was greeted on the console.
Console.WriteLine("Greeter user {0}.", userName);
}
catch (InstanceException ex)
{
Console.WriteLine("Failed to greet user (Reason: {0}).", Utility.ReturnCodes[ex.ErrorCode]);
}
}
}
}
但它不起作用!这是我的规格:
- 微软视窗 8.1
- 适用于 Windows 的 Microsoft Visual Studio Express 2012
- mcafee Internet Security(你永远不知道...)
以下是该项目的组成部分:
- 一个 Visual C# 空项目
- x86解决方案平台(必填)
并包括以下文件
- 名为 MainScript.cs 的 AC# 类(包含上面的代码)
- 项目根文件夹中的 AW.Core.dll 文件,作为参考添加。(这是包装)
- 位于 RootFolder\bin\x86\Release\ 中的 Aw.dll 文件(这是包装器使用的 C++ DLL)
- C# 空项目中的常见问题
这些是我唯一调整的东西我得到的错误是:
错误 3“AW.Utility”不包含“ReturnCodes”第 54 行第 81 列的定义
错误 5“AW.Utility”不包含“ReturnCodes”第 66 行第 102 列的定义
错误 7“AW.Utility”不包含“ReturnCodes”第 76 行第 78 列的定义
错误 9“AW.Utility”不包含“ReturnCodes”第 105 行第 82 列的定义
错误 1 类型名称“事件”在类型“AW.Instance”中不存在第 42 行第 59 列
错误 2 找不到类型或命名空间名称“InstanceException”(您是否缺少 using 指令或程序集引用?) 第 52 行 第 24 列
错误 4 找不到类型或命名空间名称“InstanceException”(是否缺少 using 指令或程序集引用?) 第 64 行 第 24 列
错误 6 找不到类型或命名空间名称“InstanceException”(是否缺少 using 指令或程序集引用?) 第 74 行 第 20 列
错误 2 找不到类型或命名空间名称“InstanceException”(您是否缺少 using 指令或程序集引用?) 第 103 行 第 20 列
您可能想知道在哪里可以获得 .dll,这里有一些链接
- Activeworlds SDK(C++ .dll)可以在这里找到:http ://wiki.activeworlds.com/index.php?title=SDK
- 我正在使用的 SDK(C++ .dll)的下载地址是:http: //objects.activeworlds.com/downloads/awsdk101.zip
- 您可以在此处找到包装器的源代码(C# .dll):(
https://github.com/Bloyteg/AW.SDK.Core
注意,信息可能并不那么准确) - 您可以在此处找到 C# 包装器的下载:
https://github.com/Bloyteg/AW.SDK.Core/releases/download/0.3.14.100/AW.Core.zip
(引用的原因是因为我不能发布更多链接)
请看看这个。我对 Visual Studio 很陌生,因为我通常使用 MonoDevelopment 在 Unity 3D 中编写代码。我是一个业余的 C# 编码器,所以请耐心等待。这是一个记录不充分的过程,使用它的开发人员通常会忙于像我这样的人。另外,其他编码人员使用 VB.net 和 C++ 而不是 C#。