Thread

Totally confused about object query (Bots)

Totally confused about object query // Bots

1  |  

pj47

Mar 30, 2000, 12:25am
Hi-

Can someone who knows about object querying tell me what I am doing wrong?
I am trying to get a bot to change an object into a teleport (and, of
course, eventually change it back). I tried to modify the SDK Sample 2
DJBot program and it works fine at ground zero (with the object at 1N 1W)
when I leave the querying commands as in the sample program.

The problem is when I try to translate it to an object that my world reports
as being at 17N 9W and that Buildbot says is at 17600NS 9700WE 10110A.
(Note: it is at about 101.1 altitude, although I don't think that matters).

It seems to me that I need to make the following changes to the querying
code to find this object:
1) Change first query command to aw_query (1, 2, sequence)
2) Also change the query command in void handle_query (int rc) to aw_query
(1, 2, sequence)
3) Change to cell_x == 9 && cell_x==17 in void handle_cell_object (void)

However, this just goes into a continual loop looking for x number of bytes
over and over (query never seems to end). What am I missing? It appears
that the query is not being updated at 16N 8W.

[Also, out of curiosity, how does the SDK get away with things like:
if (rc = aw_query (0, 0, sequence))

I'm a novice but it seems I was trained that you need double equal signs for
Boolean expressions]

FYI. The code I am using is below:

#include "stdafx.h"
#include "aw.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FIVE_MINUTES (5 * 60 * 1000)
#define CHANGE_OBJECT "dreser01.rwx"
#define WORLD "hitchhke"

void handle_cell_begin (void);
void handle_cell_object (void);
void handle_query (int rc);
void change_object (void);

int owner;
int sequence[3][3];
int obj_x;
int obj_y;
int obj_z;
int obj_yaw;
int obj_number = 0;
int cell_x;
int cell_z;


main (int argc, char *argv[])
{

int rc;

/* check command line */
if (argc < 3) {
printf ("Usage: %s number password\n", argv[0]);
exit (1);
}

/* initialize Active Worlds API */
if (rc = aw_init (AW_BUILD)) {
printf ("Unable to initialize API (reason %d)\n", rc);
exit (1);
}

/* install cell update event handlers */
aw_event_set (AW_EVENT_CELL_BEGIN, handle_cell_begin);
aw_event_set (AW_EVENT_CELL_OBJECT, handle_cell_object);

/* install query callback */
aw_callback_set (AW_CALLBACK_QUERY, handle_query);

/* create bot instance */
if (rc = aw_create (0, 0, 0)) {
printf ("Unable to create bot instance (reason %d)\n", rc);
exit (1);
}

/* log bot into the universe */
owner = atoi (argv[1]);
aw_int_set (AW_LOGIN_OWNER, owner);
aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]);
aw_string_set (AW_LOGIN_NAME, "Jed");
if (rc = aw_login ()) {
printf ("Unable to login (reason %d)\n", rc);
exit (1);
}

/* log bot into the world */
if (rc = aw_enter (WORLD, 0)) {
printf ("Unable to enter world (reason %d)\n", rc);
exit (1);
}

/* issue first property query for the ground zero area so that we can
locate
the SPEAKER_OBJECT */
printf ("Looking for object...\n");
if (rc = aw_query (1, 2, sequence)) {
printf ("Unable to query property (reason %d)\n", rc);
exit (1);
}

/* wait for query to complete and then change music every five minutes */
while (!(rc = aw_wait (FIVE_MINUTES)))
if (obj_number)
change_object();

/* close everything down */
aw_destroy ();
aw_term ();
return 0;

}

void change_object (void)
{

int rc;
char action[100];

aw_int_set (AW_OBJECT_OLD_NUMBER, obj_number);
aw_int_set (AW_OBJECT_OLD_X, obj_x);
aw_int_set (AW_OBJECT_OLD_Z, obj_z);
aw_int_set (AW_OBJECT_X, obj_x);
aw_int_set (AW_OBJECT_Y, obj_y);
aw_int_set (AW_OBJECT_Z, obj_z);
aw_int_set (AW_OBJECT_YAW, obj_yaw);
aw_int_set (AW_OBJECT_OWNER, owner);
aw_string_set (AW_OBJECT_MODEL, CHANGE_OBJECT);
aw_string_set (AW_OBJECT_DESCRIPTION, "");
sprintf (action, "create solid off, visible off;bump teleport 5N 5W
102a");
aw_string_set (AW_OBJECT_ACTION, action);
if (rc = aw_object_change ())
printf ("Unable to change object (reason %d)\n", rc);
else {
printf ("Object changed.\n");
obj_number = aw_int (AW_OBJECT_NUMBER);
}

}

void handle_cell_begin (void)
{

int sector_x;
int sector_z;

/* This is called to indicate we are receiving the contents of a new cell.
All
we need to do here is update the sequence number array for the next
call to
aw_query (). */
cell_x = aw_int (AW_CELL_X);
cell_z = aw_int (AW_CELL_Z);
sector_x = aw_sector_from_cell (cell_x);
sector_z = aw_sector_from_cell (cell_z);
sequence[sector_z + 1][sector_x + 1] = aw_int (AW_CELL_SEQUENCE);

}

void handle_cell_object (void)
{

/* This is called once for each object in each cell that we are querying.
We
check to see if the object is the OBJECT we are looking for, by
checking the name of the object and the cell it is located in. */
if (cell_x == 9 && cell_z == 17 &&
!strcmp (aw_string (AW_OBJECT_MODEL), CHANGE_OBJECT)) {
obj_x = aw_int (AW_OBJECT_X);
obj_y = aw_int (AW_OBJECT_Y);
obj_z = aw_int (AW_OBJECT_Z);
obj_yaw = aw_int (AW_OBJECT_YAW);
obj_number = aw_int (AW_OBJECT_NUMBER);
printf ("Object located!\n");
change_object();
}

}

void handle_query (int rc)
{

/* This is called when the server has stopped sending property data. If
we haven't
found the speaker yet, then we check if the query is complete, and if
not,
issue a new query with the updated sequence numbers to continue the
update. */
if(!obj_number)
if (!aw_bool (AW_QUERY_COMPLETE))
aw_query (1, 2, sequence);
else
/* the query is complete but we didn't find the speaker! :( */
printf ("Couldn't find object.\n");

}

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