Thread

more than1 bot: creation/selection problem (Sdk)

more than1 bot: creation/selection problem // Sdk

1  |  

x@x.com (xelag)

Nov 9, 1998, 3:12pm
Thanks to Kevin MacLennan's help i got VisualBasic6 to make me a bot.
Deaf he is (and will remain until VB6 can use the API, who can help?),
but cool. I wish to create more than one, and here's (one of) my
problem(s):

Whatever bot I create seems to count, but only the first one reacts,
talks etc (etc=not much more at this stage!). I suspect my
understanding of aw_instance and aw_instance_set is defective, I get
one number per session, something like 215550416, no matter how many
bots I make. I would like to register the instances to be able to
switch from one to the other.

My definitions of both (which might be wrong) are:
'AWAPI void* aw_instance (void);
Public Declare Function aw_instance Lib "aw.dll" () As Long
'AWAPI int aw_instance_set (void *instance);
Public Declare Function aw_instance_set Lib "aw.dll" (ByRef instance
As Any) As Long

Also, av_create has an 'instance', by default set to 0?

How can I set Bot0, Bot1, and Bot2 to be the actors?

Here's part of the code I use.

I first create a form, and in Form_Load i do the preliminaries:
====<code>
Private Sub Form_Load()

Dim rc As Long
Dim c as String
' Ini File
On Error GoTo Form_Load_Error
IniFile = App.Path & "\Bot1.ini"
' etc, i initialize ApplicationName, MaxBot to 3, LoginOwner,
' and PrivilegePassword.
MaxBot = Int(MaxBot): If MaxBot < 1 Then MaxBot = 1
ReDim botSlot(0 To MaxBot)
' initialize ActiveWorlds API
rc = aw_init(AW_BUILD)
If rc <> 0 Then
MsgBox "Unable to initiate API (reason " & rc & ")."
End
End If
' install handler for avatar_add event
' should this be here or is it instance related????
rc = aw_event_set(AW_EVENT_AVATAR_ADD, AddressOf evtAvatarAdd)
Exit Sub
Form_Load_Error:
Err.Clear
Resume Next
End Sub
'====</code>
Then I start creating my bots like this, triggered by some user input:
the type of botSlot() is roBot, defined as
Type roBot
Logged As Boolean
instance As Long
Caption As String
World As String
NS As Long
WE As Long
Altitude As Long
Rotation As Long
Avatar As Long
Gesture As Long
End Type
'====<code>
Public Function BotLogin(ByVal botNr)
Dim rc As Long, c As String
On Error GoTo BotLoginError
BotLogin = False
With botSlot(botNr)
If .Logged = True Then GoTo BotLoginEnd
If .Caption = "" Then .Caption = "DeafBot" & botNr
If .World = "" Then .World = "Beta"
' create bot instance
rc = aw_create("auth.activeworlds.com", 5670, botNr)
If rc <> 0 Then GoTo BotLoginFailed
' log bot into the universe
rc = aw_int_set(AW_LOGIN_OWNER, LoginOwner)
rc = aw_string_set(AW_LOGIN_PRIVILEGE_PASSWORD,
PrivilegePassword)
rc = aw_string_set(AW_LOGIN_APPLICATION, ApplicationName)
rc = aw_string_set(AW_LOGIN_NAME, .Caption)
rc = aw_login()
If rc <> 0 Then GoTo BotLoginFailed
' log bot into a world
rc = aw_enter(.World, 0)
If rc <> 0 Then GoTo BotLoginFailed
rc = aw_int_set(AW_MY_X, .WE)
rc = aw_int_set(AW_MY_Z, .NS)
rc = aw_int_set(AW_MY_Y, .Altitude)
rc = aw_int_set(AW_MY_YAW, .Rotation)
rc = aw_int_set(AW_MY_TYPE, .Avatar)
rc = aw_state_change()
.instance = aw_instance()
Call aw_say("Hi, I'm " & .Caption & ", a VB6.0 freak...")
.Logged = True
End With
BotLogin = True
Exit Function
BotLoginError:
' debug code omitted
Resume Next
BotLoginEnd:
' degug code omitted
Exit Function
BotLoginFailed:
' debug code omitted
End Function
'====</code>


TIA, XelaG

x@x.com (xelag)

Nov 9, 1998, 6:21pm
I solved the mystery:

1. my VB6 definition of aw_instance_set was incorrect, should be ByVal
instead of ByRef:
'AWAPI int aw_instance_set (void *instance);
Public Declare Function aw_instance_set Lib "aw.dll" (ByVal Instance
As Any) As Long

2. the definition and example for aw_create given in the specs in
www.activeworlds.com/sdk is confusing, at least for a non C/C++ human:
the third parameter returns the new bot's instance number and, at
least in VB, should pass a variable to retreive its value.

XelaG.

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn