对不起,标题有点令人困惑,但这是我解释它而不占用太多空间的最佳方式。请原谅我的格式,我是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]);
}
}
}
}
但它不起作用! 这是我的规格:
以下是项目的内容:
并包含以下文件
这些是我调整过的唯一内容 我得到的错误是:
错误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,这里有几个链接
https://github.com/Bloyteg/AW.SDK.Core
(注意,信息可能不那么准确)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#。
答案 0 :(得分:1)
查看您链接的源,AW.Utility.ReturnCodes不存在。
将您编写异常的任何地方更改为控制台以编写异常。即。
Console.WriteLine("Unexpected Error: {0}.", ex);
另外,看起来没有InstanceException类。你确定你不是在寻找其中一个: https://github.com/Bloyteg/AW.SDK.Core/tree/master/AW.Core/AW/Exceptions
最后,你在这里错过了一些代码吗?编译器抱怨对不存在“事件”的类型的引用,但我在您提供的代码中没有看到。我的前两条评论应该清除你的大多数问题,如果你需要更多的帮助,请告诉我。