タイトルがややこしくて申し訳ありませんが、スペースを取らずに説明できる最善の方法です。そして、私のフォーマットを許してください、私は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 ソリューション プラットフォーム (必須)
そして、次のファイルが含まれています
- AC# MainScript.cs というクラス (上記のコードを格納)
- プロジェクトのルート フォルダーにある 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 タイプ名 'Events' はタイプ 'AW.Instance' に存在しません 行 42 列 59
エラー 2 型または名前空間名 'InstanceException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?) 行 52 列 24
エラー 4 型または名前空間名 'InstanceException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?) 行 64 列 24
エラー 6 The type or namespace name 'InstanceException' could not be found (using ディレクティブまたはアセンブリ参照がありませんか?) 行 74 列 20
エラー 2 型または名前空間名 'InstanceException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?) 行 103 列 20
どこで .dll を入手できるのか疑問に思われるかもしれません。ここにいくつかのリンクがあります。
- Activeworlds SDK (The C++ .dll) は次の場所にあります: http://wiki.activeworlds.com/index.php?title=SDK
- 私が使用している SDK (The 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
(引用の理由は、これ以上リンクを投稿できないためです)
これを見てください。私は通常、MonoDevelopment を使用して Unity 3D でコードを作成するため、Visual Studio を初めて使用します。私はアマチュア C# コーダーなので、しばらくお待ちください。これはあまり文書化されていないプロセスであり、多くの場合、それを使用する開発者は私のような人のために多忙を極めています。さらに、他のコーダーは C# ではなく VB.net と C++ を使用しています。