Datablocks bug or I am doing something wrong?
by Alkor · in iTorque 2D · 12/04/2011 (6:29 am) · 7 replies
This is what I did.
I set up my fish using the instructions in the Aquarium Tutorial. I reached the Random Speed part and configured my fish "by hand" without using any datablocks.
I also went overboard and added an
at the end of the FishClass::setSpeed(%this function).
I started the game in the TGB Debugger in order to compile all scripts to dso files. I quit and then I started the game using Xcode using the simulator of IPhone 4 (was to lazy to connect my iPod). Everything worked fine, and each time an edge of the world limit was reached, I got a nice text message which informed me what the current speed is. Everything ok until now.
Now, I started to create a config datablock. I did the usual steps, closed everything, reopened everything, ran the TGB Debugger and the game works fine. I clicked on the fish to check it's world limits, in the editor they were wrongly set, but I believe the config datablock comes into play only at runtime (correct me if I am wrong).
However, when I tried running the project using the iOS simulator, I got a very strange thing happening. Instead of the nice speed text message change each time the fish reached its edge, I got that message with random speed values EVERY SECOND. However the game still seems to respect the "normal" speed changes, albeit it moves a bit slower.
Am I missing something? I will tag this as a 1.5 bug, no offense if this is not a bug and I am doing something wrong.
I set up my fish using the instructions in the Aquarium Tutorial. I reached the Random Speed part and configured my fish "by hand" without using any datablocks.
I also went overboard and added an
echo(%this.speed);
at the end of the FishClass::setSpeed(%this function).
I started the game in the TGB Debugger in order to compile all scripts to dso files. I quit and then I started the game using Xcode using the simulator of IPhone 4 (was to lazy to connect my iPod). Everything worked fine, and each time an edge of the world limit was reached, I got a nice text message which informed me what the current speed is. Everything ok until now.
Now, I started to create a config datablock. I did the usual steps, closed everything, reopened everything, ran the TGB Debugger and the game works fine. I clicked on the fish to check it's world limits, in the editor they were wrongly set, but I believe the config datablock comes into play only at runtime (correct me if I am wrong).
However, when I tried running the project using the iOS simulator, I got a very strange thing happening. Instead of the nice speed text message change each time the fish reached its edge, I got that message with random speed values EVERY SECOND. However the game still seems to respect the "normal" speed changes, albeit it moves a bit slower.
Am I missing something? I will tag this as a 1.5 bug, no offense if this is not a bug and I am doing something wrong.
#2
However it is the same config datablock that is used in the demonstrations of iTorque 1.5.
My main problem is however the stuff with the XCode that happends. Is that a bug? Or am I doing something wrong? Instead of the nice speed text message change each time the fish reached its edge, I got that message with random speed values EVERY SECOND. That's my problem. I can record a short movie if it helps. My english is sometimes not so clear.
12/06/2011 (7:41 am)
I am at work now so I can't post it. However it is the same config datablock that is used in the demonstrations of iTorque 1.5.
My main problem is however the stuff with the XCode that happends. Is that a bug? Or am I doing something wrong? Instead of the nice speed text message change each time the fish reached its edge, I got that message with random speed values EVERY SECOND. That's my problem. I can record a short movie if it helps. My english is sometimes not so clear.
#3
12/08/2011 (7:53 am)
@Alkor - It will still help me to see the exact code you are using (copy+paste) for the datablock and the flipping code.
#4
12/09/2011 (12:27 am)
Alright, I will give them as soon as I get home!
#5
12/09/2011 (1:20 pm)
As promised, here it is.//fish config datablock
//default values are used by FishClass for swimming functionality
datablock t2dSceneObjectDatablock(FishDataBlock)
{
Class = "FishClass";
Layer = "4";
WorldLimitMode = NULL;
WorldLimitMin = "-305.000, -167.322";
WorldLimitMax = "312.107, 175.000";
UsesPhysics = "1";
WorldLimitCallback = "1";
minSpeed = "15";
maxSpeed = "45";
facingDirection = "X";
};// Create this behavior only if it does not already exist
if (!isObject(ScaredFish))
{
// Create this behavior from the blank BehaviorTemplate
// Name it TouchDrag
%template = new BehaviorTemplate(ScaredFish);
// friendlyName will be what is displayed in the editor
// behaviorType organize this behavior in the editor
// description briefly explains what this behavior does
%template.friendlyName = "Scared Fish";
%template.behaviorType = "Fish Actions";
%template.description = "If the user touches the screen, fish will get scared and run faster";
%template.addBehaviorField(selectedFish, "Color to see which fish is selected", color);
}
function ScaredFish::onBehaviorAdd(%this)
{
%this.touchID = "";
%this.owner.setUseMouseEvents(true);
}
function ScaredFish::onTouchDown(%this, %touchID, %worldPos)
{
//%this.owner.setBlendColour(%this.selectedFish);
if (%this.owner.facingDirection $= "left")
{
%this.owner.setLinearVelocityX(-150);
}
else if (%this.owner.facingDirection $= "right")
{
%this.owner.setLinearVelocityX(150);
}
else if (%this.owner.facingDirection $= "X")
{
%this.owner.setLinearVelocityX(150);
}
// If we are already dragging, do nothing
// Otherwise, enable the drag variable
if(%this.touchID $="")
{
%this.touchID = %touchID;
}
}
function ScaredFish::onTouchUp(%this, %touchID, %worldPos)
{
//%this.owner.setBlendColour(1.0, 1.0, 1.0, 1.0);
if(%this.touchID $= %touchID)
{
%this.touchID = "";
}
}
function ScaredFish::onTouchMove(%this, %touchID, %worldPos)
{
%this.owner.setBlendColour(1.0, 1.0, 1.0, 1.0);
if(%this.touchID $= %touchID)
{
%this.touchID = "";
}
}
#6
If you are getting the echo message constantly, I would guess that its sitting in the onUpdate method, and firing off ~30 times per second, which could also make xcode run slower, as it has to write all of that to the log at the same time.
12/09/2011 (11:35 pm)
I think we might need to see your FishClass::onUpdate() , and FishClass::onWorldLimit() methods as well. If you are getting the echo message constantly, I would guess that its sitting in the onUpdate method, and firing off ~30 times per second, which could also make xcode run slower, as it has to write all of that to the log at the same time.
#7
Here is the onWorldLimit()
And setSpeed() one
12/10/2011 (5:54 am)
I do not have an onUpdate function.Here is the onWorldLimit()
function FishClass::onWorldLimit(%this, %mode, %limit)
{
//fish has turned around, set a new random speed
%this.setSpeed();
//set a string comparison based on %limit
switch$ (%limit)
{
//fish hit left boundary
//make it face right and go in that direction
case "left":
%this.facingDirection = "right";
%this.setLinearVelocityX(%this.speed);
%this.setFlipX(false);
%this.setPositionY(getRandom(-134, 107));
//fish hit right boundary
//make it face left and go in that direction
case "right":
%this.facingDirection = "left";
%this.setLinearVelocityX(-%this.speed);
%this.setFlipX(true);
%this.setPositionY(getRandom(-134, 107));
}
}And setSpeed() one
function FishClass::setSpeed(%this)
{
//speed is a custom dynamic variable created when this function is first called
//any other time the first call will simply modify the variable
%this.speed = getRandom(%this.minSpeed, %this.maxSpeed);
//echo(%this.speed);
}
Community Manager Michael Perry
ZombieShortbus