Game Development Community

Running The Game Twice In Order To Find The Player?!?

by David Taylor · in Torque Game Builder · 09/07/2006 (10:02 pm) · 5 replies

I have a very odd problem with TGB. When I run my game, (the very first time after opening TGB), the level loads, as is the GUI, but the gui console says it can't find the player. (And as such, I can't do anything!)

Then, as soon as I stop the run and run it again without restarting TGB itself, everything works fine. The same applies for every other time. It's just the very first time after opening TGB.

Does anyone have any ideas as to what might be causing this, and how to fix it?

#1
09/07/2006 (10:05 pm)
I had a similar issue where my scene objects were not triggering their onLevelLoaded callbacks on the first run. On a second run, the objects would trigger their callbacks with no problems. I found no problem nor solution, so I ended up just writing a workaround function which searches through the objects in the scenegraph until it finds the object i was looking for and works with it as needed, though I never figured out why everything worked on the second run and not initially.
#2
09/07/2006 (10:18 pm)
Thanks, Corey. Glad to know I'm not the only one.

In the event that nobody is able to answer my query, could you post your workaround function? That'd be most appreciated. :)
#3
09/08/2006 (12:21 am)
Often what can happen is your datablocks or other initializing code has not yet been exec'd when the level builder starts. After running the level once this code is then exec'd and all is well for subsequent runs. If this is happening to you it can be remedied by making sure all your code is exec'd in a scope that happens at project initialization, and not at the "startGame" time.
#4
09/08/2006 (5:25 am)
Thanks for the suggestion Ben, that does make sense. I had a feeling it was a scope related issue.
#5
10/09/2006 (1:44 am)
I worked out what was wrong - it was a pathing problem. The main.cs file was looking for my other files in the wrong directory. Quite why it found them after reloading the level, I have no idea, but it all works like it's supposed to, now. :)