Thread

object adding/modification/deletion (Sdk)

object adding/modification/deletion // Sdk

1  |  

pc wizard

Sep 26, 1998, 11:38pm
Ok.. here's what I'm trying to do:
I have my bot enter the world (all rights, I'm caretaker...) and it puts an
object there (zjuke.rwx with create sound on it) and that works... but then
I'm trying to get it to where they say something (like "start the music")
and it will change the create sound to a different midi.... the only thing
is it can't change it.. it always comes up with a reason code 204 (cannot
find element I think). I tried making something where it deleted the object
and it does the same thing.. here's part of my code:


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

#define bot_owner "PC Wizard"

#define bot_name "Megahertz"

#define music1 "Start the music"
#define laugh1 "lol"
#define laugh2 "roflmao"

void handle_avatar_add (void);
void avatar_delete (void);
void chat (void);
void handle_chat (void);
void AW_TERM (void);
int AW_DESTROY (void);
int AW_WORLD_EJECT (void);
int AW_OBJECT_CHANGE (void);

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 handler for avatar_add event */
/* Handlers ----------------- Handlers */
aw_event_set (AW_EVENT_AVATAR_ADD, handle_avatar_add);
aw_event_set (AW_EVENT_AVATAR_DELETE, avatar_delete);
aw_event_set (AW_EVENT_CHAT, chat);
aw_event_set (AW_EVENT_CHAT, handle_chat);
/* Handlers ----------------- Handlers */
/*======================================*/

/* 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 */
aw_int_set (AW_LOGIN_OWNER, atoi (argv[1]));
aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]);
aw_string_set (AW_LOGIN_APPLICATION, "PC Wizards bot program");
aw_string_set (AW_LOGIN_NAME, bot_name);
//aw_string_set (AW_LOGIN_NAME, argv[3]);
if (rc = aw_login ()) {
printf ("Unable to login (reason %d)\n", rc);
exit (1);
}

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


/* announce our position in the world */
aw_int_set (AW_MY_X, 800); /* .8W */
aw_int_set (AW_MY_Z, 800); /* .8N */
aw_int_set (AW_MY_Y, 0);
aw_int_set (AW_MY_YAW, 2250); /* face towards GZ */
aw_int_set (AW_MY_TYPE, 251);
if (rc = aw_state_change ()) {
printf ("Unable to change state (reason %d)\n", rc);
exit (1);
}

aw_int_set (AW_OBJECT_X, 1000);
aw_int_set (AW_OBJECT_Y, 0);
aw_int_set (AW_OBJECT_Z, 700);
aw_int_set (AW_OBJECT_NUMBER, 1);
aw_int_set (AW_OBJECT_YAW, 2250);
aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
aw_string_set (AW_OBJECT_DESCRIPTION, "-Playing-");
aw_string_set (AW_OBJECT_ACTION, "create sound
http://midivault.ml.org:81/misc/Nebula.mid");
if (rc = aw_object_add ())
printf ("Unable to add object (reason %d)\n", rc);
else
puts ("Object added");


/* main event loop */
while (!aw_wait (-1))
;


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

}

void handle_avatar_add (void)
{

char message[100];

if (!strcmp (aw_string (AW_AVATAR_NAME), bot_owner)) {
//sprintf (message, "Ah, my master has entered, hello", aw_string
(AW_AVATAR_NAME));
sprintf (message, "Ah, my creator has entered! Hello %s", aw_string
(AW_AVATAR_NAME));

}

else {
sprintf (message, "Hello %s, I'm %s, and I'll be your host tonight.",
aw_string (AW_AVATAR_NAME), bot_name);
}
aw_say (message);

/* log the event to the console */
printf ("avatar_add: %s\n", aw_string (AW_AVATAR_NAME));

}

void avatar_delete (void)
{

char message[101];

sprintf (message, "%s just left" , aw_string (AW_AVATAR_NAME));
aw_say (message);
/* message to console */
printf ("avatar_delete: %s\n", aw_string (AW_AVATAR_NAME));


}

static char* chat_type[] = {"said", "broadcast", "whispered"};

void chat (void)

{

printf ("Session %d %s %s\n", aw_int (AW_CHAT_SESSION),
chat_type[aw_int (AW_CHAT_TYPE)], aw_string (AW_CHAT_MESSAGE));

}


void handle_chat (void)
{
int rc;
if (strstr (aw_string (AW_CHAT_MESSAGE), bot_name)) {
aw_say ("That's my name, don't wear it out! :)");
}
else if (strstr (aw_string (AW_CHAT_MESSAGE), laugh1)) {
aw_say ("hahaha");
}
else if (strstr (aw_string (AW_CHAT_MESSAGE), laugh2)) {
aw_say ("LOL!");
}

}

/*Music=============================Music*/
if (strstr (aw_string (AW_CHAT_MESSAGE), music1)) {
aw_say ("*starts up the juke box* -KICK-");
aw_int_set (AW_OBJECT_OLD_NUMBER, 1);
aw_int_set (AW_OBJECT_OLD_X, 1000);
aw_int_set (AW_OBJECT_OLD_Z, 700);
aw_int_set (AW_OBJECT_NUMBER, 2);
aw_int_set (AW_OBJECT_X, 1000);
aw_int_set (AW_OBJECT_Y, 0);
aw_int_set (AW_OBJECT_Z, 700);
aw_int_set (AW_OBJECT_YAW, 2250);
aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
aw_string_set (AW_OBJECT_DESCRIPTION, "Local H -Bound For The Floor");
aw_string_set (AW_OBJECT_ACTION, "create sound
http://midivault.ml.org:81/bands/Local_H/BoundForTheFloor.mid");

if (rc = aw_object_change ())
printf ("Unable to change object (reason %d)\n", rc);
else
puts ("Object changed");
}


}

I used the Sample 1 to start the bot.. then I just added to that. But I've
tried everything I can think of (which isn't much :)) to get it to change
the object but it always does a 204 error.... and the object is in the
world.. Also:
Can anybody give me an example on how I could get the bot to read what
someone says from a command and then take a midi address that they said and
put it in for the create sound? sorta like a request..

PC Wizard (ICQ-537376)
wizardry at home.com
http://pcwizard.ml.org

jan-willem de bleser

Sep 27, 1998, 12:21am
This is a multi-part message in MIME format.
--------------E601EF56B13A29D00DD072D5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

you know that error 204 means that it cant find the old object, right?
my guess is that the error is in the following code:

if (strstr (aw_string (AW_CHAT_MESSAGE), music1)) {
aw_say ("*starts up the juke box* -KICK-");
aw_int_set (AW_OBJECT_OLD_NUMBER, 1);
aw_int_set (AW_OBJECT_OLD_X, 1000);
aw_int_set (AW_OBJECT_OLD_Z, 700);
aw_int_set (AW_OBJECT_NUMBER, 2);
aw_int_set (AW_OBJECT_X, 1000);
aw_int_set (AW_OBJECT_Y, 0);
aw_int_set (AW_OBJECT_Z, 700);
aw_int_set (AW_OBJECT_YAW, 2250);
aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
aw_string_set (AW_OBJECT_DESCRIPTION, "Local H -Bound For The Floor");
aw_string_set (AW_OBJECT_ACTION, "create sound
http://midivault.ml.org:81/bands/Local_H/BoundForTheFloor.mid");

if (rc = aw_object_change ())
printf ("Unable to change object (reason %d)\n", rc);
else
puts ("Object changed");


[View Quote] > Ok.. here's what I'm trying to do:
> I have my bot enter the world (all rights, I'm caretaker...) and it puts an
> object there (zjuke.rwx with create sound on it) and that works... but then
> I'm trying to get it to where they say something (like "start the music")
> and it will change the create sound to a different midi.... the only thing
> is it can't change it.. it always comes up with a reason code 204 (cannot
> find element I think). I tried making something where it deleted the object
> and it does the same thing.. here's part of my code:
>
> #include "aw.h"
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> #define bot_owner "PC Wizard"
>
> #define bot_name "Megahertz"
>
> #define music1 "Start the music"
> #define laugh1 "lol"
> #define laugh2 "roflmao"
>
> void handle_avatar_add (void);
> void avatar_delete (void);
> void chat (void);
> void handle_chat (void);
> void AW_TERM (void);
> int AW_DESTROY (void);
> int AW_WORLD_EJECT (void);
> int AW_OBJECT_CHANGE (void);
>
> 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 handler for avatar_add event */
> /* Handlers ----------------- Handlers */
> aw_event_set (AW_EVENT_AVATAR_ADD, handle_avatar_add);
> aw_event_set (AW_EVENT_AVATAR_DELETE, avatar_delete);
> aw_event_set (AW_EVENT_CHAT, chat);
> aw_event_set (AW_EVENT_CHAT, handle_chat);
> /* Handlers ----------------- Handlers */
> /*======================================*/
>
> /* 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 */
> aw_int_set (AW_LOGIN_OWNER, atoi (argv[1]));
> aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]);
> aw_string_set (AW_LOGIN_APPLICATION, "PC Wizards bot program");
> aw_string_set (AW_LOGIN_NAME, bot_name);
> //aw_string_set (AW_LOGIN_NAME, argv[3]);
> if (rc = aw_login ()) {
> printf ("Unable to login (reason %d)\n", rc);
> exit (1);
> }
>
> /* log bot into the world called "wizardry" */
> if (rc = aw_enter ("wizardry", 0)) {
> printf ("Unable to enter world (reason %d)\n", rc);
> exit (1);
> }
>
> /* announce our position in the world */
> aw_int_set (AW_MY_X, 800); /* .8W */
> aw_int_set (AW_MY_Z, 800); /* .8N */
> aw_int_set (AW_MY_Y, 0);
> aw_int_set (AW_MY_YAW, 2250); /* face towards GZ */
> aw_int_set (AW_MY_TYPE, 251);
> if (rc = aw_state_change ()) {
> printf ("Unable to change state (reason %d)\n", rc);
> exit (1);
> }
>
> aw_int_set (AW_OBJECT_X, 1000);
> aw_int_set (AW_OBJECT_Y, 0);
> aw_int_set (AW_OBJECT_Z, 700);
> aw_int_set (AW_OBJECT_NUMBER, 1);
> aw_int_set (AW_OBJECT_YAW, 2250);
> aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
> aw_string_set (AW_OBJECT_DESCRIPTION, "-Playing-");
> aw_string_set (AW_OBJECT_ACTION, "create sound
> http://midivault.ml.org:81/misc/Nebula.mid");
> if (rc = aw_object_add ())
> printf ("Unable to add object (reason %d)\n", rc);
> else
> puts ("Object added");
>
> /* main event loop */
> while (!aw_wait (-1))
> ;
>
> /* close everything down */
> aw_destroy ();
> aw_term ();
> return 0;
>
> }
>
> void handle_avatar_add (void)
> {
>
> char message[100];
>
> if (!strcmp (aw_string (AW_AVATAR_NAME), bot_owner)) {
> //sprintf (message, "Ah, my master has entered, hello", aw_string
> (AW_AVATAR_NAME));
> sprintf (message, "Ah, my creator has entered! Hello %s", aw_string
> (AW_AVATAR_NAME));
>
> }
>
> else {
> sprintf (message, "Hello %s, I'm %s, and I'll be your host tonight.",
> aw_string (AW_AVATAR_NAME), bot_name);
> }
> aw_say (message);
>
> /* log the event to the console */
> printf ("avatar_add: %s\n", aw_string (AW_AVATAR_NAME));
>
> }
>
> void avatar_delete (void)
> {
>
> char message[101];
>
> sprintf (message, "%s just left" , aw_string (AW_AVATAR_NAME));
> aw_say (message);
> /* message to console */
> printf ("avatar_delete: %s\n", aw_string (AW_AVATAR_NAME));
>
> }
>
> static char* chat_type[] = {"said", "broadcast", "whispered"};
>
> void chat (void)
>
> {
>
> printf ("Session %d %s %s\n", aw_int (AW_CHAT_SESSION),
> chat_type[aw_int (AW_CHAT_TYPE)], aw_string (AW_CHAT_MESSAGE));
>
> }
>
> void handle_chat (void)
> {
> int rc;
> if (strstr (aw_string (AW_CHAT_MESSAGE), bot_name)) {
> aw_say ("That's my name, don't wear it out! :)");
> }
> else if (strstr (aw_string (AW_CHAT_MESSAGE), laugh1)) {
> aw_say ("hahaha");
> }
> else if (strstr (aw_string (AW_CHAT_MESSAGE), laugh2)) {
> aw_say ("LOL!");
> }
>
> }
>
> /*Music=============================Music*/
> if (strstr (aw_string (AW_CHAT_MESSAGE), music1)) {
> aw_say ("*starts up the juke box* -KICK-");
> aw_int_set (AW_OBJECT_OLD_NUMBER, 1);
> aw_int_set (AW_OBJECT_OLD_X, 1000);
> aw_int_set (AW_OBJECT_OLD_Z, 700);
> aw_int_set (AW_OBJECT_NUMBER, 2);
> aw_int_set (AW_OBJECT_X, 1000);
> aw_int_set (AW_OBJECT_Y, 0);
> aw_int_set (AW_OBJECT_Z, 700);
> aw_int_set (AW_OBJECT_YAW, 2250);
> aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
> aw_string_set (AW_OBJECT_DESCRIPTION, "Local H -Bound For The Floor");
> aw_string_set (AW_OBJECT_ACTION, "create sound
> http://midivault.ml.org:81/bands/Local_H/BoundForTheFloor.mid");
>
> if (rc = aw_object_change ())
> printf ("Unable to change object (reason %d)\n", rc);
> else
> puts ("Object changed");
> }
>
> }
>
> I used the Sample 1 to start the bot.. then I just added to that. But I've
> tried everything I can think of (which isn't much :)) to get it to change
> the object but it always does a 204 error.... and the object is in the
> world.. Also:
> Can anybody give me an example on how I could get the bot to read what
> someone says from a command and then take a midi address that they said and
> put it in for the create sound? sorta like a request..
>
> PC Wizard (ICQ-537376)
> wizardry at home.com
> http://pcwizard.ml.org



--------------E601EF56B13A29D00DD072D5
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jan-willem De Bleser
Content-Disposition: attachment; filename="vcard.vcf"

begin: vcard
fn: Jan-willem De Bleser
n: De Bleser;Jan-willem
org: High school
email;internet: debleser at mediaone.net
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard


--------------E601EF56B13A29D00DD072D5--

roland vilett

Sep 27, 1998, 12:28am
Object creation and manipulation is no doubt by far the most difficult
aspect of using the SDK. As soon as I get a free moment, I'm going to
create Sample Application #2 for the SDK which will implement a simple DJ
bot, much like yours, although I plan to have it simply rotate through a
fixed list of MIDI files to keep it simpler.

One problem with your app is that it creates the juke box object each time
you run it. That's fine for testing but for a real bot that's not good
because you are going to wind up with a pile of juke boxes, one on top of
the other, one for each time you ran your bot. A better approach I think is
to create the juke box object yourself (by hand) and instead have the bot
look for it when it starts up. However this is a bit tricky because it
involves using aw_query(), probably the single most complex call in the SDK.
I will illustrate all of this in the next sample application.

One thing that you'll have to change in your code as it currently stands is
that after the aw_object_add() call succeeds, you'll need to query and save
the value of the AW_OBJECT_NUMBER attribute. This is a 32-bit integer that
uniquely identifies the object within the cell. Then before the call to
aw_object_change(), set AW_OBJECT_OLD_NUMBER to this value.

The AW_OBJECT_NUMBER attribute is assigned by the SDK, not by you. The docs
are not particularly clear on this point right now. Each time you call
aw_object_change(), you'll need to query the object number again for the
subsequent call to aw_object_change(), something like this:

int number;

aw_int_set (AW_OBJECT_X, 1000);
aw_int_set (AW_OBJECT_Y, 0);
aw_int_set (AW_OBJECT_Z, 700);
aw_int_set (AW_OBJECT_YAW, 2250);
aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
aw_string_set (AW_OBJECT_DESCRIPTION, "-Playing-");
aw_string_set (AW_OBJECT_ACTION, "create sound
http://midivault.ml.org:81/misc/Nebula.mid");
if (rc = aw_object_add ())
printf ("Unable to add object (reason %d)\n", rc);
else {
puts ("Object added");
number = aw_int (AW_OBJECT_NUMBER);
}

....

/*Music=============================Music*/
if (strstr (aw_string (AW_CHAT_MESSAGE), music1)) {
aw_say ("*starts up the juke box* -KICK-");
aw_int_set (AW_OBJECT_OLD_NUMBER, number);
aw_int_set (AW_OBJECT_OLD_X, 1000);
aw_int_set (AW_OBJECT_OLD_Z, 700);
aw_int_set (AW_OBJECT_X, 1000);
aw_int_set (AW_OBJECT_Y, 0);
aw_int_set (AW_OBJECT_Z, 700);
aw_int_set (AW_OBJECT_YAW, 2250);
aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
aw_string_set (AW_OBJECT_DESCRIPTION, "Local H -Bound For The Floor");
aw_string_set (AW_OBJECT_ACTION, "create sound
http://midivault.ml.org:81/bands/Local_H/BoundForTheFloor.mid");

if (rc = aw_object_change ())
printf ("Unable to change object (reason %d)\n", rc);
else {
puts ("Object changed");
number = aw_int (AW_OBJECT_NUMBER);
}


[View Quote]

jan-willem de bleser

Oct 2, 1998, 9:22am
This is a multi-part message in MIME format.
--------------7F15B42C298FD36F2C295557
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



[View Quote] > Object creation and manipulation is no doubt by far the most difficult
> aspect of using the SDK. As soon as I get a free moment, I'm going to
> create Sample Application #2 for the SDK which will implement a simple DJ
> bot, much like yours, although I plan to have it simply rotate through a
> fixed list of MIDI files to keep it simpler.
>
> One problem with your app is that it creates the juke box object each time
> you run it. That's fine for testing but for a real bot that's not good
> because you are going to wind up with a pile of juke boxes, one on top of
> the other, one for each time you ran your bot. A better approach I think is
> to create the juke box object yourself (by hand) and instead have the bot
> look for it when it starts up. However this is a bit tricky because it
> involves using aw_query(), probably the single most complex call in the SDK.
> I will illustrate all of this in the next sample application.
>
> One thing that you'll have to change in your code as it currently stands is
> that



> after the aw_object_add() call succeeds, you'll need to query and save
> the value of the AW_OBJECT_NUMBER attribute.

is this done with aw_query?

> This is a 32-bit integer that
> uniquely identifies the object within the cell. Then before the call to
> aw_object_change(), set AW_OBJECT_OLD_NUMBER to this value.
>
> The AW_OBJECT_NUMBER attribute is assigned by the SDK, not by you. The docs
> are not particularly clear on this point right now. Each time you call
> aw_object_change(), you'll need to query the object number again for the
> subsequent call to aw_object_change(), something like this:
>
> int number;
>
> aw_int_set (AW_OBJECT_X, 1000);
> aw_int_set (AW_OBJECT_Y, 0);
> aw_int_set (AW_OBJECT_Z, 700);
> aw_int_set (AW_OBJECT_YAW, 2250);
> aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
> aw_string_set (AW_OBJECT_DESCRIPTION, "-Playing-");
> aw_string_set (AW_OBJECT_ACTION, "create sound
> http://midivault.ml.org:81/misc/Nebula.mid");
> if (rc = aw_object_add ())
> printf ("Unable to add object (reason %d)\n", rc);
> else {
> puts ("Object added");
> number = aw_int (AW_OBJECT_NUMBER);
> }
>
> ...
>
> /*Music=============================Music*/
> if (strstr (aw_string (AW_CHAT_MESSAGE), music1)) {
> aw_say ("*starts up the juke box* -KICK-");
> aw_int_set (AW_OBJECT_OLD_NUMBER, number);
> aw_int_set (AW_OBJECT_OLD_X, 1000);
> aw_int_set (AW_OBJECT_OLD_Z, 700);
> aw_int_set (AW_OBJECT_X, 1000);
> aw_int_set (AW_OBJECT_Y, 0);
> aw_int_set (AW_OBJECT_Z, 700);
> aw_int_set (AW_OBJECT_YAW, 2250);
> aw_string_set (AW_OBJECT_MODEL, "zjuke.rwx");
> aw_string_set (AW_OBJECT_DESCRIPTION, "Local H -Bound For The Floor");
> aw_string_set (AW_OBJECT_ACTION, "create sound
> http://midivault.ml.org:81/bands/Local_H/BoundForTheFloor.mid");
>
> if (rc = aw_object_change ())
> printf ("Unable to change object (reason %d)\n", rc);
> else {
> puts ("Object changed");
> number = aw_int (AW_OBJECT_NUMBER);
> }
>
[View Quote]

--------------7F15B42C298FD36F2C295557
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Jan-willem De Bleser
Content-Disposition: attachment; filename="vcard.vcf"

begin: vcard
fn: Jan-willem De Bleser
n: De Bleser;Jan-willem
org: High school
email;internet: debleser at mediaone.net
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard


--------------7F15B42C298FD36F2C295557--

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