Game Development Community

Help! Is there a way to make Object IDs permanent?

by Adam F · in Torque Game Engine · 03/10/2008 (4:24 pm) · 6 replies

Hi,

I'm still new to TGE, so bear with me..


I've implemented a door system into my game that works like this:

function addDoor()
{
%doorObj = new StaticShape()
{
position = "22.07 -4.25 0.0";
scale = "0.03 0.032 0.03155"; //Correct size
rotation = "0 0 1 -90";
datablock = door;
};
%obj = new Trigger()
{
position = "21.55 -0.84999 0.2";
scale = "0.5 2.5 0.5";
rotation = "0 0 0 0";
dataBlock = doorTrigger;
polyhedron = "0.0000000 0.0000000 0.0000000 2.0000000 0.0000000 0.0000000 0.0000000 -2.0000000 0.0000000 0.0000000 0.0000000 2.0000000";
doorID = %doorObj;
};
}

function doorTrigger::onEnterTrigger(%trigger, %this, %obj)
{
openDoor(%this.doorID);
}


So basically, the whole system relies on the trigger knowing the door's ID..

Here's where my problem comes in. Each time the game is loaded, the door IDs are changed, but the triggers still have the old IDs from the previous session.

Is there any way to make the IDs permanent, so that they won't change every time the game is loaded?

If not, is there a different simple solution that I could use?


Thanks,

Adam.

About the author

Recent Threads

  • Hide the player model?

  • #1
    03/10/2008 (5:19 pm)
    Adam,
    if you're dynamically creating the door and the trigger each run, it should work fine.

    do you know why the trigger has the old ID from the previous session ?

    one thing to watch out for w/ dynamically creating stuff is that if you happen to save out the mission (like from the mission editor), it will save your dynamically created stuff, with the simIDs and everything,
    and then the next time you run you'll have two copies of the dynamic objects - one from the mission and one dynamically generated.
    #2
    03/10/2008 (5:42 pm)
    Thanks for the reply, Orion.

    Ah, yes.. That makes sense actually, because what I've been doing is putting 'addDoor();' in the console to create a door, and then positioning it to where I want it using the mission editor, and then save. But now I realise this is probably a bad way of doing this.


    "do you know why the trigger has the old ID from the previous session ?"

    I might have been a bit unclear here.. What I meant was that both the door and trigger get new IDs, but the 'doorID' stored in the trigger remains the same as in the previous session (because it was saved in the mission editor).


    Taking on board what you have said, I'm still struggling to think of a solution. If I dynamically create all of the doors, then it should work fine, but as I said at the top of this post, I'm not necessarily dynamically creating them, but instead just using the code as a means to create the door in the mission editor.
    #3
    03/10/2008 (5:56 pm)
    A few options come to mind.

    1a. create a SimGroup containing both the door and the trigger, with the requirement that the door be the first object in the SimGroup. then the trigger can find its associated door as %this.getGroup().getObject(0).

    1b. same as 1a, but instead of assuming the first object in the group is the door, assume the first object in the group of a given classname is the door.

    1c. same as 1b, but add a field to the door like "itstheone=true", and assume the first object in the group which has itstheone == true is the door.

    1d. if you have TGE 1.5, you could set the door's "internalName" field to something and use findObjectByInternalName. this is probably the best option.

    2. give the door a global-namespace name when you create it, and point the trigger to that global name. i would encourage not doing this.
    #4
    03/10/2008 (6:45 pm)
    Could you explain a bit more how findObjectByInternalName works please.

    I've just had a go at using it, but couldn't seem to get it to function properly.

    I kept getting:

    Unable to find function findObjectByInternalName

    or

    Unable to find object: ' ' attempting to call function 'findObjectByInternalName'


    In my game I will have more than one door, so my plan is to create a string, ie "myDoor1" and assign that string to the internalName field. Then increment it each time a new door is created. (By incrementing an integer and then appending it to 'myDoor'.. Is this possible in Torquescript?)


    Thanks
    #5
    03/10/2008 (6:58 pm)
    Yes it's possible.


    $NumDoors = 0;

    function addDoor()
    {
    $NumDoors++;
    %doorName = "UniqueDoor" @ $NumDoors;
    %triggerName = "UniqueTrigger" @ $NumDoors;

    %doorObj = new StaticShape(%doorName)
    {
    position = "22.07 -4.25 0.0";
    scale = "0.03 0.032 0.03155"; //Correct size
    rotation = "0 0 1 -90";
    datablock = door;
    };

    %obj = new Trigger(%triggerName)
    {
    position = "21.55 -0.84999 0.2";
    scale = "0.5 2.5 0.5";
    rotation = "0 0 0 0";
    dataBlock = doorTrigger;
    polyhedron = "0.0000000 0.0000000 0.0000000 2.0000000 0.0000000 0.0000000 0.0000000 -2.0000000 0.0000000 0.0000000 0.0000000 2.0000000";
    doorID = %doorName;
    };

    }

    This gives them a unique name in the constructor and it will stick when you save it.
    #6
    03/10/2008 (7:17 pm)
    Ah, that works great.


    Thanks both for your help.. It's much appreciated!


    Adam.