About Store Forum Documentation Contact



Post Reply 
T (*this) conversion to ObjMemx container
Author Message
Kiekos Offline
Member

Post: #1
T (*this) conversion to ObjMemx container
Hey lads!

Simple question to probably most of you but I'm stuck... In my NPC's update loop I have something like this:

Code:
if( Lit==this  && Ms.br(0) ){
    // some stuff

    interaction = true;
}

if( interaction ){
    // more stuff

    T.actionMoveTo( some_position );
}

It has to be done this way, as the first "if" is done once (only when I click) and the second "if" is done every frame. The problem is that because in the second "if" there is no other requirement than just interaction value, it does the thing I want to all NPCs and not just the particular one I clicked.

I need to know which NPC I'm referring to in the first "if". Is there a way to check the index of the NPC that I clicked and then use it in the second "if" like this:

Code:
NPC[index].actionMoveTo( some_position );

Thanks,
Kiekos
11-22-2013 07:20 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #2
RE: T (*this) conversion to ObjMemx container
You could do the following:

Identify the object targeted by using a raycast based on the screen pos of the mouse and projected into the scene.

Have a setMoveToPosition function in your NPC class and call that with the desired position. This would set a suitable flag ('interaction' if you like) and your Update code traps this and instigates theactionMoveTo then resets the flag. This leaves your NPC code pretty much generic.
11-23-2013 12:24 AM
Find all posts by this user Quote this message in a reply
Kiekos Offline
Member

Post: #3
RE: T (*this) conversion to ObjMemx container
Thanks for the idea, I will try to implement something like that as it's deffinitely a solution!

For now I came up with something simple that works, but is not optimal at all and must be changed (especially when I have hundreds of NPCs on the map)...

Code:
// first "if"
REPA(NPCs) if( NPCs[i].pos() == T.pos() ) index = i;

// second "if"
NPC[index].actionMoveTo( some_position );

But is there really no way to find out which object I clicked and want to be moved?
(This post was last modified: 11-23-2013 01:16 AM by Kiekos.)
11-23-2013 01:10 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: T (*this) conversion to ObjMemx container
I think you've got that already in your first post:
Lit==this
Since you have Lit pointing to NPC object, then that's what you want?
if(Lit==this && Ms.br(0))actionMoveTo(..)
11-23-2013 05:39 AM
Find all posts by this user Quote this message in a reply
Kiekos Offline
Member

Post: #5
RE: T (*this) conversion to ObjMemx container
Yea, I know... But I can't do it that way. I have to remember somehow which one I clicked in the first "if" and use that index in the second "if".

The first one is executed exactly once (when clicked) whilst the second "if" is repeated every frame.
11-23-2013 12:46 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: T (*this) conversion to ObjMemx container
Just remember the 'Lit' somewhere? wink
as Reference<..> of course
11-25-2013 04:39 AM
Find all posts by this user Quote this message in a reply
Post Reply