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.

Page «Previous 1 2 3 4 5 6 Last »
#1
10/22/2009 (1:13 pm)
function enemy::onUpdate(%this)
{
	%this.getPosition();	
}

That code will do nothing. I think it's worth it to help you step through the troubleshooting process so that in the future you can work faster and more efficiently:

1) What are you trying to accomplish in this function?
2) What does the function getPosition() do, and how does a person work with it?
3) What does the line %this.getPosition(); do that gets you to the goal you outlined in #1, and/or how should that line be corrected or modified?
#2
10/22/2009 (1:13 pm)
one question (i've spotted a couple errors in your code, and stopped reading it): do you actually run that code? (i kinda know the answer) if so, does it give you any errors? if so, do you spot them at run time, and then go to the editor and correct them?...

you know, sometimes... just SOMETIMES, we, the ones that actually use the engine, write things in our preferred editor, compile the code and see how it runs... if it doesnt work, we go thru the code again to see if its a logical problem or something else.

i have the feeling that that method might work for you too... if only you could give it a go... i cant help but imagine that you wouldnt be asking so many useless (and repeated) questions every day, and i wouldnt post this "meaningless", "tiresome", "bothersome" "etc" replies (from your pov, that is).

so, do you mind giving that method a try?... pretty please?

oh... and btw, yet another thread with misleading title (do you actually know what the % simbol is used for?... if so, why using it the way you're doin it lately?)
#3
10/22/2009 (1:17 pm)
Quote:
That code will do nothing.

sorry Ted, that code actually does something: WASTE SOME PRECIOUS CPU CYCLES.

Quote:
1) What are you trying to accomplish in this function?
2) What does the function getPosition() do, and how does a person work with it?
3) What does the line %this.getPosition(); do that gets you to the goal you outlined in #1, and/or how should that line be corrected or modified?

good advice... if only he would listen (read)... im still under the impression that all he does, is hack together some snippets from here and there, change some function names and stuff like that, and then, w/o even compiling, comes to the forums asking for help.
#4
10/22/2009 (1:27 pm)
@Ehrlichman: Easy, dude :) I'm just trying to get him to think in terms of troubleshooting the script so that he develops the critical thinking skills used in scripting and coding. Answering his questions in this way helps him learn those skills, which will help him both reduce the amount of mistakes he makes, as well as review his script and catch errors before needing to post to the forums and then wait for the answer.

@Rennie: I don't think getting direct answers to your questions is actually helpful to you at this point. You know enough scripting to be dangerous ;) So it's better that future answers for you be given in the form of guided troubleshooting steps. In other words, what I'm doing here is giving you ways to look at the scripts to find out what is wrong instead of just telling you so that you can eventually be able to do that on your own. It will make you a much better scriptor.
#5
10/22/2009 (1:38 pm)
Ted, i got it from the very 1st time... is just that, as you will get to notice any time soon, that he will ditch your advice, and ask for the very same thing i a different way in a months time or so.

maybe i havent done it the way you just did (which by the way, its the way every programmer thinks when something goes wrong with its code and is looking to catch the "whats goin on" in his code), but trust me, i've tried (and William and some others too)... with no luck.

but yeah... im gonna try and take it easy.
#6
10/22/2009 (3:27 pm)
@Ted: Thanks. I will keep that in mind fine sir. I am looking forward to the fun, I can be having with Torque and TGB, I will keep you posted on the yacht ride to Heaven's Island!


Cheers,
Ren
#7
10/22/2009 (3:30 pm)
Rennie, I meant post the answers here so that we can help you learn how to troubleshoot the code.
#8
10/22/2009 (3:31 pm)
Yes I understand that. Future times will call.


Cheers,
Ren!






I am thinking this should be pretty good tho.



#9
10/22/2009 (3:36 pm)
@Ted.
Sorry I have been away from TGB for the last hour or two. I just saw this now...



Essentially I am trying to insure my owner.position will be known, for the getWorld or setWorldLimit function. Trying to figure out if one should go here. You see I don't like using that one, but it seems it is a must.


My main problem is trying to decide if my shoelaces go on my shins or my shoes right now.





Things like that, small calls, stuff that should be easy, and will be but my overall problem is that I have difficulty in isolating terms and what should go where. I think. Putting it all together really.
#10
10/22/2009 (4:04 pm)
@Rennie: Okay, you only answered the first question, so you're not off the hook for the other two...

You said you are "trying to insure my owner.position will be known, for the getWorld or setWorldLimit function", so that's good- you know what you are trying to do. Now answer the next two questions and we'll proceed to the steps beyond those.

Quote:Things like that, small calls, stuff that should be easy, and will be but my overall problem is that I have difficulty in isolating terms and what should go where. I think. Putting it all together really.

That's why you need to answer the questions I'm laying out, so you can figure out what goes where. If you don't provide the answers and go through this process, then I will give up on helping you. Deal? Deal.

#11
10/22/2009 (4:14 pm)
function enemy::onUpdate(%this)  
{  
    %this.getPosition();      
}

@Ted
1) What are you trying to accomplish in this function?

I was thinking that the position of the object should always be known. Perhaps setting this up in another function like "onLevelLoaded", or "onAddBeahior" would do?


2) What does the function getPosition() do, and how does a person work with it?
Well hmm, getPosition simply calls a vector. OH! so, by calling a vector, it will be called in which ever function this method exists? if so, then that vector will only be in that function unless!(?), I can place it as a a variable that could be called in other functions say %ObjectPosition = %this.owner.getPosition();


But if that is so, where do I then put this and use this best, where ever I sit fit I suppose?



3) What does the line %this.getPosition(); do that gets you to the goal you outlined in #1, and/or how should that line be corrected or modified?



%this.getPosition() will call the 0,0 vector of the object in question (%this), in worldSpace.




Am I right? I think so for the most part.












#12
10/23/2009 (10:08 am)
@Ted,
this may be of help to you to better understand my lackings.

My main issue, I think is that I have trouble in relating methods and where they should go. I am going to be going over in more detail the tutorials etc but this is a good example for me.


WolrdLimits:

Now I would think, if this were a behavior of an enemy AI, %this.setWorldLimit(); should be called in the onBehaviorAdd or onLevelLoaded or even onEnterScene functions

if I have an "update callback" enabled, I am thinking that it (owner.getPosition) should go here as it will continually update the owners position, thus allowing the onWorldLImit function to be aware of the owners.position.

Is this thinking right? it is in my head, but I am unsure in programming if this is truly correct.
#13
10/23/2009 (10:31 am)
I might be wrong but what I understood from http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide is the following:

function enemy::onUpdate(%this)    
{    
    %this.getPosition();        
}

%this.getPosition(); will return the position of %this.

Let's suppose that the position of %this is equal to "34 87", the code above is the same as:

function enemy::onUpdate(%this)    
{    
    "34 87";        
}

Meaning that the code is doing nothing useful (except wasting CPU cycles as pointed out before).

getPosition() returns a value. The code you posted don't do anything with that value...

That's how I understand it. Again, I'm not sure of it: I haven't touched t2d for a very long time and haven't done much more than the most basic tutorials, so don't take my word... double-check ;)
#14
10/23/2009 (10:40 am)
Yes, I remember reading about that. That the CPU is used and abused like no other when dealing with the onUpdate callback, so you should be very careful with what you add here, or (from my understanding any update callback, ie updateMovement)











#15
10/23/2009 (10:54 am)
actually, what I meant was more that, if I understand getPosition() well, you're just loading the CPU with that line of your code without any use...
#16
10/23/2009 (11:55 am)
@Rennie: Seb is getting to the conclusion that I was trying to make you see by reviewing your code. You touched on it when you listed the corrected line storing the position in the variable, and then you pursued a tangent about putting the function anywhere you "see fit", which is incorrect. The correct answer is that you put it where it is needed, and nowhere else, or else it's a waste of effort.

The thing is, you're grabbing the position of this and...do nothing with it. It goes into the void. Even if you use the corrected line and store it in a variable, you're still doing nothing with the variable, and the variable ceases to exist once that function concludes (which is immediately after the line that calls and/or stores the information).

Now, what's the purpose of that? You say you want the Enemy object to be aware of the position, but to what end? Programs do not have awareness, so unless you store the position and access it with a purpose, all you're doing is wasting CPU cycles.

So, the next step is:

1) What is the Enemy supposed to do with the position information, and under what circumstances?
#17
10/23/2009 (12:22 pm)
well he is supposed to (with the getPosition info) decide wether or not he is onWorldLimit

and if so, do something.

if that is true, would getPosition be best used in onWorldLimit?
#18
10/23/2009 (1:24 pm)
now you understand, Ted, why it is SO DIFFICULT to try an make this guy come into his senses and try and understand things the right way?... not even his logic works correctly, cuz he says again and again that he reads the docs, when its painfully obvious that hes not doing such thing?...
#19
10/23/2009 (1:30 pm)
I thought I asked you not to reply to any of my posts.

Please don't in the future.
I think you have a lot of negative energy and I don't want you thinking you can direct any of it at me.


Thanks











#20
10/23/2009 (1:43 pm)
Moderated. Do not post harassing or inflamatory comments.
Page «Previous 1 2 3 4 5 6 Last »