Aller au contenu

Photo

Objects and while looping, bug?


  • Veuillez vous connecter pour répondre
27 réponses à ce sujet

#26
Shallina

Shallina
  • Members
  • 1 011 messages
yup if you change the tag you won't be able to refer that object as before for action that happend after.

If you need to keep that tag, an other approach is to store a local var in the object that was checked.

SetLocalInt(waypoint,"checked",TRUE);

But that won't work alone.

Or you can use different tag for your waypoints, and construct the tag.

tag = WP1,WP2,WP3 ectc....

int i =1;
String sTag = "WP" + IntToString(i);
While (isObjectValid(GetOBjectByTag(sTag)){


String sTag = "WP" + IntToString(++i);

}

Well something like that.

The "way to access the object" need to be altered so the object won't be accessed again. Or you have the problem of the infinite loop.

Modifié par Shallina, 02 avril 2012 - 04:11 .


#27
kamal_

kamal_
  • Members
  • 5 240 messages
This is for my commoner ai project. Any requirement for a builder to change a tag is verboten by the project, even if it's tag1, tag2 etc. Not requiring the builder to change tags is a core requirement. lots of testing and the assistance in this thread has eliminated the infinite looping.

The system has currently passed all waypoint related tests that there is code for. Npcs correctly follow schedules, randomly choose their activity for a time period and randomly choose from the activity waypoints for a time period and move to them. They also automatically equip and unequip as appropriate for the activity without a builder having to set inventory (appropriate dress code not yet added). The current bugs are animation related.

Additional features like the waypoint in use detection have to wait until the basics are working 100%. it's not important a this point and having code for too many things going through my head will just confuse me.

#28
kevL

kevL
  • Members
  • 4 056 messages
kamal_

this might be interesting (Pastebin). It adds two things: MinDistance and not using objects that are already in use. The latter is accomplished by appending a string to the selected object's tag "_caiUse", then removing it when the NPC using that object selects (or tries to select..) another. Note the NPC *can* select the same object again ....


At first I played around with MinDist. But in the first iteration that i had, it was doing the same thing as "_caiUse" so the counting routines got changed to use GetFirst/NextObjectInShape. (which is probly what should have been done from the git-go..)

- changed the function name, because "kL_GetRandomUnusedObjectWithMinAndMaxDistances()" didn't sound right 8|_`


ps. Naturally keep your backup solid 'cause this could screwthings up a lot.

nyway, peruse at yer leisure & discretion,


Edit. simplified the convoluted method of reverting the tag .....

Modifié par kevL, 15 mars 2013 - 11:22 .