Game Development Community

Level Finish, Timers, Collectables, Fixed resolutions and Fonts

by Lewis Bibby · in Torque 3D Professional · 06/18/2011 (5:07 pm) · 15 replies

Level Finish, Timers, Collectables, Fixed resolutions and Fonts

This might be a bit much to ask in one go but I have a couple questions I'd like to throw out there.

Level Finish

I'm having trouble adding a trigger to the end of my level that brings up a menu that allows you to either go to next level or back to the level select. I have the graphics come up on screen but don't know specifically how to unload a level or load the next.

Timers

This is probably too large a question to ask among all the rest but for my game I would like to include a timer that counts down from the level start like in "Super Monkey Ball" and if it reaches zero before the player reaches the finish then he fails the level and is offered the chance to retry or return to level select. Ultimately I would like the time the player completes the level in to be recorded in some way so that it can shown on the menus (with better times replacing the old ones). The timer would also have to reset if the player respawns etc.

Collectables

Another issue I'm having is adding collectables in my game. To clarify in each of my levels there would be three batteries that players can collect and the amount they've collected in the level should be reflected on the HUD. The amount of batteries collected in the game over all (from every level) would be recorded as a method of unlocking new levels/characters (say 10 batteries unlocks a new character) and collecting the same battery twice also shouldn't increase the overall amount of batteries collected. I thought I'd be able to adapt the ammo in the game but I just haven't gotten anywhere on this issue.

Fixed Resolutions

I would also like to limit the resolutions in my game somewhat. By this I mean that the window mode shouldn't be resizable except by using the in game options and I would also like to remove some of the resolutions you can select.

Fonts

Finally I would like to change the default font in the game to a different one that I've selected. I've looked at how to do this but in the GUI editor it seems I'd have to edit the profiles for each one individually I'm wondering if there's a faster way I could just replace all fonts. Also when I added my own font (but letting the GUI editor create its own UFT files) it didn't work and I'm not too certain why. It created a UFT but the UFT either didn't load or wasn't actually my font.

I know that is quite the wall of text so any help with any of the questions would really help me out.

Thanks in advance!

#1
06/19/2011 (6:26 am)
1. Look in serverConnection and gameCore to see how levels load. Also open up the stock "choose level gui" and see how that works. You could create a new function that close the current game and then loads the new level directly (that wants doing in serverConnection).

2. Schedule function, with a gui displaying the changing timer. For a completed level you'd have to store the info in another file somewhere. For a SinglePlayer game you could simply add it to the "prefs" file as a "prefs global" (though any player could change that by manually by editing the text file) and then display that global variable on a "high score" gui.

3. Check out the doumentation, it's got a section on creating an inventory. You'd have to pass the collected# across levels somehow, probably by writing it to temporary file or holding it as a global somewhere.

4. No idea, I usually play games full screen.

5. Fonts are supposed to ... just work. Notice anything "special" about the failure? Happening only on certain sizes or anything? Maybe make a bug report.
#2
06/19/2011 (1:25 pm)
Thanks for all the assistance Steve I really appreciate it.

Just thought I'd let you know how I've got on with your advice.

for the level quit iv got it working now by poking around where you recommended and for the timer iv been making progress with the schedule function so I think I'm heading the right way with that as well.
Regarding the inventory tutorial it was helpful for how I'd go about showing the information on screen but I'm still a bit vague in the area of how to make my collectables "pick-up" when the player touches them in my levels so I'll have to keep ploughing regarding that.

And for the fonts I'll have a more in-depth look at what's going on to see if it is a bug or not.
#3
06/19/2011 (3:01 pm)
"Item class" can be auto-picked up ... if the playerObject has the available space in it's inventory. Look in (art)player.cs for the stock max inventory listings (only weapons and ammo in stock). No maxInventory listing for an item, no pickup.
#4
06/19/2011 (10:49 pm)
I've given it a shot at creating my own pickup by mimicking what I could learn from the item data and max inventory functions you mentioned are included by default. After trying to write my own I get an error in the console when my player collides with the pickup saying,

scripts/server/player.cs (117): Unknown command pickup.
object (10477) Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

At the risk of exposing my own ineptitude with code here is what I did.

I made a new datablock called Batteries.cs and told it to load in the datablockExec. Inside that file I added

datablock ItemData(Batt)
{
   // Mission editor category
   category = "Ammo";

   // Hook into Item Weapon class hierarchy. The weapon namespace
   // provides common weapon handling functions in addition to hooks
   // into the inventory system.
   className = "Ammo";

   // Basic Item properties
   shapeFile = "art/shapes/Grass_World/Decor/Barrel.DAE";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   // Dynamic properties defined by the scripts
   pickUpName = "Battery";
   maxInventory = 10000;
};

I then went to my player.cs and in the PlayerData section added this,

//Batterie Pickup
   
   maxInv[Batt] = "9999";
   
   maxInvBatt = "9999";

Any further assistance would be greatly appreciated!
#5
06/20/2011 (6:21 am)
1. Don't have anything else called "Batt", that's why it's a good idea to call anything pickupable "BattAmmo" to diferentiate it between other objects in-game.

2. There is a HEIRARCHY to Torque which doesn't seem to get mentioned much. Try execing objects above the player execs. For ammo, try putting them with the other weapons - not at the end below players.
example:
//databockExec.cs

// Do the sounds first -- later scripts/datablocks may need them

// Do the various effects next -- later scripts/datablocks may need them

// Add a rigid example
exec("./rigidShape.cs");

exec("./health.cs");

//yorks <- custom staticShapesClass Objects should go here

// Load our supporting weapon datablocks
exec("./weapon.cs");

// Load the weapon datablocks
// <----- yorks here is good for ammo

// Load the default player datablocks

// Load our other player datablocks

// Load the vehicle datablocks

Also to note: for weapons, objects, fx, etc, you have to exec in order whether you're doing it in seperate files - or have them listed in order in the same file (like weapons do).

//In order!
//audio
//particles 
//emitters
//debris
//explosions/splash

3. Just to note: maxInventory in itemData (ammo) is how many you pickup when you touch it - I'd suggest "1" and not "10000".
#6
06/20/2011 (8:43 pm)
Ok, I've revised the name of the pickup and changed the executable order but I'm still getting the same error in the console.

I'm wondering if my issue lies with either the part that says

// Mission editor category  
   category = "Ammo";  
  
   // Hook into Item Weapon class hierarchy. The weapon namespace  
   // provides common weapon handling functions in addition to hooks  
   // into the inventory system.  
   className = "Ammo";

Since I'm not actually trying to make a type of ammo just a generic pickup. Either that or it may be something to do with me using the Action Adventure Kit as the basis for my game...

Still thanks for all the help, I'm very grateful :)
#7
06/21/2011 (10:57 am)
That pickup thing is from the Player.cs file... look for Armor::onCollision and you'll see:
// Try and pickup all items
   if (%col.getClassName() $= "Item")
   {
      %obj.pickup(%col);
      return;
   }

Not sure the best fix there (it's calling pickup on the player object's datablock, with the item you are trying to pick up).
#8
06/21/2011 (11:39 am)
@Bryan

I may just be looking in all the wrong places but after a good scouring of the Player.cs I don't seem to be able to find anything like that at all.
#9
06/21/2011 (12:52 pm)
For the timer request check my web site:
http://www.gamealchemy.fr/crbst_9.html

You can find timer and countdown timer with callbacks for event plug ;)
#10
06/21/2011 (1:11 pm)
Lewis, trying duplicating the health.cs instead for you battery, and take out the if(statement) about health level obviously.
#11
06/21/2011 (1:56 pm)
@Jean-Louis

Those look very promising I'll give them A try in the very near future, Thanks!

@Steve

After trying it using health.cs i got the same error in the console unfortunately
#12
06/21/2011 (2:12 pm)
so ... what does player.cs(117) say?

more to the point - use find-in-files to see what's happened to
::pickup(
#13
06/21/2011 (6:23 pm)
Well that early on in my player.cs is just Sound effect datablocks unless I'm looking in the wrong place and Find-in-file is returning 0 results

Find "::pickup( " in files of type(s) "*.cs;*.gui;*.mis;*.t2d" in "E:\Dropbox\Dropbox\Platform Game\Distressed Robot Labour V0.2\game\"
Results: 0    In Files: 0    Searched Files: 498

Not really sure what to say.
#14
06/21/2011 (6:29 pm)
Check scripts/server/ for item.cs, inventory.cs, weapon.cs. Make sure you haven't ditched anything and that they're all getting exec'd in scriptExec.cs

Also make sure you've got the latest DirectX "redistributable" and update your GPU drivers.

Also try rebuilding the solution.
#15
06/21/2011 (8:31 pm)
Ok, after checking the scripts weren't being executed so after adding them I still got the same error but after some side by side comparison i noticed that my player.cs says

function DefaultPlayerData::onCollision(%this,%obj,%col)
{
   if (%obj.getState() $= "Dead")
      return;

   // Try and pickup all items
   if (%col.getClassName() $= "Item")
   {
      %obj.pickup(%col);
      return;
   }

instead of

Armor::onCollision

Explaining why I couldn't find it using the search feature. My only issue is I'm not sure what to do with this revelation but I'm sure with a bit more digging I'll get there.

EDIT

How could I test that my player.cs is able to access the pickup function from inventory.cs? because that seems to be where the error may be.