OnTileScript/setTileScript
by Joe Spataro · in Torque Game Builder · 07/21/2005 (2:23 pm) · 2 replies
Can someone post some examples of how to use these commands properly?
It would be very helpful to me.
Also, how do I use custom tile data?
joe.s
It would be very helpful to me.
Also, how do I use custom tile data?
joe.s
#2
If you have existing maps you want to port over, the easiest way to do so is to uncomment the Save line and leave the load line commented. Then load up each of your maps once in the tile editor and re-save. Finally uncomment the load line, recompile and again you're all set.
As for using the custom data, its very easy. You set it to a string, containing whatever you want. For example in my last mini project I set certain tiles to hold a custom data of "scoringzone". Then you can check whether a specific tile on a specific layer has custom data or not via
Following is an example of how I used this.
07/22/2005 (4:25 am)
Getting custom data to work is very straight forward. Look in engine/T2D/fxTileMap2D.cc. Search for "fxTileLayer2D::loadStream" and likewise "fxTileLayer2D::saveStream" Inside each of these will be a commented out line that saves the custom data. Uncomment both these, recompile and you're up and running. If you have found the correct line it should look like this:// Read Tile-Script Parameters. pTileObject->mCustomData = fileStream.readSTString(); // Will be added in when new file-format is ready.
If you have existing maps you want to port over, the easiest way to do so is to uncomment the Save line and leave the load line commented. Then load up each of your maps once in the tile editor and re-save. Finally uncomment the load line, recompile and again you're all set.
As for using the custom data, its very easy. You set it to a string, containing whatever you want. For example in my last mini project I set certain tiles to hold a custom data of "scoringzone". Then you can check whether a specific tile on a specific layer has custom data or not via
%layer = MyTileMap.getTileLayer( 0 ); %xy = %layer.pickTile( MyPlayer.getPosition() ); %data = %layer.getTileCustomData(%xy);
Following is an example of how I used this.
function Arena::IsScoringZone(%this, %pos)
{
%layer = %this.map.getTileLayer( $ARENA::LAYERS::INFO );
%xy = %layer.picktile(%pos);
return (%layer.getTileCustomData(%xy) $= "scorezone");
}
Torque Owner Philip Mansfield
Default Studio Name
As for tile scripts, you can use them like this:
In the level editor, add a script to your tile, and save the map file.
Then add the following code:
function fxSceneObject2D::onTileScript( %this, %tLayObj, %tXY, %script ) { // here we figure out what to do with the various script names embedded in the tile markers switch$( getWord(%script,0) ) { case "sciptname1": myFunction(); case "scriptname2": myFunction2; { }When the tile with the appropriate script comes onto the screen, the relevant script is called. You can call functions directly from the tilescript, but I don't recall off hand how to do that. Another quick search of the forums should bring it up as it has been discussed before.