Game Development Community

Fill Battle Tutorial Help

by William Lee Sims · in Torque Game Builder · 02/14/2011 (8:57 pm) · 16 replies

Working on the Fill Battle Tutorial on TDN? Have questions, comments, or snide remarks? Put them here and I'll be able to track your issues. Thanks!

TDN Tutorial:
tdn.garagegames.com/wiki/TGB/Tutorials/Fill_Battle

#1
02/14/2011 (10:36 pm)
Wow, this looks amazing.

I've been considering putting relatively dumb AI in my current demo. But seeing how quickly you can integrate a C++ class into TGB may have changed my mind!

Cheers!
#2
02/15/2011 (8:49 am)
Great job Will! I'm thrilled to have been a part of this.
#3
02/16/2011 (12:19 am)
Image link not found

Under - Adding Attributes to the Buttons

http://wsims.com/ShowAndTell/tutorial/fb18.png
#4
02/16/2011 (11:13 am)
Very odd! I'll get that up first thing this evening.
#5
02/16/2011 (7:44 pm)
I uploaded the image. Thanks for catching this!
#6
04/07/2011 (8:43 pm)
Excellent tutorial about C++/Torque integration.

One thing that I would do differently would be to define all your Torque game interface inside a Torque class. It is confusing to have to modify the game.cs StartGame function with a global variable and a init() function:

$FillBattle::Logic = new FillGridModel();
TileBoard.init();

What I usually do is:
Add the name of my class to the parameter of t2dSceneGraph in the level file, as in
%levelContent = new t2dSceneGraph(TileBoard)
Then define a new file (without the need to change game.cs at all ) with

function TileBoard::OnAdd(%this)
{
   %this.model = new FillGridModel();
   %this.init(); 
}

Like this the OnAdd function is called automatically by the TGB engine. In the rest of the class you can then redefine the usual callback methods
function TileBoard::onLevelLoaded( %this, %scenegraph )
{ 
}
#7
04/12/2011 (9:50 am)
That's an excellent point, Pedro. In fact, that's the best way to keep your code modular. When I get back to finishing the tutorials, I'll probably put your suggestion in.

Personally, I like to do all of the model init/un-init in the scene graph. I'll give the scene graph a name and do
function gameHUDScene::onLevelLoaded( %this )
{
  // Initialize models here
}

function gameHUDScene::onLevelEnded( %this )
{
  // Uninitialize models here
}

In my first "real" game, I had the models owned by the objects in the game and it made it very hard to save the game. Ever since, I keep all of the models in one area to make it easy to save them all out to disk.
#8
04/12/2011 (6:43 pm)
@William. Thanks. I just uploaded a new tutorial
tdn.garagegames.com/wiki/TGB/Tutorials/The_Game_of_Life

that was heavily based on the Fill Batle Tutorial. It also defines a C++ class and integrates it with Torque in the same manner. Credits are given :-)
#9
10/19/2011 (1:25 pm)
Thanks for this tutorial. I'm attempting to follow it to learn how to integrate C++ and TorqueScript, but I've run into a problem. At the end of "The Emperor's New Clothes" section I rebuilt the engine and TGB and ran the game as described in the tutorial, but when I open the console and type:

$a = new FillGridModel();

I get the following error:

<input> (0): Unable to instantiate non-conobject class FillGridModel.

Obviously it can't find or otherwise create the object. So I cleaned and rebuilt the solution, with the same results. I also triple checked that I copied the source files correctly, confirmed that the source files were added to both projects, verified that the class names were not mis-typed and that the DECLARE_CONOBJECT and IMPLEMENT_CONOBJECT macros were included, and confirmed that the fillGridModel.obj file was being linked.

At this point I'm at a loss for what to try next. What are the key requirements to integrating a C++ object into Torque? Is there supposed to be a script file also?
#10
10/19/2011 (4:40 pm)
Are you sure you're running the game with the newly compiled exe?
#11
10/20/2011 (4:51 am)
@Patrick

Thanks! You were correct, the game exe had not been updated, only the tgb executable. Now it works great!
#12
12/18/2012 (2:24 pm)
I know this is an older thread. The tutorial brought me here. I am going through the tutorial and just finished "Creating The Game" section. I found myself in an endless loop, I double checked the code to make sure I type it correctly. Made sure there was nothing missing. After that was fruitless I decided to cut and paste the code straight from the tutorial getting the same exact results.

I know it is in the while loop dealing with the stack. The endless loop only happens if the color is the same as the one next to it, I will try to represent it in simple text.

---------
|X|X|O|Y|
|Y|X|Z|B|
|Y|X|Q|B|
---------
That is an excerpt of the top corner of the tilemap[0,0] to [3, 2] etc..

If you click the color of anything but "X" no endless loop, say for example I click "Y" then the new shape would look like this.
---------
|Y|X|O|Y|
|Y|X|Z|B|
|Y|X|Q|B|
---------

Now I click the color "X" as to change all of those. Now that X matches the color to the right, it falls into endless loop then crash.
I am at a loss on trying to figure out why. I have tried everything, going to still try but I posted here in hopes maybe someone ran across the same problem or if there is a tiny problem I didn't notice. I can post my code if needed.
#13
12/18/2012 (3:05 pm)
I found what was going on.

In the loop there is code that looks like this in every IF statement.

%downTileType = TileBoard.getTileType(%xCoord, %yCoord + 1)

I used just one of the left, right, down, up, if sections. I decided to give it a shot and enclose the %yCoord + 1 in parenthesis like this.

%downTileType = TileBoard.getTileType(%xCoord, (%yCoord + 1))
I did that for all four IF statements and that seemed to fix the problem.

Well, kind of fixed the problem. I found that if you click the same color twice it goes into an endless loop again if there are the same colors next to it like described above.
#14
12/18/2012 (7:36 pm)
why oh why do I find the problem seconds after finally posting...

[edited]

Ok, I found another problem, could be a win8 thing. Up until now I just manually copied the exe to the new location figured I would tackle the error later. I am out of ideas.

There is a postbuild command of copy, and no matter what it ends in error. I even opened up a command prompt with and without admin privs. Get a syntax error. I have copy <statement location> SPC <statement dest>

I added SPC to make it clear I added a space. Even tried xcopy, still no luck, have quadruple checked the source directory and filename along with destination. Works fine on my windows 7 machine. Is there a new way to do it under windows 8? I figured it would be the same.
#15
12/19/2012 (9:14 am)
I'm not sure if there is a Windows 8 specific problem as my development environment hasn't been updated... However, you need to make sure that Torque is closed when you do the build or the post-build copy will certainly fail.

Are you sure that this issue isn't resolved in a future part of the tutorial.

Sorry for a lack of specifics but I don't have this setup currently to go through it.
#16
12/19/2012 (10:17 am)
I unfortunately don't have that project/tutorial set up on my computer anymore. I am using Windows 8, though, and my copies are still working.

The only idea I have is that you installed TGB in "Program Files" and it won't allow copying into there. Also, Patrick's solution is common: make sure you aren't running the game when you re-build.