Game Development Community

Better Understanding %WorldLimit and %onUpdate Together

by rennie moffat · in Torque Game Builder · 10/22/2009 (12:42 pm) · 107 replies

Hi there, if some could, please tell me where I am going wrong with this, or if I am not, I sure I am though. Where I am having most trouble is where I link things, so to speak, I am not sure about my on update and even if it should exist and if it should what command should really go in there.


function Enemy::onLevelLoaded(%this)
{
  %this.owner.enableUpdateCallback();
   
  %left = getWord(%worldLimit, 1);
  %top = getWord(%worldLimit, 2);
  %right = getWord(%worldLimit, 3);
  %bottom = getWord(%worldLimit, 4);

  %this.setWorldLimit("NULL", %left, %top, %right, %bottom, true);
  
 }
 
 
function enemy::onUpdate(%this)
{
	%this.getPosition();	
}
 
 
function enemy::onWorldLimit(%this, %limitMode, %limit)
{
	
	
	%this.owner.getWorldLimit();
	
	switch$(%limit)
	{
		case "left":
		if (%this.left)
		{
			%this.owner.setLinearVelocityY(5);
		}
	        case "right":
		if (%this.right)
		{
			%this.owner.setLinearVelocityY(-5);
		}
	
	        case "top":
		if (%this.top)
		{
			%this.owner.setLinearVelocityX(5);
		}
	
	        case "bottom":
		if (%this.bottom)
		{
			%this.owner.setLinearVelocityX(-5);
		}
	

	}


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.

#61
10/26/2009 (2:12 pm)
@William, hi, I am just working over this. and I believe I wanted to reply to you comment on local vs global variables and what they were.

I did have a question for you. Are local variables local to a function or a class?
#62
10/26/2009 (2:23 pm)
@William just have gone over your info. Thanks.
a few questions tho.



The following script assumes a few things:
1) redRiserImageMap is already defiend in TGB (or elsewhere in scripts).
%redRiser = new  t2dStaticSprite()
ok, so if it is, for instance, where would the most ideal place be to define it? It's class? onLevelLoaded?


2) Objects that interact with this must have the "Send Collision" box checked in TGB (or elsewhere in scripts).

OH! So, my Spacer3000 is going to fly over the trigger, which is setoff due the onEnter Trigger call. But in order for them to notice each other, set off the trigger use collisions. Ok that sounds easy!

3) That your trigger is named "centerTrigger".

Yes done in onLevelLoaded of centerTrigger class
%this = %this.centertrigger;
Is that correct?
#63
10/26/2009 (2:28 pm)
Local variables are local to a function. (It's a bit of a simplification, but it works well for Torque Script.)

But local variables may references global variables or single objects (like your player in a game).

For example, in that last bit of code, both "%this", "%object", and "%redRiser" will only exist inside the function "onEnter".

But the "%this" will reference the single "centerTrigger" that you put into your scene in TGB. The "%object" will reference your player (or anything you allow to interact with the trigger).

But you'll never be able to access "%redRiser" again. Once the function is done, the variable "%redRiser" means nothing.

If you _needed_ to access it again, there are many ways you could do this.

If there were ever only going to be 1 "riser" at a time, you could assign it to a dynamic variable in the trigger itself ("%this.redRiser = %redRiser;"). Or, you could give the riser a name ("%redRiser = new t2dStaticSprite(Bob)...").

If you _needed_ to access it again, but there were going to be many of these "risers" at at time, you'd add them to a SimSet.
#64
10/26/2009 (3:35 pm)
Quote:But you'll never be able to access "%redRiser" again. Once the function is done, the variable "%redRiser" means nothing.



So if I wanted to access redRiser again in another function in another class, how would I call it?




Quote:
("%redRiser = new t2dStaticSprite(Bob)...").
What is Bob in this? Is it an imageMap name?


Quote:
If you _needed_ to access it again, but there were going to be many of these "risers" at at time, you'd add them to a SimSet.
Nice.




;].r.1k


#65
10/26/2009 (3:37 pm)
Hi, I am currently working on a shoots behavior. It is not working. and I am not sure why. Could someone if you have a moment spot the error?


PS. No errors in compiler, so it must be a function etc.

if(!isObject(Spacer3000ShootsBehavior))
{
	%template = new BehaviorTemplate(Spacer3000ShootsBehavior);
	
	%template.friendlyName = "Spacer3000 Shoots Behavior";
	%template.behaviorType = "Spacer 3000 Shoots Behavior";
	%template.description = "Spacer3000 Shoots Behavior";
	
	%template.addBehaviorField(Keybind, "Key to bind Shooting Behavior", keybind, "Space");
	%template.addBehaviorField(SpacerProjectile01, "Projetile01 of Spacer3000", object, "SpacerProjetile01",  t2dSceneObject);
	%template.addBehaviorField(Velocity, "Velocity of projectile", flaot, 30);
}
	


function Spacer3000ShootsBehavior::onBehaviorAdd(%this)
{
	if(!isObject(moveMap));
	return;
	
	%this.enableUpdateCallback();	
	moveMap.bindObj(getWord(%this.SpacerShoot, 0), getWord(%this.SpacerShoot, 1), "SpacerShoot", %this);
	
	%this.SpacerShoot = 0;
}


function Spacer3000ShootsBehavior::onBehaviorRemove(%this)
{
	if(!isObject(moveMap))
	return;
	%this.disableUpdateCallback();
	
	moveMap.unBindObj(getWord(%this.SpacerShoot, 0), getWord(%this.SpacerShoot, 1) "SpacerShoot", %this);

	%this.SpacerShoot = 0;
}

function Spacer3000ShootsBehavior::onUpdate(%this)
{
	%this.SpacerShoot();
}


function Spacer3000ShootBehavior::SpacerShoot(%this, %val)
{
	if(%val == 0)
	{
		cancel(%this.SpacerProjectile01)
		return;
	}
	
	if(!isObject(%this.SpacerProjectile01))
	return;
	
	%SpacerProjectile01 = %this.SpacerProjectile01.cloneWithBehaviors();
	
	%SpacerProjectile01.setPosition(%this.owner.position);
	%SpacerProjectile01.setLinearVelocityY(%this.Velocity);
}



#66
10/26/2009 (4:40 pm)
Please stop lying to all of us. I spent but 15 seconds looking at this before I found 3 compile errors!

What this also tells me is that you didn't try it. Because of the compile errors, it wouldn't even show up in the behavior list.
#67
10/26/2009 (4:40 pm)
The code has been updated, I still am struggling with it and I don't know why? I am getting in more and more but here, for instance I have all things mostly right (there in lies the problem). But I figure, I must have a very noticeable bad habit that could be easy to spot by a pro or someone above white belt with blue stripe.


if(!isObject(Spacer3000ShootsBehavior))
{
	%template = new BehaviorTemplate(Spacer3000ShootsBehavior);
	
	%template.friendlyName = "Spacer3000 Shoots Behavior";
	%template.behaviorType = "Spacer 3000 Shoots Behavior";
	%template.description = "Spacer3000 Shoots Behavior";
	
	%template.addBehaviorField(Keybind, "Key to bind Shooting Behavior", keybind, "Space");
	%template.addBehaviorField(SpacerProjectile01, "Projetile01 of Spacer3000", object, "SpacerProjetile01",  t2dSceneObject);
	%template.addBehaviorField(Velocity, "Velocity of projectile", flaot, 30);
}
	

function Spacer3000ShootsBehavior::onBehaviorAdd(%this)
{
	if(!isObject(moveMap));
	return;
	
	%this.enableUpdateCallback();	
	moveMap.bindObj(getWord(%this.shootKey, 0), getWord(%this.shootKey, 1), "SpacerShoot", %this);
	%this.SpacerShoot = 0;
}


function Spacer3000ShootsBehavior::onBehaviorRemove(%this)
{
	if(!isObject(moveMap))
	return;
	%this.disableUpdateCallback();
	
	moveMap.unBindObj(getWord(%this.shootKey, 0), getWord(%this.shootKey, 1) "SpacerShoot", %this);
	%this.shoot = 0;
}


function Spacer3000ShootBehavior::SpacerShoot(%this, %val)
{
	%SpaceProjectile01 = %this.SpacerProjectile01;
	%SpaceProjectile01.cloneWithBehviors();
	
	if(%val == 1)
	{	
		%SpacerProjectile01.setPosition(%this.owner.getPosition());
		%SpacerProjectile01.setLinearVelocityY(%this.owner.xVelocity() + %this.velocity);
	}
				
}
#68
10/26/2009 (4:43 pm)
um, Please stop accusing me of lying.

It shows up in my editor and does not have any errors.


or didn't I just checked, there is one on 17 I must have put in an eidt.
JEzz Willam easy on the language, its easy to be harsh, but hard to take harsh esp on email. person to person even, god. In fact I find that very rude, please apologize.
#69
10/26/2009 (4:47 pm)
ps. the error was a semi colon, clearly something to get upset about.




:?
#70
10/26/2009 (4:54 pm)
What do you call it when somebody says "No errors in compiler" when in fact there are several? I was raised to call that lying.

Not one word in my last post was harsh. It states 2 facts (it won't compile and it won't be in the behavior list). All of it was true and can be backed up with facts. I will gladly provide screenshots to prove all of it if necessary.

Even your new code has compiler errors.

I will not apologize to you. Stop lying, try your code, and then you can apologize to me for saying that my facts are fabrications.
#71
10/26/2009 (4:59 pm)
oh ok fair.
I didn't know that.

I swear i ran it thru the compiler and got no errors. But obviously I made an error because it does have them so I am sorry.

Anyhow....
Please do not call me a liar, if you can do that we are all good

Thanks
Ren
#72
10/26/2009 (5:05 pm)
Here is something good from me.


I am looking at this code from the shhots behavior it is not bad kind of exciting. anyhow...
here is the code



function ShootsBehavior::fire(%this, %val)
{
   if (%val == 0)
   {
      cancel(%this.fireSchedule);
      return;
   }
in this would which has nothing declared for when %val == 1, does that mean it (the function) assumes that if it is NOT 0 then it is 1?






#73
10/26/2009 (5:11 pm)
Rennie, you posted code that will not run because of syntax errors, and yet you claimed to have run it. Your claim is provably false, because what you posted here will not run. You're not dealing with a bunch of noobs here; we can clearly see that you aren't doing what you say you're doing.

You are the one who's being rude and needs to apologize here. You also need to begin showing some evidence (not claims - evidence!) that you're actually listening to the advice you get. I've explained some things to you two or three times, and pointed you to docs that explain it again, and you've shown no signs of having read any of it.

Get the chip off your shoulder, stop yelling at people who want to help you, and start listening to us instead. Until you do these things, you'll get no further help from me.
#74
10/26/2009 (5:17 pm)
hmm, there must be a mix up some how between files. I have been experiencing that recently since I had to remove and reboot TGB from scratch. I will investigate.


But I promise you I was not lying, Why would I do such a thing? Really, what would I have to gain?




This is strange here I am not yelling at all or angry, I am just working I am not trying to get into it with anyone, please relax.
#75
10/26/2009 (5:18 pm)
PS

Quote:
from Rennie:
I swear i ran it thru the compiler and got no errors. But obviously I made an error because it does have them so I am sorry.

I already did apologize to him, I guess you did not read my post fully.



#76
10/26/2009 (5:30 pm)
I am going to aplogise again, I swear I ran the compiler and saw no errors. AND my game runs, AND it shows up as a slectable behavior.



Anyhow, I do have a serious questionI would love help on. if you can and have a moment, please look at this as I can not explain the error, your help is very important to me.


moveMap.unBindObj(getWord(%this.shootKey, 0), getWord(%this.shootKey, 1) "SpacerShoot", %this);
this is line 29 of the code, where the error exists but I see no error. Is there one?
#77
10/26/2009 (5:30 pm)
Actions speak louder than words. As I said, I'm done with you until you show me that you've changed your ways. I'm also finished discussing it.
#78
10/26/2009 (5:32 pm)
Please see above, post 76.
#79
10/26/2009 (5:38 pm)
ps and why should I have to prove to you that I have "changed". Have you known me for a long time or something?