Having issues with CreateObject
Posted: Tue Feb 17, 2004 11:10 pm
I am using CreateObject, and it is causing me problems. It compiles fine in the toolset, but seems to crash NWN when I use it in code.
NOTE:
bazaarmerchant+doubledigitnumber is the tag of a merchant
q_bazaarmerchant is the resref of the creature that acts as a merchant for the merchant
Merchantof sets which merchant object the creature will be linked to.
CODE (on enter script for an area):
void main()
{
int iNumMerchants=7;
int a;
location lSpawn;
string sSpawn;
a=Random(2);
while(a<iNumMerchants)
{
if(a>9)
{
sSpawn="bazaarmerchant"+IntToString(a);
} else
{
sSpawn="bazaarmerchant0"+IntToString(a);
}
lSpawn=GetLocation(GetObjectByTag(sSpawn));
sSpawn="q_"+sSpawn;
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn,FALSE,sSpawn);
SetLocalInt(GetObjectByTag(sSpawn),"Merchantof",a);
a=a+1+Random(2);
}
}
CONDENSED CODE TO CHECK CreateObject (another OnEnter script):
void main()
{
int a=1;
location lSpawn;
string sSpawn;
sSpawn="bazaarmerchant0"+IntToString(a);
lSpawn=GetLocation(GetObjectByTag(sSpawn));
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn);
}
Now, am I doing something wrong, or is CreateObject just messed up?
NOTE:
bazaarmerchant+doubledigitnumber is the tag of a merchant
q_bazaarmerchant is the resref of the creature that acts as a merchant for the merchant
Merchantof sets which merchant object the creature will be linked to.
CODE (on enter script for an area):
void main()
{
int iNumMerchants=7;
int a;
location lSpawn;
string sSpawn;
a=Random(2);
while(a<iNumMerchants)
{
if(a>9)
{
sSpawn="bazaarmerchant"+IntToString(a);
} else
{
sSpawn="bazaarmerchant0"+IntToString(a);
}
lSpawn=GetLocation(GetObjectByTag(sSpawn));
sSpawn="q_"+sSpawn;
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn,FALSE,sSpawn);
SetLocalInt(GetObjectByTag(sSpawn),"Merchantof",a);
a=a+1+Random(2);
}
}
CONDENSED CODE TO CHECK CreateObject (another OnEnter script):
void main()
{
int a=1;
location lSpawn;
string sSpawn;
sSpawn="bazaarmerchant0"+IntToString(a);
lSpawn=GetLocation(GetObjectByTag(sSpawn));
CreateObject(OBJECT_TYPE_CREATURE,"q_bazaarmerchant",lSpawn);
}
Now, am I doing something wrong, or is CreateObject just messed up?