How do I set a object name for a object that is created at runtime.
by Brian Westgate · in Technical Issues · 01/10/2011 (8:49 pm) · 2 replies
I'm looking to gain access to the player object that is created in the fps template (player giadon of DefaultPlayerBase). I can only get access during run time via the console, but I want to gain access to him before that so I can create scripts involving him. Since he is created somehow at run time I am having trouble finding a way to place him in my custom sim group I made for future access. Through debugging I found that when he is created he is placed in the MissionCleanup group. I can gain access to him using this group at run time, but since he isn't created with a name I have to rely on his ID to remove him and place him in another group for future use. This ID changes depending on the objects in the map so I don't believe it is a reliable way to always get access. Is there a way so I can make the giadon player object of the fps spawn with a name or is there a global player variable I'm unaware of that will give me access to the player object. I've already tried adding name = "x"; & name = x; to the datablock and he still doesn't spawn with a name. I've tried quite a few different things with no solution. Hopefully someone else can help me solve this. Thanks.
#2
You can gain access to it via the game connection.
01/11/2011 (6:24 pm)
The player is a control object.You can gain access to it via the game connection.
Torque Owner Brian Westgate
function PlayGui::onWake(%this) { // Turn off any shell sounds... // sfxStop( ... ); $enableDirectInput = "1"; activateDirectInput(); // Message hud dialog Canvas.pushDialog( MainChatHud ); Canvas.pushDialog( gStart ); chatHud.attach(HudMessageVector); // just update the action map here moveMap.push(); // hack city - these controls are floating around and need to be clamped schedule(0, 0, "refreshCenterTextCtrl"); schedule(0, 0, "refreshBottomTextCtrl"); playerGroupFindPlayer(); // Find player in MissionCleanup and add to PlayerGroupSim } function playerGroupFindPlayer() { for(%i = 0; %i < MissionCleanup.getCount(); %i++) { %id = MissionCleanup.getObject(%i).getID(); if(%id.getDataBlock().name $= "DefaultPlayerData") { PlayerGroup.add(MissionCleanup.getObject(%i)); } } }Don't forgot though to put the player object back into the MissionCleanup group so it can be cleaned up properly.