Having issues with CreateObject

Moderator: Event DM

Post Reply
User avatar
Titanium Dragon
Sage
Posts: 2916
Joined: Sun Apr 27, 2003 5:18 pm
Location: Corvallis, OR (GMT - 7)
Contact:

Having issues with CreateObject

Post by Titanium Dragon » 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?
Gilkin> ouch. how often do you roll a 20?
Cath> once every 20 rolls?
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Tue Feb 17, 2004 11:48 pm

from Lexicon
Creating a creature during the OnEnter event without first checking to see what's actually entering the area causes NWN to enter an infinite loop of creating creatures (as each creature created causes the OnEnter event to fire its attached script again). This can be avoided by testing if GetIsPC(GetEnteringObject()) is true (if its true, then create the creature(s); if its false then a creature that was created fired the event).
so the CreateObject itself triggers the OnEnter as you have it written... hope that helps..
You see things and you say, "Why?" But I dream things that never were and say, "Why not?" George Bernard Shaw
User avatar
Titanium Dragon
Sage
Posts: 2916
Joined: Sun Apr 27, 2003 5:18 pm
Location: Corvallis, OR (GMT - 7)
Contact:

Post by Titanium Dragon » Tue Feb 17, 2004 11:51 pm

Thanks :D That makes perfect sense. Sorry to bother you with something so trivial. :?
Gilkin> ouch. how often do you roll a 20?
Cath> once every 20 rolls?
User avatar
Jordicus
Team Member; Retired with Honors
Posts: 8042
Joined: Tue Jan 21, 2003 3:46 pm
Location: Whitehall, PA (GMT -4)
Contact:

Post by Jordicus » Tue Feb 17, 2004 11:54 pm

not trivial at all.. just one of those things where 1 + 1 is not adding up for some reason.. :P
You see things and you say, "Why?" But I dream things that never were and say, "Why not?" George Bernard Shaw
Post Reply