Game Development Community

Make a change then restart TGB? Surely not

by Andy Hawkins · in Torque Game Builder · 07/01/2006 (7:03 pm) · 11 replies

So I've been working through the shooter tutorial at TDN and every script change I make, like to make the player move, add the enemy etc, will only work if I save the .CS files, close down TGB and restart it.... What the????

I even go so far as deleting all the .DSO's while running TGB and try to play the changes but even that doesn't work. I must be doing something wrong - or is this a know bug? I have the latest official release.

Also I've noticed my additions to game.cs such as exec("./gameScripts/player.cs"); etc only work in main.cs not game.cs - but this could be the same issue. However, why is main.cs working without a restart and game.cs not?

#1
07/01/2006 (8:56 pm)
The trick is to exec your .cs files in the startGame() function since its called each time you press the play button or press F5 in the level editor. You'll want to use the following syntax when adding new .cs files to the gameScripts folder:

exec("~/gameScripts/player.cs");

Notice the tilde instead of a dot.
#2
07/02/2006 (2:37 am)
The ./ tells TGB to look for the new script file in the same folder where the script you put the exec command is located. Since game.cs is located in the gameScripts folder, "./gameScripts/player.cs" is telling TGB to find the player.cs file in gameScripts/gameScripts/ folder - which is not where you put it. Your main.cs file is located in your project folder, one level above, so that's why it was working only from there.

To fix it, if you wish to keep exec stuff in the startGame() function, either the ~ example above is ok or you can use exec("./player.cs");
#3
07/06/2006 (12:58 am)
I'm noticing the same thing, using the official release. I'm using the Torsion editor to modify the scripts in the scrollerdemo, and all the scripts are called with exec() in main.cs (using '~' in all the paths). But, the changes still are not picked up until I restart TGB. I read somewhere this was a bug and was fixed, but it appears it's back. Is there anything else I can do, as restarting TGB constantly is a big pain.
#4
07/06/2006 (2:52 am)
YES YES YES - I cannot abide this! Fix the bug! Fix the bug!!! YargggHHHH!! Just kidding :)

Any chance there is a workaround? Or maybe a bug fix coming soon?
#5
07/06/2006 (8:31 am)
@Greg:
If you are doing the exec in main.cs then you won't see the changes until you restart TGB. As Dennis pointed out, you have to exec in your startGame() function to see the changes without restarting. Alternatively you can still exec in your main.cs, but then you'll have to manually bring down the console and exec the edited script yourself. There is no bug, both of these methods work fine.
#6
07/06/2006 (12:45 pm)
Thanks Ben, Sorry I missed the fact that this had to be in the StartGame() function. I'll give that a try when I get home (working for the man at the moment). This kind of thing should be highlighted and bolded somewhere in "Read me first" kind of document. Maybe it is somewhere, but there's so much out there, I didn't know what to read first. ;)

It would be nice if there was a "recompile all scripts" button somewhere. Something to think about for version 1.2 maybe.
#7
07/06/2006 (12:58 pm)
Im not using the leveleditor at all, if i make changes in torsion to say, game.cs, can i recompile or something from the console? I noticed there is a compile command, but do I need to then type exec(~/gamescripts/game.cs);
#8
07/06/2006 (4:54 pm)
Thanks for the info. I'll try it too. You know I was only kidding about the rant above right?

It's important to note that the issue arose from TDN documentation on the shooter tutorial, if someone wouldn't mind reviewing it please.
#9
07/07/2006 (1:44 am)
@James:
It doesn't matter if you use the level editor or not. The main thing to take away from this is that a changed .cs file has to be recompiled and executed again for the running engine to take notice. If you try to execute a script that is newer than the compiled .dso then it will automatically recompile it. So you can manually bring down the console and exec the script again. You should get a console message telling you it's recompiling.
#10
07/24/2006 (2:14 pm)
I've been using restartInstance(); to force the level editor to recognize my script changes.. it seems to work most of the time. I will occasionally shut it down, and clean out the .dso's just to be sure.

Anyone know anything wrong with this approach?

BTW, it also makes a nice "reset game" button.
#11
07/24/2006 (3:46 pm)
If you exec your scripts in game.cs (in startGame function or anywhere else in that file) then when you press play it should read your present state of scripts.