Better Understanding %WorldLimit and %onUpdate Together
by rennie moffat · in Torque Game Builder · 10/22/2009 (7: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
a beginner with some good ideas for games. Looking to learn lots.
#82
"The logic is taking over, the logic is taking over"
Robot gone mad.
10/27/2009 (12:46 am)
if you notice, I think I have trimmed down on the amount of words I use. "The logic is taking over, the logic is taking over"
Robot gone mad.
#83
I just listed 5 posts that had examples of the line you were trying to debug. I thought as soon as you saw those that you'd know exactly what was wrong. I guess you're not looking for help, but just the answer.
For the record, there were 3 errors in just this one line.
10/27/2009 (1:15 am)
Nowhere in my post did I say your question was inappropriate. You must not read extra words into my posts.I just listed 5 posts that had examples of the line you were trying to debug. I thought as soon as you saw those that you'd know exactly what was wrong. I guess you're not looking for help, but just the answer.
For the record, there were 3 errors in just this one line.
moveMap.unBindObj(getWord(%this.Keybind, 0), getWord(%this.Keybind, 1), %this);
#84
Rennie here, is quite the opposite and I admire his ability to stay the course in the face of much nonsense and confrontation, especially being new to the game. Rennie, your determination is admirable! If you would apply that same level of determination to understanding the fundamentals of programming, you would be on the fast track to getting your game complete!
With that being said, I think I was actually the first person to stop helping Rennie (an admission of my hypocrisy) and I will continue that until I see him regroup his efforts and demonstrate an understanding of the basic building blocks. It's just a waste of both our time until then.
Don't give up Rennie!
Ted/William... You guys are saints - If you ever want to put a fraction of the kind of effort you put into helping Rennie into helping me make a game, I would be eternally grateful!
Sorry to derail your thread Rennie... but you already did that a few times, so I figured I'd throw it out there.
10/27/2009 (1:33 am)
When I first started with TGB, a little over 2 years ago now, I would have been thrilled to get any one of these responses to my questions but I was timid and worried about upsetting the TGB gods. :)Rennie here, is quite the opposite and I admire his ability to stay the course in the face of much nonsense and confrontation, especially being new to the game. Rennie, your determination is admirable! If you would apply that same level of determination to understanding the fundamentals of programming, you would be on the fast track to getting your game complete!
With that being said, I think I was actually the first person to stop helping Rennie (an admission of my hypocrisy) and I will continue that until I see him regroup his efforts and demonstrate an understanding of the basic building blocks. It's just a waste of both our time until then.
Don't give up Rennie!
Ted/William... You guys are saints - If you ever want to put a fraction of the kind of effort you put into helping Rennie into helping me make a game, I would be eternally grateful!
Sorry to derail your thread Rennie... but you already did that a few times, so I figured I'd throw it out there.
#85
10/27/2009 (1:44 am)
You wouldn't want a fraction of my help. It only takes but a minute or two, here and there, to respond. It's been a good break from the mountain of chores I have today.
#86
Emails are a touchy thing I Have found (recent esp). IF you write something out of a spur of the moment haste, think nothing of it, if someone else rads it, they might not get or be near the emotion the writer was when he wrote it so emotion gets in the way of facts. that is something I think is important we emphasize here at the jedi council,\ of tgb'ers.
Again I love what is being done here and the help I am receiving.
I do have a question tho. To post a whole behavior as I did, I in hindsight am now thinking is a bit of a daunting task to ask, but it wasn't what I was thinking. I was thinking or hoping, my mistakes are very general, I am not declaring something correctly or something, beyond basic syntax. It was my hope I could have a pro or someone in the know point me in the right direction with a common error I was committing, that is all.
And Patrick, I hear you buddy thanks!
10/27/2009 (1:52 am)
Cool I love you guys and no where do I want to "blow this all up".Emails are a touchy thing I Have found (recent esp). IF you write something out of a spur of the moment haste, think nothing of it, if someone else rads it, they might not get or be near the emotion the writer was when he wrote it so emotion gets in the way of facts. that is something I think is important we emphasize here at the jedi council,\ of tgb'ers.
Again I love what is being done here and the help I am receiving.
I do have a question tho. To post a whole behavior as I did, I in hindsight am now thinking is a bit of a daunting task to ask, but it wasn't what I was thinking. I was thinking or hoping, my mistakes are very general, I am not declaring something correctly or something, beyond basic syntax. It was my hope I could have a pro or someone in the know point me in the right direction with a common error I was committing, that is all.
And Patrick, I hear you buddy thanks!
#87
I am sorry I did not get what you "thought" I thought you were putting up a complaint of "crazy old Ren's multiple posts of something stupid". I did not realise. I will look over them, but if you could tell me what they are it may be quicker for me to move on. Am checking tho, thanks.
10/27/2009 (1:55 am)
@William. I am sorry I did not get what you "thought" I thought you were putting up a complaint of "crazy old Ren's multiple posts of something stupid". I did not realise. I will look over them, but if you could tell me what they are it may be quicker for me to move on. Am checking tho, thanks.
moveMap.unBindObj(getWord(%this.Keybind, 0), getWord(%this.Keybind, 1), %this); //this line has 3 errors. What are they?
#88
10/27/2009 (2:04 am)
This is my line side by side a line from functioning line.moveMap.unbindObj(getWord(%this.shootKey, 0), getWord(%this.shootKey, 1) %this); //my code.
moveMap.unbindObj(getWord(%this.fireKey, 0), getWord(%this.fireKey, 1), %this); //functioning
#89
10/27/2009 (2:07 am)
I just noticed one comma missing after (%this,shootKey, 1),
#90
You say you have been working with Torque for a couple of years. How far along are you? Can you program a basic game with relative ease? ( I am looking to get stuff onto the iPhone. So my games are relatively small)
10/27/2009 (2:24 am)
@ Patrick.You say you have been working with Torque for a couple of years. How far along are you? Can you program a basic game with relative ease? ( I am looking to get stuff onto the iPhone. So my games are relatively small)
#91
I have gotten my behavior to work, except when I shoot(hot space bar) only one projectile comes out. If I release and rehit the space bar when a projectile is present on screen, the one created 1st disappears and the new projectile is shown. I am not sure why this occurs.
Please explain if you can.
10/27/2009 (2:34 am)
I hope this is a valid question. I have gotten my behavior to work, except when I shoot(hot space bar) only one projectile comes out. If I release and rehit the space bar when a projectile is present on screen, the one created 1st disappears and the new projectile is shown. I am not sure why this occurs.
function Spacer3000ShootsBehavior::SpacerShoot(%this, %val)
{
if(!isObject(%this.SpacerProjectile01))
return;
$SpacerProjectile01Velocity = -40;
%SpacerProjectile01 = %this.SpacerProjectile01.cloneWithBehviors();
%this.SpacerProjectile01.setPosition(%this.owner.position);
%this.SpacerProjectile01.setLinearVelocityY($SpacerProjectile01Velocity);
if(!isEventPending(%this.shootSchedule))
%this.shootSchedule = %this.schedule(%this.shootRate * 1000, "SpacerShoot", %this);
}Please explain if you can.
#92
The reason that only one projectile is there is because you are using your "master" projectile to do the firing instead of the cloned projectile.
So instead of "%this.SpacerProjectile01.setPosition(%this.owner.position);", you should be using "%SpacerProjectile01.setPosition(%this.owner.position);".
10/27/2009 (3:15 am)
That single line I gave you _was_ the fix to your problem. I was just saying that I had to make 3 changes to the original line to get to that one.The reason that only one projectile is there is because you are using your "master" projectile to do the firing instead of the cloned projectile.
So instead of "%this.SpacerProjectile01.setPosition(%this.owner.position);", you should be using "%SpacerProjectile01.setPosition(%this.owner.position);".
#93
so by using %SpacerProjectile01 over %this.SpacerProjectile01 I am calling the "master" projectile. So having said that their can only be "one master" but infinite clones.
If that is right, Awesome?
10/27/2009 (3:47 am)
Hm ok, so by using %SpacerProjectile01 over %this.SpacerProjectile01 I am calling the "master" projectile. So having said that their can only be "one master" but infinite clones.
If that is right, Awesome?
#94
Would you be able to shed light on why this won't work?
Thanks,
Ren
10/27/2009 (3:51 am)
I made that one adjustment and nothing fired, so I made the following adjustemts and still nothing.Would you be able to shed light on why this won't work?
Thanks,
Ren
function Spacer3000ShootsBehavior::SpacerShoot(%this, %val)
{
if(!isObject(%SpacerProjectile01))
return;
$SpacerProjectile01Velocity = -40;
%SpacerProjectile01 = %this.SpacerProjectile01.cloneWithBehviors();
%SpacerProjectile01.setPosition(%this.owner.position);
%SpacerProjectile01.setLinearVelocityY($SpacerProjectile01Velocity);
if(!isEventPending(%this.shootSchedule))
%this.shootSchedule = %this.schedule(%this.shootRate * 1000, "SpacerShoot", %this);
}
#95
10/27/2009 (4:02 am)
You need to leave the if-statement at the top the same as it was before. Your local variable "%SpacerProjectile01" doesn't exist until you do your clone. What this function wants to know is "Does the master object exist?" If it does, then it goes ahead and clones the master object. If it doesn't, then it just skips doing anything in this function.
#96
You mean leave inside the if statement %this.Projectile?
Right I see what you mean by it does not exist until the .cloneWithBehaviors is declared.
Thanks.
10/27/2009 (4:19 am)
So when you say "leave the if statemtn at the top.You mean leave inside the if statement %this.Projectile?
Right I see what you mean by it does not exist until the .cloneWithBehaviors is declared.
Thanks.
#97
10/27/2009 (10:50 am)
Yep... the first if-statement should be checking to see if the master object exists.
#98
As such, I have messed around a bit with this function and it does not work anymore, but I can not see why.
Can you explain to me why this function is not working, assuming the glitch is inside this function.
10/27/2009 (11:13 am)
hm ok I am beginning to see how and why things work. Why and when I should declare something. The logic of programing is beginning to make sense more, like I was NEO in the last scene of the first movie when he begins to "believe" and everything looks like green numbers? Well, not that good but beginning.As such, I have messed around a bit with this function and it does not work anymore, but I can not see why.
Can you explain to me why this function is not working, assuming the glitch is inside this function.
function Spacer3000ShootsBehavior::SpacerShoot(%this, %val)
{
if (%val == 0)
{
cancel(%this.shootSchedule);
return;
}
if(!isObject(%this.SpacerProjectile01))
return;
%SpacerProjectile01 = %this.SpacerProjectile01.cloneWithBehviors();
%SpacerProjectile01.setPosition(%this.owner.position);
%SpacerProjectile01.setLinearVelocityY($SpacerProjectile01Velocity);
$SpacerProjectile01Velocity = -40;
if(!isEventPending(%this.shootSchedule))
%this.shootSchedule = %this.schedule(%this.shootRate * 1000, "SpacerShoot", %this);
}
#99
10/27/2009 (5:45 pm)
@Patrick: I agree that he shouldn't give up trying to learn how to script/code, but what I'm seeing in this thread is something different entirely, and that's why I will not help him...
#100
Like you said though, he shouldn't give up - he needs to refocus his efforts on the proper area for his current skill level.
@Rennie, regarding your question about my ability to program a simple game with relative ease. I guess the answer is no. I still fumble through code, omit semicolons, waste time writing functions for things that are already in the engine, make typos, try to use local variables that are out of scope, get in over my head, get completely and irrecoverably stuck, etc, etc, etc. I can't just whip a simple game together but I can enjoy the time I spend writing code in TGB because I have an understanding of the fundamentals and can get the ideas I have in my head into a game.
It's never a quick process for me. To me, software development is just a string of problems to be solved. No matter if you're making a game or a piece of accounting software; the end result being fun doesn't make the creation process also fun. I love writing software of almost any kind, so its an added bonus to be able to make something fun in the end.
Sorry if I sound preachy, but the fact is I respect the people that are trying to help you and I've read this entire thread (sort of shamefully) and I think they deserve to at least have their input be honestly addressed when they take the time to help.
I've also recommended it to you before, but I created a tutorial that's on TDN that works with the current version of TGB and is aimed at people in your position. I think it would help quite a bit. You can access it under the "Stacker Tutorial" section here.
10/27/2009 (6:26 pm)
@Ted, you don't have to explain yourself to me. I agree that Rennie has demonstrated unwillingness to learn the essentials, pretty much ignored helpful suggestions and obviously didn't try some of the examples provided to him. (Posts 67 - 72: 6 posts in 25 minutes... come on Rennie, you obviously didn't labor over it too much). In fact, it took a lot less than the above to get me to stop providing input.Like you said though, he shouldn't give up - he needs to refocus his efforts on the proper area for his current skill level.
@Rennie, regarding your question about my ability to program a simple game with relative ease. I guess the answer is no. I still fumble through code, omit semicolons, waste time writing functions for things that are already in the engine, make typos, try to use local variables that are out of scope, get in over my head, get completely and irrecoverably stuck, etc, etc, etc. I can't just whip a simple game together but I can enjoy the time I spend writing code in TGB because I have an understanding of the fundamentals and can get the ideas I have in my head into a game.
It's never a quick process for me. To me, software development is just a string of problems to be solved. No matter if you're making a game or a piece of accounting software; the end result being fun doesn't make the creation process also fun. I love writing software of almost any kind, so its an added bonus to be able to make something fun in the end.
Sorry if I sound preachy, but the fact is I respect the people that are trying to help you and I've read this entire thread (sort of shamefully) and I think they deserve to at least have their input be honestly addressed when they take the time to help.
I've also recommended it to you before, but I created a tutorial that's on TDN that works with the current version of TGB and is aimed at people in your position. I think it would help quite a bit. You can access it under the "Stacker Tutorial" section here.
Torque Owner rennie moffat