Game Development Community

making a behavior a class script.

by rennie moffat · in Torque Game Builder · 06/18/2010 (3:16 pm) · 12 replies

Hi, I am just wondering if someone could give me some quick help. I have relied on behaviors to develope my game tho I have had suggestins made than in iTGB, what I am working in now is "not totally groovey" with behaviors. As such, just a quick question. Edit; if others know that behavior are "just fine" in iTGB, just as TGB please post thoughts, otherwise, please read on.

Thanks.


if in a behavior
if(!isObject(tileBehavior))
{
	%template = new behaviorTemplate(tileBehavior);
	
	%template.friendlyName = "tile Behavior";
	%template.behaviorType = "tile";
	%template.description = "tile";
	
	%template.addBehaviorField(velocity, "", float, "60");
	%template.addBehaviorField(object, "", object, "object", t2dSceneObject);
}

function tileBehavior::onBehaviorAdd(%this)
{
	%this.positionX = %this.owner.position.x;
    %this.positionY = %this.owner.position.y;
}


function tileBehavior::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{		
	%this.object.moveTo(%this.positionX, %this.positionY, %this.velocity, true);
}


How would I make this a class script?




About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
06/18/2010 (4:40 pm)
Put the following code in a script file that get executed (not in the behavior directory) and save it.
function tile::onLevelLoaded(%this, %scenegraph)
{
   %this.velocity = 60;
   %this.positionX = %this.getPositionX();
   %this.positionY = %this.getPositionY();
}

function tile::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{		
   %this.moveTo(%this.positionX, %this.positionY, %this.velocity, true);
}

Then set the class of your object to 'tile' in the editor and make sure the mouse events are enabled.
#2
06/18/2010 (4:48 pm)
and this could just be called in tile.cs from the game.cs right?


#3
06/18/2010 (4:53 pm)
Be careful, as there are several issues you are missing here.

1) Does your tile have more than 1 behavior on it? If so, you need to analyze all of the interactions and build a class that accounts for all of these behaviors.

2) I don't think this behavior would be sped up by making it a class, but I don't know iTGB at all.

3) Patrick's answer is a start, but it's missing a few things. The "object" class is what actually moves and also needs to be assigned to the class. The velocities look like they could be variable in your behavior. It appears that you manually set "Use Mouse Events" on each tile in the editor, a feature that needs to be clarified before building the class.

You need to resolve these issues with the other behaviors to actually build a class.
#4
06/18/2010 (5:06 pm)
@william
2. there seem to be quite a few complaints. Much confusion. As Of right now I am a little dissapointed, but am far from being able to give a verdict. It might just be little things I need to learn about the engine. But as of right now, my game that works in TGB will not run in iTGB at all. If i make a test level, attach one behavior that works here, crashes there.



3. are you saying, of course
%this.moveTo();
///absent arguments noted

how would I declare an object that is not of tile class to moveTo on mouse up so something like...
%this.obeject.moveTo();

#5
06/18/2010 (5:10 pm)
@william
1. no, in this case it does not. However one very strange thing that has happened to me in iTGB is that I was experiencing all this funny business so I went to look at the level.cs file just to see if I could see anything funny. Some of the objects, with one behavior attached ( this is true since I double checked the editor ) had 2 (identical) behaviors attached in the level.cs.


So for example, objectX had _behavior0 = "thisBehavior" && objectX also had _behavior1 = "thisBehavior", when it was only attached once in the editor.

As I say after a few days of working with I am reserving judgement but am bummed so far. I am optimistic tho. I hope it is just a little adjustment here and there that I need to make.
#6
06/18/2010 (5:16 pm)
I can't answer your questions about the "object" because I'm not sure how your behavior works. Did you assign your player to the "object" field of every tile? Or can any object be assigned to the "object" field? Do you manually set "Use Mouse Events" on each tile in the editor? And what about speed? Can clicking on a certain tile cause the user to move at different rates? Are there other behaviors added to the tile that might cause interactions with this behavior?

All of these questions must be addressed before a real solution can be found. Patrick or I could just "convert" your behavior, but to really get to a proper answer, much more needs to be addressed.

This is serious. Migrating behaviors to classes is not a 1-to-1 operation. If you are going to migrate your behaviors into classes, you need to design your classes from the ground up. This means factoring in every behavior on each type of object in your game and building the proper class for it.
#7
06/18/2010 (5:40 pm)
well, perhaps "object" is a bad description, or word to use.

lets call object, in this case "player". Player is a t2dSceneObject, named: player, class defined as: playerClass.


On mouseUp on tileClass, "player" moves to that specific (one which experienced mouse event) tile.



All other issues..,
Speed: always constant, no matter the tile.

mouseEvents, for each tile object of tileClass are true. I guess I did not set that in the example. In the real world I did. :::)sorry().





On your last point, are you simply saying that if I have say 3 behaviors on one object, that I now need to have those 3 behaviors act as a single class script? if so I understand.


#8
06/18/2010 (6:42 pm)
If you've checked mouseEvents for the tile and have given the tile a class name "tile", then you can do as Patrick has shown, with an alteration:
function tile::onMouseUp( %this, %mod, %worldPos, %mouseClicks )
{		
  %playerSpeed = 60; // I shudder to put this here, but
                     // I can't get into how to re-design
                     // all of your code.
  player.moveTo( %this.getPosition(), %playerSpeed );
}

As a simple answer, if you have 3 behaviors on one object, you'll need to convert those 3 behaviors to act as a single class. The more complex answer is that there are ways to use the "superClass" that would save some duplication of code, but that's something you need to decide.
#9
06/18/2010 (7:12 pm)
Cool,
I really feel I have it down. I just need to think of or more precisely, realize how iTGB works. It can't be a shame. Hey I thoughtTGB was a sham back in the day. I was so terrible, with out a clue how to do anything, and I have built a very good game that I think will work well with any iDevice.
#10
06/18/2010 (8:31 pm)
You should put a video of your game on YouTube (even if it's just the TGB version) and write a blog of your progress with TGB. That way you can start generating interest in your game while you wrap it up.
#11
06/18/2010 (8:44 pm)
Yes good idea. I was thinking of getting some software so I could film my screen. Hmm, perhaps sooner then later. I did want to, was going to post a blog upon completion. My plan was to have it finished last week. I thought transfer upload to XCode, iTunes would only take a day. Seems I was wrong, but inexperience can do terrible things... anyhow, things aren't so bad. I will post a blog with the next month or so, will keep you posted.

#12
06/19/2010 (7:58 am)
just a heads up, to anyone reading this who does iTGB and that I may have brought any doubts to. My problem was that I had copied my dso files with my cs files from TGB into iTGB.



Woops.