setTileCustomData error
by Kevin James · in Torque Game Builder · 07/30/2010 (4:59 pm) · 12 replies
This code fills the tilelayer:
This code clears tiles to form tunnels in tilelayer:
error = "t2dTileLayer::setTileCustomData() - Invalid number of parameters!"
Any ideas why this fails?
for (%x=0;%x<%cntX;%x++)
for(%y=0;%y<%cntY;%y++){
%this.setStaticTile(%x,%y, %imageMap, %frame);
%this.setTileCustomData(%x,%y,10);//no errors
%this.setTileCollisionActive(%x,%y,true);
}This code clears tiles to form tunnels in tilelayer:
function tunneler::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
if (%dstObj.wall) {
%dstObj.setTileCustomData(%srcRef,%dstRef,0);//error!
%dstObj.clearTile(%srcRef SPC %dstRef);
}
}error = "t2dTileLayer::setTileCustomData() - Invalid number of parameters!"
Any ideas why this fails?
About the author
Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/
#2
But then I realized I'm clearing the tile anyway so its not needed. I'm getting into the A-Star methods built into TGB. I want to be able to click somewhere in the grid and have the player find a path around walls and such. The A-star tutorial has a lot of junk in it that I have to wade through...
07/30/2010 (6:30 pm)
I changed it to this and it works for some reason:if (%dstObj.wall) {
%dstObj.setTileCustomData(%srcRef SPC %dstRef,0);//used for pathfinding
%dstObj.clearTile(%srcRef SPC %dstRef);
}But then I realized I'm clearing the tile anyway so its not needed. I'm getting into the A-Star methods built into TGB. I want to be able to click somewhere in the grid and have the player find a path around walls and such. The A-star tutorial has a lot of junk in it that I have to wade through...
#3
I got inspired a few months back and tried writing a more simple, script only version but it ended up wayyyyy too slow for any practical purpose and I scrapped it.
Are you planning on having varying costs per tile rather than just passable/non passable?
What about avoiding any moving obstacles such as enemies that change the path once the path finding code began?
My basic plan of attack was to use custom data in a tile layer (as is yours I see), calculate the path, push each of the node positions onto a stack, then use the moveTo function while popping locations from the stack - deriving world positions using the code you posted about the other day to get world positions from tile x/y's.
07/30/2010 (7:12 pm)
I completely agree that the A* tutorial has a lot of junk to work through... I got inspired a few months back and tried writing a more simple, script only version but it ended up wayyyyy too slow for any practical purpose and I scrapped it.
Are you planning on having varying costs per tile rather than just passable/non passable?
What about avoiding any moving obstacles such as enemies that change the path once the path finding code began?
My basic plan of attack was to use custom data in a tile layer (as is yours I see), calculate the path, push each of the node positions onto a stack, then use the moveTo function while popping locations from the stack - deriving world positions using the code you posted about the other day to get world positions from tile x/y's.
#4
07/30/2010 (7:43 pm)
For now I'm just going with pass/no pass. Any encounters along the way will cancel the path. Also, I couldn't find anything on TDN for aStarPath or aStarActor for a list of methods. I'm to the point where I need to define the starting and ending points for the path, but I'm hitting the wall instead.
#5
I'm dusting off an old A* resource I started and plan on posting next week but wanted to pick your brain to see if I should add anything before I do.
08/02/2010 (2:31 pm)
Hey Kevin, are you still working through this? I'm dusting off an old A* resource I started and plan on posting next week but wanted to pick your brain to see if I should add anything before I do.
#6
I would like to see a step by step guide on how to make A* pathfinding.
08/02/2010 (4:33 pm)
I'm trying to make it work; its very frustrating. The A* tutorial is less than worthless because most of it does not apply. I got so far with my code and it tells me: "PathAStar2d::calculate( sX / sY, dX / dY ) - start or end points are blocked". The destination is right in front of the player with nothing in between. Is it a grid update issue? I have no idea what's going on. I would like to see a step by step guide on how to make A* pathfinding.
#7
I designed it so create a t2dTileLayer that you paint with 10 provided brushes that each have the cost in them where 0 = no cost and 10 = impassable. Then in that onLevelLoaded, you assign it to the A* system as they do in the example:
So now, we have the A* system all setup, we need to create a Unit to follow the path and create a goal.
What I'm trying to do now is create a generic 'Unit' object that has some helper functions to set a target in script, set a target via the mouse, make it selectable so it only moves if it was selected, etc. If you have any input on other elements that you would this more useful, I'd appreciate it.
Then, similar for the goal, some helpers to set it via script or mouse.
Thoughts?
08/02/2010 (6:51 pm)
I've found a number of confusing elements in the A* demo application (admittedly, I'm not going through the tutorial) and general over complication of it. That's why I'm creating this resource. I think I've been able to distill out the important parts and put together, what I see, as a much simpler example to follow. I designed it so create a t2dTileLayer that you paint with 10 provided brushes that each have the cost in them where 0 = no cost and 10 = impassable. Then in that onLevelLoaded, you assign it to the A* system as they do in the example:
$pathGrid = new pathGrid2D() { sceneGraph = %sg; };
$pathgrid.setdiagonalmovement(true);
$pathGrid.setTileLayer(%this);
$pathGrid.currentTileLayer = %this;So now, we have the A* system all setup, we need to create a Unit to follow the path and create a goal.
What I'm trying to do now is create a generic 'Unit' object that has some helper functions to set a target in script, set a target via the mouse, make it selectable so it only moves if it was selected, etc. If you have any input on other elements that you would this more useful, I'd appreciate it.
Then, similar for the goal, some helpers to set it via script or mouse.
Thoughts?
#8
08/02/2010 (7:33 pm)
That sounds great to me. It would be nice to see how you turn a unit into the aStarActor and then interface with it. In my case, I assigned my player the aStarActor as a superclass because obviously I don't want to lose all of the existing class methods. What I have now should work, but I've missed something essential.
#9
Here's the quick and dirty:
Copy the aStarActor, aStarPath and Enemy script files from the AStarDemo into your project and make sure you exec them.
Create a t2dTileLayer and make sure that every tile has custom data between 0 and 10 for clear to impassable. Set it's class to "aStarTileLayer".
Create a t2dStaticSprite (or any t2dSceneObject) and set it up as so:
Name: DestinationTemplate
Class: Destination
Make sure that this object is sitting on a valid spot on your t2dTileLayer and your actor can reach it along it's path or nothing will happen.
Create a t2dStaticSprite and set it up like so:
Name: EnemyTemplate
Class: Enemy
SuperClass: aStarActor
I hate that this is called Enemy. This is the class I converted to Unit. They call it enemy because in the example those little butterflies were the 'Enemy'...
Create a new script file, exec it and paste the following into it:
That should get you started... Let me know if you run into any issues.
08/03/2010 (3:32 am)
Kevin,Here's the quick and dirty:
Copy the aStarActor, aStarPath and Enemy script files from the AStarDemo into your project and make sure you exec them.
Create a t2dTileLayer and make sure that every tile has custom data between 0 and 10 for clear to impassable. Set it's class to "aStarTileLayer".
Create a t2dStaticSprite (or any t2dSceneObject) and set it up as so:
Name: DestinationTemplate
Class: Destination
Make sure that this object is sitting on a valid spot on your t2dTileLayer and your actor can reach it along it's path or nothing will happen.
Create a t2dStaticSprite and set it up like so:
Name: EnemyTemplate
Class: Enemy
SuperClass: aStarActor
I hate that this is called Enemy. This is the class I converted to Unit. They call it enemy because in the example those little butterflies were the 'Enemy'...
Create a new script file, exec it and paste the following into it:
function aStarTileLayer::onLevelLoaded(%this, %scenegraph)
{
echo("aStarTileLayer loaded.");
//setup the aStar pathGrid2D
$pathGrid = new pathGrid2D() { sceneGraph = %sg; };
$pathgrid.setdiagonalmovement(false);
$pathGrid.setTileLayer(%this);
$pathGrid.currentTileLayer = %this;
//short delay to wait for the destination to get loaded
%this.schedule(500, doAstar, %start, %goal);
}
function aStarTileLayer::doAstar(%startNode, %goalNode)
{
echo("starting a*");
//this position needs to be a valid place on the t2dTileLayer you created.
spawnEnemy("-45 35");
}
function spawnEnemy(%position)
{
%newEnemy = UnitEnemy.cloneWithBehaviors();
%newEnemy.moveSpeed = 15;
%startCoords = %position; //world
%newEnemy.setPosition(%startCoords);
%newEnemy.destinationCoords = %newEnemy.findDestination();
%newEnemy.startPath(%startCoords, %newEnemy.destinationCoords);
}That should get you started... Let me know if you run into any issues.
#10
1. "findDestination()" should be findDestinationPath?
2. "startPath" might be followAStarPath? I'm less sure of this one because the followAStarPath only accepts 1 variable.
That confusion aside, I've made some progress today because my player was configured with the variable "speed" instead of "moveSpeed" which explains some problems.
Using this code:
starts the player moving in the right direction but then he stops for no reason.
08/03/2010 (3:40 pm)
A couple of points to clarify:1. "findDestination()" should be findDestinationPath?
2. "startPath" might be followAStarPath? I'm less sure of this one because the followAStarPath only accepts 1 variable.
That confusion aside, I've made some progress today because my player was configured with the variable "speed" instead of "moveSpeed" which explains some problems.
Using this code:
%this.currentPath = %this.findDestinationPath (%this.target.position); %this.followAStarPath(%this.currentPath);
starts the player moving in the right direction but then he stops for no reason.
#11
1. I don't think so... This should be findDestination. It's in the Enemy.cs file and it loops through the simset of possible destinations and assigns one.
2. Still don't think so but this does the same as the findDestination but for the paths. Also in th enemy.cs file.
I think that by bypassing the findDestination call, you're only getting path that is the first section of the total path, hence, why your player stops short. Possible?
08/03/2010 (3:58 pm)
Kevin,1. I don't think so... This should be findDestination. It's in the Enemy.cs file and it loops through the simset of possible destinations and assigns one.
2. Still don't think so but this does the same as the findDestination but for the paths. Also in th enemy.cs file.
I think that by bypassing the findDestination call, you're only getting path that is the first section of the total path, hence, why your player stops short. Possible?
#12
After a lot of testing and echos, apparently the player moves toward the target but always stops 1 node short of the destination. This is with every tile set to 0 and no cleared tiles.
1. It never gets to "isFrustrated"
2. There's only 1 path
08/03/2010 (5:04 pm)
I switched my code so I'm using the enemy.cs methods:%this.destinationCoords = %this.findDestination(); %this.startPath(%this.position,%this.destinationCoords);
After a lot of testing and echos, apparently the player moves toward the target but always stops 1 node short of the destination. This is with every tile set to 0 and no cleared tiles.
1. It never gets to "isFrustrated"
2. There's only 1 path
function player::findDestination(%this)
{
// pick a random destination
if (!isObject(DestinationSet))
{
// we should have destinations in our level
error("No available destinations in level!");
return "0 0";
}
%maxTargetCount = DestinationSet.getCount();
echo("findDestination: "@%maxTargetCount); // = 1
%targetDestinationIndex = getRandom(1, %maxtargetCount) - 1;
%targetDestination = DestinationSet.getObject(%targetDestinationIndex);
%targetCoords = %targetDestination.getPosition();
return %targetCoords;
}
Torque Owner RollerJesus
Dream. Build. Repeat.