VB.NET Sample Program with SDK .NET Wrapper: Difference between revisions

From ActiveWiki
Jump to navigation Jump to search
Tomas (talk | contribs)
Created page with "Visual Studio VB.NET This example is used on Windows Forms. Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (o..."
 
Tomas (talk | contribs)
No edit summary
 
Line 1: Line 1:
Visual Studio VB.NET
==A simple greeter bot==
 
*Visual Studio VB.NET
 
This program implements a very simple greeter bot. The bot logs into the universe, enters a world, and says "Greetings [name]" to every user that enters the world.  You will need to download the [http://www.activeworlds.com/sdk/Download50.htm AWSDK] and [https://github.com/Bloyteg/AW.SDK.Core/ ActiveWorlds SDK .NET Wrapper] to use this program.
 
This example is used on Windows Forms. You must add a button to login and a timer to detect events.


This example is used on Windows Forms.
Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (or Debug)
Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (or Debug)
Go the applications properties/references and click on the "add" button
Go the applications properties/references and click on the "add" button.
Then click on "browse" and go to the folder where you put those .dll files and choose the AW.Core.dll (No need to do anything with the aw.dll)
Then click on "browse" and go to the folder where you put those .dll files and choose the AW.Core.dll (No need to do anything with the aw.dll)
Then move back up in the properties to "Compile". There change the "Target CPU" to "x86" (The wrapper will not support x64)
Then move back up in the properties to "Compile". There change the "Target CPU" to "x86" (The wrapper will not support x64)
Line 12: Line 17:


Public Class Form1
Public Class Form1
     Public WithEvents bot As AW.Instance
     Public WithEvents bot As AW.Instance
     Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click
     Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click

Latest revision as of 15:01, 28 July 2021

A simple greeter bot

  • Visual Studio VB.NET

This program implements a very simple greeter bot. The bot logs into the universe, enters a world, and says "Greetings [name]" to every user that enters the world. You will need to download the AWSDK and ActiveWorlds SDK .NET Wrapper to use this program.

This example is used on Windows Forms. You must add a button to login and a timer to detect events.

Place the files aw.dll and AW.Core.dll in the folder from where the exe will run in i.e. [app name]/bin/Release (or Debug) Go the applications properties/references and click on the "add" button. Then click on "browse" and go to the folder where you put those .dll files and choose the AW.Core.dll (No need to do anything with the aw.dll) Then move back up in the properties to "Compile". There change the "Target CPU" to "x86" (The wrapper will not support x64)

Imports AW


Public Class Form1

    Public WithEvents bot As AW.Instance
    Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click
        Dim result As AW.Result
        bot = New Instance()

        AddHandler bot.EventAvatarAdd, AddressOf AW_EventAvatarAdd

        bot.Attributes.LoginName = "Name of the bot"
        bot.Attributes.LoginPrivilegePassword = "Password"
        bot.Attributes.LoginOwner = 12345
        result = bot.Login()

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
            bot.Dispose()
            bot = Nothing
            Exit Sub
        End If

        result = bot.Enter("Name of the world")

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
            Exit Sub
        End If

        bot.Attributes.MyX = 0 'X position of the bot in centimeters (W positive/E negative)  
        bot.Attributes.MyY = 0 'Y position of the bot in centimeters (height)  
        bot.Attributes.MyZ = 0 'Z position of the bot in centimeters (N positive/S negative)  
        bot.Attributes.MyYaw = 0 'In tenths of a degree. (0 to 3599)
        result = bot.StateChange()

        If Not result = AW.Result.Success Then
            MsgBox("Error: " & result.ToString)
        End If
    End Sub

    Private Sub AW_EventAvatarAdd(ByVal sender As AW.Instance)

        Dim session As Integer = sender.Attributes.AvatarSession
        Dim name As String = sender.Attributes.AvatarName

        sender.Say("Greetings " & name & "! Welcome to Active Worlds :-)")
        'Or whisper to the user:
        'sender.Whisper(session, "Greetings " & name & "! Welcome to Active Worlds :-)")
    End Sub

    Private Sub AWTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AWTimer.Tick
        Utility.Wait(0)
    End Sub

End Class