Load an entity with action

Posted By: BES

Load an entity with action - 10/03/08 02:43

Is it possible to load an entity with an action already attached? ent_create allows you to assign an action defined in the loading level, but I'm hoping to be able to load an entity with an action defined in that entity's wed project and not in the loading project. In this way, I hope to store some data about the object that I am loading within itself. If there is another way to attach data to an object, please let me know!

Thanks so much for your time!
Posted By: Quad

Re: Load an entity with action - 10/03/08 09:27

in fact you cant "define" any actions on a wed project, you define them in your project, and let the wed know you defined some actions by attaching your script to your map.(we re doing this because we want see our actions in behaviour list wink )

when you press run from wed it runs the script not the level.(try adding a short script that doenst even loads your level or that loads another level)
Posted By: Trooper119

Re: Load an entity with action - 10/05/08 07:19

While he's technically correct, this can be surpassed, what I do is create a function that has all of the actions I want predefined as integer values, and pass those values to the function, the function from there simply translates what I'm sending to it and creates actions from it.

For an example (I know I murdered the explanation)
Code:
#define action1 1
#define action2 2
#define action3 3

main()
{
    ENTITY* aPointer;
    //specifying a pointer allows you to send it/manipulate it later in this or other functions
    aPointer = spawnFunction(action1);
}

//Usually I'd specify 2 or 3 variables for the vector in 
//order to place it where you want but it's really up to you.
ENTITY* spawnFunction(int action)
{
    if(action == action1)
    {
       ent_create("default.mdl", vector(0, 50, 100), yourAction1);
    }
    else if (action == action2)
    {
       ent_create("raptor.mdl", vector(0, 50, 100), yourAction2);
    }
    else if (action == action3)
    {
       ent_create("tower.mdl", vector(0, 50, 100), yourAction3);
    }
    else
    {
        //you could write an error, or whatever here, it's good practice to use error checking
    }
    return my;
}

//Usually defined somewhere else, like another file
action yourAction1()
{
...
}
action yourAction2()
{
...
}
action yourAction3()
{
...
}

Posted By: BES

Re: Load an entity with action - 10/06/08 19:16

Thanks, both of you. I think I have to use a different means to accomplish my purpose (load a config file probably). In retrospect it didn't make much sense to think I could run code not compiled with the loading project.

Cheers!
© 2024 lite-C Forums