How to create instanse of another function????

(9 posts) (3 voices)

Tags:

No tags yet.

  1. sunder3dvia

    veteran
    Joined: May '13
    Posts: 276

    Hi,

    I have created a function or Task on an Actor. I would like to access the local variable of that function or task in another task where the task is written on another actor. How can I do that?

    I want to know the purpose of the following function. Here TransportPtr is pointer of function which is written in another actor. m_Train is member variable of current task.

    TransportPtr myTransport = Transport::ComponentCast(m_Train);

    Posted 1 year ago #
  2. iainB85

    Interplanetary Delivery Boy
    Joined: Jun '08
    Posts: 515

    Hello,

    I am a little confused as to what you are asking but I took a quick stab at it this morning -- do you mean you have a function in one behavior, and want to access it from another behavior? I attached a sample of this.

    In "be1" there is a function that accepts a vkString input then prints it.

    In "be2" there is a task that calls the function from "be1" and sets the vkString input to "Hello World"

    Is this similar to what you are asking?

    Attachments

    1. forumFunctionAccess.zip (11.2 KB, 2 downloads) 1 year old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 1 year ago #
  3. sunder3dvia

    veteran
    Joined: May '13
    Posts: 276

    Hi,

    My question was related to this only. In your sample you have defined two function on two different behavior. In one behavior you have created a local variable called be1Act type of vkActorPtr. In that you have assigned another behavior. Why do you do like that? Cant we access without doing that?

    I mean be1 variblename = be1;

    Posted 1 year ago #
  4. iainB85

    Interplanetary Delivery Boy
    Joined: Jun '08
    Posts: 515

    Hello,

    You can create a function outside of the main brackets then call it anywhere. Ex:

    // Definition of the function be1Function
    void
    be1::be1Function(vkString toPrint)
    {
    
    }
    
    void fn_Print(vkString toPrint)
    {
    	Print(toPrint);
    }

    I can call that "fn_Print" in any function now, as it is seperate from the function specific to this behavior. Is that what you were looking for?

    Posted 1 year ago #
  5. sunder3dvia

    veteran
    Joined: May '13
    Posts: 276

    Hi,

    Here I attach a sample project. Please look at it.

    In that I have created two 3D entity on that I have written behavior. On NewBehavior1 I have declared variable "m_Name". I would like to access this variable in NewBehavior2. How can I do.?

    Thanks.

    Posted 1 year ago #
  6. sunder3dvia

    veteran
    Joined: May '13
    Posts: 276

    Project is Here!!

    Attachments

    1. Sample.zip (7.7 KB, 3 downloads) 1 year old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 1 year ago #
  7. hiddentux

    3D Experience Guru
    Joined: Feb '09
    Posts: 378

    Best Answer

    Hi,

    Please have a look to the attached project.

    Two side notes :
    - Execute must return something in tasks, whether it's true or false, you should have a return somewhere
    - You can create behaviors directly in your Stages : right-click on the Stage >> New >> Behavior (there's no need to instantiate 3D Entities and to add behaviors on them)

    Attachments

    1. Sample_v2.zip (6.6 KB, 6 downloads) 1 year old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 1 year ago #
  8. iainB85

    Interplanetary Delivery Boy
    Joined: Jun '08
    Posts: 515

    In fact in "NewBehavior2" you need to create a member that points to "NewBehavior1" (or a component on it's component ring, such as the vkActor, then do a component cast).

    Why? Because there can be many instances of this behavior with the members all configured differently and you need to point to a specific instance in order to get the value of the member.

    I updated your project to illustrate this point. It now has 3 instances of "Behavior1" and the "m_Name" member is configured differently for each one. In the "Behavior2" I create members to point to each instance, then in the task I print out each of the "m_Name" values.

    Does this help clarify?

    Attachments

    1. Sample.zip (9.2 KB, 1 downloads) 1 year old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 1 year ago #
  9. sunder3dvia

    veteran
    Joined: May '13
    Posts: 276

    Hi iainB85 and hidde,

    Thanks for your support.... I got ti what I was looking for it.

    Posted 1 year ago #

Reply

You must log in to post.