PDA

View Full Version : Data Exchange + Push Interaction woes


maybesomethingdunno
22nd Jul 2010, 05:00 AM
Maybe I've been looking at this too long and I simply need another opinion. Maybe I'm going about this all the wrong way. Perhaps my little brain isn't developed enough to wrap its feeble self around this. :P I don't know.

Here's my problem...
I'm trying to coordinate and/or pass information between several objects at once and it's driving me insane. :P
Every time I change the order of what appears first or what does what first, I fall into a trap of "wait, how would X know that Y's attribute has a value of true/false?" or "Argh! Why isn't 'Push Interaction' working?!"

What's involved:
The active Sim (the pink / light red colored female figure in the diagram)
An (invisible) object with with a routing slot (the black square and the green square respectfully)
A NPC in a loop where he routes from the routing slot to a location relative to the object (the orange-ish figure and the blue arrows)
A cart object to be snapped in the NPC to carry the active Sim along the NPC's path (the purplish rectangle)
http://img833.imageshack.us/img833/9849/chart.png (http://img833.imageshack.us/i/chart.png/)

Since I don't have a CRES to adjust the positions of the slots of the NPC, the cart object is necessary.

At this point, I think I'd like the NPC to wait at the routing slot until the Sim boards the cart. I understand this can simply be an attribute check ("AmIReady?" == true/false). Once the Sim has boarded the cart, the NPC would start to move. So, somehow the cart would need to change the value of the NPC's "AmIReady?" attribute to get the NPC moving. However...

The Sim must act one way on the trip to the routing slot (the green square) and act another way on the return trip to the general position relative to the main object (the black square). Once again, it would be easy to constantly toggle the value of an attribute within the NPC each time it routes to and fro ("MyDirection"). But, if the Sim is snapped into the cart and the cart is snapped into the NPC, how would that value get sent upwards from object to object? The Sim would be interacting with the cart, so somehow the cart would need to get the information from the NPC, correct? Once the cart is snapped into the NPC, the NPC somewhat forgets it's there. They wouldn't really have any sort of "My/Stack Object" relationship anymore; neither one is actively running an interaction on the other. Thanks to Echo, I have a "Get ID of Closest X" bhav...so, I might could tell the cart/NPC to look for the closest NPC/cart and get its object ID? Or, would that not work for objects snapped into other objects?

Since the object is invisible, I'm using a self-interaction to make the Sim route to the object's routing slot to start the interaction for the time being. The Sim spawns the NPC who automatically spawns the cart into one of his slots. The NPC is waiting for its attribute value to change to start moving. I assume the Sim must be interacting with the cart to be snapped into it, so I assume I'd want to push the Sim into an interaction with it from within the self-interaction. But, I'm failing spectacularly. Even if I had the object spawn the NPC, I'd still have to go from the self-interaction to the cart. I'd probably still have the attributes issue. Conceptually, I could have the Sim spawn the NPC (which would spawn the cart) and just put a delay between the initial movement, but I'd still need the directional information for deciding the Sim's actions.

(I'll worry about if/when to delete the cart and NPC when I get there.)

In the self-interaction, I have:

Spawning the NPC: "[prim 0x002A] Create New Object Instance (GUID 0xwhatever, place: in front of Me, Create object normally,..."

Getting the closest Cart: "[private 0x100C] Get in Temp 0 - ID - Closest Cart (1 arg: My 0x000B (object id))"

"[prim 0x0002] Expression (Local 0x0000 := Temp 0x0000)"

"[prim 0x000D] Push Interaction (Target: Stack Object, Object: Local 0x0000, Interaction: Literal 0x0000, maximum priority, Icon index: Literal 0x0001)"

The NPC and cart are spawned, but the Sim doesn't do anything afterward. When I click on the cart directly, the interaction seems to work fine on that end. Although I don't get an error, the operands for the Push Interaction must be wrong. (It would help if I knew more what I'm doing. :lol: )

I understand the target is the Sim, the object would be the cart, the interaction would be the corresponding TTAB interaction, and the max priority means it's of the up-most importance. I'm not certain what the Icon index is beyond the guess of what the interaction queue icon is. The cart will also be invisible once I'm able to trust that it's doing what it's supposed to be doing, so I'd rather have a custom graphic for the queue icon or the active Sim's face.

Echo
22nd Jul 2010, 10:24 AM
Woah, wall of text! :)

I'm going to have to come back and re-read that in a bit, but a quick note - in your "Push Interaction", the Stack Object will be pointing to the NPC, not the Sim. Is that what you intended?

maybesomethingdunno
22nd Jul 2010, 08:17 PM
That was the tl;dr ("too long; didn't read") version. :giggler: I was hoping a diagram would ease understanding and save people from some confusion-induced verbosity. I guess the matter of whether or not I made any sense is still yet to be determined. :lol:

I want the Sim to perform the interaction, not the NPC. If my memory serves me correctly, I recall trying:

[prim 0x0002] Expression (Stack Object's 0x000B (object id) := Literal 0x0000),
[prim 0x0002] Expression (Stack Object ID 0x0000 := Literal 0x0000),
and even
[prim 0x0002] Expression (Stack Object ID 0x0000 := My 0x000B (object id)) before the Push Interaction.

But I didn't see any change, or maybe I simply goofed and one of those is correct (I simply made a typo or something). I can certainly try again.

Echo
23rd Jul 2010, 12:59 AM
The last one is the one you want, assuming this is being run from an interaction and the one doing the interacting is the sim. :)

Stack Object's 0x000B (object id) is read-only, you can't write to it, so the first one will error.
The second one sets the stack object to point at object 0, which is pretty much guaranteed not to be your sim.

Edit: I'm not sure if you've read this:
http://www.modthesims.info/showthread.php?t=212101
But if you haven't, I'd strongly recommend it. It might help explain what some of these commands are actually doing. :)

maybesomethingdunno
23rd Jul 2010, 02:14 AM
Thanks Echo. While there is always more to learn or to better understand, I often feel much of modding falls under the "use it or lose it" category of knowledge/skills. At times, it seems all too easy to lose the knowledge and understanding of even basic things. (Not that I had much to begin with, but still... :lol: )

Yes, this code is within the self-interaction. It's basically: go here, spawn the NPC in front of me, find the the cart within the NPC (which should be the closest one since the NPC is right there), and push the Sim to interact with the cart. The interaction being the "get on me" interaction.

I seem to have figured out what was wrong! :)

The "Get in Temp 0 - ID - Closest Cart" node to get the closest cart was being called too fast (i.e. before the NPC had fully spawned and/or had a chance to spawn the cart into its slot). So, the "Get in Temp 0 - ID - Closest Cart" was returning false (since it couldn't find one), which would then end the interaction before the Push Interaction was even called. I put in an "idle for 1 Sim minute" node to give the NPC and cart time to spawn. My test Sim successfully routes, spawns the NPC (which spawns the cart), and has the cart's interaction pushed onto her so that she boards the cart. Hooray for progress! :D

Now, I've just got the data exchange headache problem to deal with to tell the NPC he can start to move. :)

Would it be best to tell the cart/NPC to look for the closest NPC/cart and push an interaction to toggle the attribute values? (For this whole process, should I have a "look for closest and then push" method for any time I need to exchange or alter data between these objects?)

I worry about relying too much on a "closest X" method for if/when there may be multiple NPCs/carts to a wave.

Echo
23rd Jul 2010, 05:59 AM
The "Create New Object Instance" call sets the Stack Object's ID to the ID of the created object, so you really don't need the "get closest" call. You've already got the ID ready and waiting for you in the stack object immediately following the create call. :)

maybesomethingdunno
23rd Jul 2010, 09:48 PM
Okay, I understand this for the NPC/cart data transaction. But, it would still be necessary to some extent, right?

The Sim doesn't directly create the cart. In the self-interaction, the Sim creates the NPC. In turn, the NPC creates the cart in its "Function - Main" bhav (to automatically snap the cart into its own slot). While the Sim's self-interaction would have the ID of the created NPC and the NPC would have the ID of the cart, there doesn't seem to be a direct way for the Sim to get the cart ID for the Push Interaction. Of course, just because I don't see it or know about it, doesn't mean it doesn't exist. :lol:

Okay, as soon as I typed that, you helped me to realize how I might should be doing this:
1. The Sim creates the NPC,
2. The NPC becomes the Stack Object ID,
3. Store the NPC's ID in a local variable for future reference,
4. The Sim then creates the cart and places it into the NPC's slot directly via "[prim 0x002A] Create New Object Instance (GUID 0xwhatever, place: in Stack Object's slot 0xSlot#, Create object normally...",
5. Store the cart's ID in a local variable for future reference.

How does that sound? If that works, the self-interaction could have access to the object's ID (when the Sim routes to it), the NPC's ID, and the cart's ID. (Wow! To think that a multi-hour headache could be condensed into 5 seemingly simple steps...)


Thanks again for your help (both direct and indirect :) )!

Echo
24th Jul 2010, 02:08 AM
Yep, that should work just fine. :)