Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Class Cog Question
Class Cog Question
2006-05-15, 10:40 AM #1
I have an NPC class cog that I'm using for pedestrian conversations and I want to randomize the various responses the NPC can give. However, if an NPC exhibits one response, I want that response to be consistent for that individual NPC without having to assign each NPC an individual class cog with its own responses.

So my question is, if I have a randomizer run in a class cog at startup, is the returned value different for each NPC with the class cog or consistent across the same cog to all NPCs?
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2006-05-15, 10:51 AM #2
I think it will be individual for each instance of the cog. You could have a master cog calculate the random value and make the class cogs retrieve it using triggers, though.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2006-05-15, 5:21 PM #3
Simpler method, and I love heaps. <3
Code:
Startup:
   Sleep(.25); // Safety to make sure all things are created
   HeapNew(0, GetThingCount());
   For(i=0; i<GetThingCount(); i=i+1)
      HeapSet(i, -1);
   Return;

Touched:
   If(HeapGet(GetSenderRef()) < 0)
   {
      HeapSet(GetSenderRef(), Rand()*numpossibilities);
   }

   If(HeapGet(GetSenderRef()) <= 1)
   {
      // Do one thing
   }
   Else If(HeapGet(GetSenderRef()) <= 2)
   {
      // Do another thing
   }
   Else If(HeapGet(GetSenderRef()) <= 3)
   {
      // Do another thing, etc.
   }
   /// ...
   Return;

Note, this is based upon the assumption that the things are not created after startup.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2006-05-16, 7:37 AM #4
Oh wow, I didn't think of using heaps... that's great! :D Thanks.
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2006-05-16, 9:24 AM #5
Reminder: There is only *one* instance of a class cog per template for all things that use that template.

Several comments about Descent_pilot's cog:

- The Sleep in startup is useless. There is no reason to have it. I have confirmed that things placed in the level are created before startup is ever called.

- HeapNew was discovered to use only one parameter. Anyone looking at the Hub Reference (which has the most current cog info) would know this.

- The heap is certainly a good way to handle the NPC situation, but be sure you note what each heap slot key (GetSenderRef() in the example) and value means.

:)
2006-05-20, 10:25 AM #6
Originally posted by ZeqMacaw:
Reminder: There is only *one* instance of a class cog per template for all things that use that template.

Several comments about Descent_pilot's cog:

- The Sleep in startup is useless. There is no reason to have it. I have confirmed that things placed in the level are created before startup is ever called.

- HeapNew was discovered to use only one parameter. Anyone looking at the Hub Reference (which has the most current cog info) would know this.

- The heap is certainly a good way to handle the NPC situation, but be sure you note what each heap slot key (GetSenderRef() in the example) and value means.


Counter points, I've had problems with manipulating things on startup, sleep is a safety catch, doesn't hurt anything.

Whoops, habit on the heap. (see, me old school cogger lol)
<.<
>.>

Heaps = Godsend of JK programmers for cog.

Thats all. :p
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!