Game Development Community

onWorldLimit

by rennie moffat · in Torque Game Builder · 10/07/2009 (4:10 pm) · 54 replies

I am just better trying to understand how to code this.

From many of the examples I have seen the case where switch$ (%limit), with case"left" etc used, this is fine, but what I am wondering is, many seem to declare "left", "right" etc, with conditions for each. What I am wondering is, are these bottom, top etc, inherent only when you set up the worldLimits thru the console?


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 Last »
#1
10/07/2009 (4:52 pm)
Here may be of service. I am trying to do this. if you don't want to answer I understand.

My code is still holding, let me try. will post.
thanks.
#2
10/07/2009 (5:34 pm)
I have something, perhaps if you have a minute please take a look.

It is code for my onWorldLimits function, it is the approach i think I should take now towards building my worldLimits, for the player.


I am receiving an error in the code on line 2, before the {, but I think it must be inside the code.


%this.owner.left()
		{
			if (%playerPosition + %cameraPosition <= -50)
			{
				%this.left();
				%this.owner.setLinearVelocity(2);
			}

the code that concerns me is the fact I have this inside my onWorldLimits Function. I have previooulsy called setWorldLimit in my onBehaviorAdd. I set it as..

%this.owner.setWorldLimit(CLAMP, %this.owner.left, %this.owner.top, %this.owner.right, %this.owner.bottom, true).

I am unsure of my calls to my {min|max}{x|y}'s. Can I/should I set them to %this.owner like that, or am I just messing with the system?








#3
10/07/2009 (5:42 pm)
I have looked at case methods as well, but not sure if the lack of them, in my code is what is causing the problem.
#4
10/07/2009 (5:57 pm)
re:
left, right, top, bottom.


%limit - This is either "Left", "Right", "Top", or "Bottom", depending on the side of the world limit that was hit.
#5
10/07/2009 (6:05 pm)
switch$(limit)
		{
		case "left":
			if (%playerPosition + %cameraPosition <= -50)
			{
				%this.left;
				%this.owner.setLinearVelocityX(2);
			}

has turned out that the %this.owner.setLinearVelocityX(2);
is causing the glitch, but I want my player to kind of "bounce" off of the wall when hit.
#6
10/07/2009 (6:23 pm)

switch$(limit)
		{
		case "left":
			if (%playerPosition + %cameraPosition <= -50)
			{
				%this.setLinearVelocityX(2)
			}	
///i am currently getting an error right here. This perplexes me, as I cant explain why.		
		case "right":
			if (%playerPosition + %cameraPosition >= 50)
			{
				%this.setLinearVelocityX(-2)
			}
			
		case "top":
			if (%playerPostion + %cameraPosition >= -50)
			{	
				%this.setLinearVelocityY(-2)
			}
			
		case "bottom":
			if (%playerPosition + %cameraPosition >=50)
			{
				%this.setLinearVelocityY(2)
			}
#7
10/08/2009 (1:46 am)
... i cant help it man... i know you'll get angry (like i care)... but you havnt learned a damned thing in the last 3-4 months... the errors in your code are SO SILLY (in most cases) that it actually hurts.

just a hint... i've spotted no less than 6 errors in your code.
#8
10/08/2009 (4:26 am)
@Ehrlichmann - Man, you've created a "Where's Waldo" and now I wanna play!

@Rennie - You have a lot of errors in this, not just where the compiler is telling you. If I just told you how to fix the one thing you asked, you'd be back a dozen more times, so let me try to list the errors. (I'll be making a few assumptions on where this code is located based upon your previous posts.)

Compile Errors:
1, 2, 3, 4) Statements are supposed to end in semi-colons. Every programmer I've ever met is terribly embarassed if they ask for help and this was the cause.

Intent Errors (the compiler won't tell you about these):
5) Is "limit" a named object? I'm guessing that it's really a passed in parameter and should be referenced as such.
6) I'm guessing that you haven't really set "%playerPosition" and "%cameraPosition" to anything. The engine will happily create the variable for you on their first use.
7) I'm almost certain that one of the ">=" is meant to be a "<=".

Logic Errors (the compiler won't tell you about these, either):
8) Even if you are setting the positions, they will be vectors. When you add "1 10" to "2 20", you'll get "3".
9) You aren't even using the y-component on the "top" and "bottom" cases.
10) Assuming you are in an "onLimit" function, the cases for the "%limit" variable will be telling you that you've already hit the edge.
11) I'm not positive, but I think you have your velocities backwards in the last two cases.
12) If the player hits the edge, do you want them to continually move away from the wall if the user doesn't intervene or did you just want bounce behavior?

It's too bad that you don't have a Windows machine. There is a really great tutorial program to learn the very basics of programming in TGB. I think it would be really worth your time to try to get access to a Windows machine and to get this product.
#9
10/08/2009 (10:43 am)
Quote:
It's too bad that you don't have a Windows machine. There is a really great tutorial program to learn the very basics of programming in TGB. I think it would be really worth your time to try to get access to a Windows machine and to get this product.

if im not mistaken, even if you dont have a windows machine, you can still run those tuts. and if you're on a Mac its even easier, since you can emulate windows and all that...
#10
10/08/2009 (1:41 pm)
Yes I can split my drive and run windows on one partition. I will look at this tut. I could be wrong but i think that life would be so much easier if I had somebody who I could actually talk to, like if I were in a class room, if i had a teacher, but ces la vis, thank you for your input.




#11
10/08/2009 (1:49 pm)
6) I'm guessing that you haven't really set "%playerPosition" and "%cameraPosition" to anything. The engine will happily create the variable for you on their first use.

I did set them up is the in the onAddBehavior, this is one I am not sure of. If I set it in the right function and made the right call which was: %playerPosition = %this.owner.getPosition(); & %currentCameraPosition = %this.owner.getCurrentCameraPosition();. If you could tell me where these should go for future notice, I will certainly not ask again.


8) Even if you are setting the positions, they will be vectors. When you add "1 10" to "2 20", you'll get "3".


wouldn't it be 3 30?




10) Assuming you are in an "onLimit" function, the cases for the "%limit" variable will be telling you that you've already hit the edge.

Ok, so in onLimit, I would not to create an if statement. as in if these vectors add up and player is determined to be outside or on worldLimit... That is not right, since it already is on limit. If so, then I just tell it what to when onLimit, as oppose to calculate if it is.




#12
10/08/2009 (2:47 pm)
Quote:
but ces la vis

its been a while since last time i spoke french (like 10 years?)... but if im not mistaken, its C'est la Vie ...


Quote:
thank you for your input.

W/E.


Quote:
I did set them up is the in the onAddBehavior, this is one I am not sure of. If I set it in the right function and made the right call which was: %playerPosition = %this.owner.getPosition(); & %currentCameraPosition = %this.owner.getCurrentCameraPosition();. If you could tell me where these should go for future notice, I will certainly not ask again.

i hate repeating myself... but it seems like theres no other way:
you designed the behaviour, you SHOULD know how it works, and where to initialize the parameters, variables and stuff... so, if you wanna take my advice (i know you wont) try to understand YOUR OWN CODE (if its true you're actually writting it), try it, debug it, and make it better.

we can tell what you're trying to achieve by reading the snippets you post here and there, but we still dont have the whole picture (not like we need to, its not our project anyway), so telling you where to initialize parameters and stuff its kinda outta scope.

also, if you cant write a behaviour properly, the go the old school way, make regular functions (classes, methods and all that) and use them as is, and see what happens. its not that hard... unless you dont even try to do stuff on your own, and pretend for someone else to do it for you (while pretending you're learning in the process, which i know you're not).



Quote:
Ok, so in onLimit, I would not to create an if statement. as in if these vectors add up and player is determined to be outside or on worldLimit... That is not right, since it already is on limit. If so, then I just tell it what to when onLimit, as oppose to calculate if it is.

again, it all depends on what you wanna achieve with the code... if you need an "if" statement or not, depends on how you wanna process the info given to you by the engine, and what to do with it.
#13
10/08/2009 (2:48 pm)
That program is EXACTLY like being in a classroom with a computer. It gives you things to type into the console, explains why each part is there, all in a conversational manner. You can then continue playing with the simulation until you're ready to move on. I did the demo to see what it is like, and I'm pretty impressed with the hands-on, classroom-like experience.

As for #6, if you don't understand local variables, I don't know if I can help you much. I'm certain now that you have no background in actual programming.

As for #8, why would you second guess me about this without trying it first? I feel insulted.

As for #10, you need a complete redesign before this will work. You could either reset the player's clamp region constantly (which I fear would have problems), or you need to check the player's position against the camera's constantly (the approach I'd take).

What's most frustrating to me right now is that I asked you to research a few functions and wanted you to describe them fully to me with maybe an example. If you'd done that successfully, you'd already be done with this. Instead, you blew if off as unnecessary.

I've been coding 100 times longer than you have. This community has probably been coding 1,000,000 times longer than you have. I have supportive family, friends, and teachers. When they give me advice, even advice I don't agree with, I think about it for a long time. You've gotten advice on this forum that I would have killed to have when I was young. You then dismiss it. And by dismissing it, you dismiss a vast amount of experience that is trying to be passed onto you.

You may mean no disrespect, but your actions are disrespectful.
#14
10/08/2009 (2:51 pm)
ok I am getting sick of you guys harping on me. Instead perhaps you could answer me this.



I built this. I studied it and while in my mind, I know what I want it to do, it does not.
Is there any chance you could enlighten me on how this actually is supposed to work, or why this gives errors.

thank you.


function Spacer300WorldLimits::onUpdate(%this)
{
	%worldLimit = sceneWindow2D.getCurrentCameraPosition();
	
	%this.owner.setWorldLimit(bounce, getWord(%worldLimit, 0), getWord(%worldLImit, 1), getWord(%worldLimit, 2), getWord(%worldLimit, 3);
	 
}
#15
10/08/2009 (2:53 pm)
Quote:
What's most frustrating to me right now is that I asked you to research a few functions and wanted you to describe them fully to me with maybe an example. If you'd done that successfully, you'd already be done with this. Instead, you blew if off as unnecessary.

I've been coding 100 times longer than you have. This community has probably been coding 1,000,000 times longer than you have. I have supportive family, friends, and teachers. When they give me advice, even advice I don't agree with, I think about it for a long time. You've gotten advice on this forum that I would have killed to have when I was young. You then dismiss it. And by dismissing it, you dismiss a vast amount of experience that is trying to be passed onto you.

You may mean no disrespect, but your actions are disrespectful.

i guess now you feel what i felt back then huh?... sometimes trying to pass info onto this guy its like hitting a wall head on... and getting chewed in the process.
#16
10/08/2009 (2:53 pm)
ps William, I am not sure why you feel the need to say I am being disrespectful. Please refrain, I thought I was being good with you by answering each thing you pointed out. Anyhow, guys... please no more issues. I simply want to ask questions. Please answer if you can.

Thanks
Ren
#17
10/08/2009 (3:00 pm)
Quote:
ok I am getting sick of you guys harping on me. Instead perhaps you could answer me this.

I built this. I studied it and while in my mind, I know what I want it to do, it does not.
Is there any chance you could enlighten me on how this actually is supposed to work, or why this gives errors.

thank you.

not a chance i will "enlighten" you... its been said many times, go read the docs, try to understand them, how stuff works and shit, and then try to apply it into a practical thing.

this line
%worldLimit = sceneWindow2D.getCurrentCameraPosition();
makes no sense to me... if you wanna obtain the world limit of something, why store the current camera position? (yes, thats what you're doing there).

and the next line... well, i could tell you whats wrong there, but its not in my best interest to do so, so maybe someone else will.

again... take it as you will, but learning the basics (and i really mean it, LEARN THE BASICS) wont hurt you, and will help you in the long run... i know, i did, and now when i ask something in the forums, its actually something worthwhile, usefull, and probably not really (well) documented.

#18
10/08/2009 (3:15 pm)
Thanks Eric(for short),
I will look at that in a bit, right now tho I am on this.

startCameraMove(%time)
It, "Quote", Performs a camera move as specified in a call to setTargetCameraArea/Position/Zoom.

There are 3 potential things this method does, area, position and zoom related to targetCamera. My question is, if I wanted to use this function and 3 of its functions area, zoom and position, would I need to
A. Would I need to set:
%zoom = t2dsceneWindow.setTargetCamera();
%area = t2dSceneWindow.setTargetCamera();

Actually right now I have no B.

Is this correct in programming Torque?

#19
10/08/2009 (3:18 pm)
ps. just read your tip. thanks! will do.


;--|||L1.
#20
10/08/2009 (3:18 pm)
none of the above are correct.

look for the camera methods in the docs, study them and give them a try... playing with the camera methods its pretty cool, and gives visual results inmediately...
Page «Previous 1 2 3 Last »