declaring an object in a keyBound function
by rennie moffat · in Torque Game Builder · 10/08/2009 (4:56 pm) · 15 replies
if (!isObject(%this.projectile))
return;
If I have multiple projectiles, how would I declare them? With in this, I would imagine but would if(!Object(%projectile0), (%projectile1), (%projectile2)) but very unsure. The reason I ask is because this is from the fire or "shoots.cs" behavior. I was thinking it would be neat to add a fire function which shot 3 things in three angles. It is only one key tho, so, I need to have it shoot 3 things.
Perhaps a better question is PRECISELY, what does it mean?
return;
If I have multiple projectiles, how would I declare them? With in this, I would imagine but would if(!Object(%projectile0), (%projectile1), (%projectile2)) but very unsure. The reason I ask is because this is from the fire or "shoots.cs" behavior. I was thinking it would be neat to add a fire function which shot 3 things in three angles. It is only one key tho, so, I need to have it shoot 3 things.
Perhaps a better question is PRECISELY, what does it mean?
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.
#2
as my studying continues, I have looked at 3 different things. And found, that I have one question that needs to be answered for me currently and that is, can I, in a function say something like this?
10/08/2009 (6:02 pm)
Hi there, as my studying continues, I have looked at 3 different things. And found, that I have one question that needs to be answered for me currently and that is, can I, in a function say something like this?
function BigGun::fire()
{
%object = %this.objectA
%object = %this.objectB
%object = %this.objectC
///where by i would apply different angles to each A, B and C when fire is triggered, thus creating a 3 projectile shot?
}
#3
10/08/2009 (6:12 pm)
yes you can.. but you're just wasting some precious cpu cycles. why?... well, when you learn the basics, you'll notice it inmediately.
#4
Also, I did do this, it does, not work, perhaps you be better off answering this. It is the shoots.cs behavior, times three so to speak. I added in a projectile ABC and simply copy pasted the language which I understand and tweaked a bit. It loads but does not fire.
Perhaps you could answer this?
10/08/2009 (6:26 pm)
ok why is that? I am declaring something too much, code could be simplified?Also, I did do this, it does, not work, perhaps you be better off answering this. It is the shoots.cs behavior, times three so to speak. I added in a projectile ABC and simply copy pasted the language which I understand and tweaked a bit. It loads but does not fire.
Perhaps you could answer this?
#5
10/08/2009 (6:28 pm)
sorry forgot the codefunction ShootsBehavior::fire(%this, %val)
{
if (%val == 0)
{
cancel(%this.fireSchedule);
return;
}
if(!Object(%projectile))
return;
%projectileA = %this.projectileA.cloneWithBehaviors();
%projectileB = %this.projectileB.cloneWithBehaviors();
%projectileC = %this.projectileC.cloneWithBehaviors();
%projectileA.setPosition(%this.owner.position);
%projectileA.setRotation(%this.owner.rotation);
%projectileA.setLinearVelocityPolar(%this.owner.rotation + %this.owner.getVelocity() + %this.angle(30), %this.projectileSpeed);
%projectileB.setPosition(%this.owner.position);
%projectileB.setRotation(%this.owner.rotation);
%projectileB.setLinearVelocityPolar(%this.owner.rotation + %this.owner.getVelocity() + %this.angle(0), %this.projectileSpeed);
%projectileC.setPosition(%this.owner.position);
%projectileC.setRotation(%this.owner.rotation);
%projectileC.setLinearVelocityPolar(%this.owner.rotation + %this.owner.getVelocity() + %this.angle(-30), %this.projectileSpeed);
if (!isEventPending(%this.fireSchedule))
%this.fireSchedule = %this.schedule(%this.fireRate * 1000, "fire", 1);
}
#6
10/08/2009 (6:29 pm)
Again! Sorry I just noticed that it does lead back to the if(!Object(%projectile)). so again, how can I bring in more then one object if this declaration is necessary?
#7
1) arrays, vectors and matrixes for TGB.
2) SimSets on TGB
whenever you read, and understand all of the above, come back here.
10/08/2009 (6:38 pm)
i got some homework for you.1) arrays, vectors and matrixes for TGB.
2) SimSets on TGB
whenever you read, and understand all of the above, come back here.
#9
Vector, in is the difference between two points. In torque it can be used for a position, vector, or size.
A matrix is mathematical phenomenon that where by it maps out info pints on a grid.
A SImSet is a container for a sequence of unique objects.
A SimSet is an well ordered set of references to SimObjects. A SimObject can be a member of any number of SimSets and acts independently of any SimSet it is in.
The SimSet's member objects are stored initially in the order of insertion (add()), and can be removed (remove()), retrieved (getObject()), and queried (isMember()).
The SimSet can have all its members counted (getCount()), printed (listObjects()), and removed (clear()).
A member can be reordered via bringToFront() and pushToBack(), or re-ordered relative to another via reorderChild().
I have looked thru the code of a sim set but I found it a bit daunting. I trying to imagine when I would and how (eventually) use this.
10/08/2009 (6:54 pm)
Array data structure, an arrangement of items at equally spaced addresses in computer memory.Vector, in is the difference between two points. In torque it can be used for a position, vector, or size.
A matrix is mathematical phenomenon that where by it maps out info pints on a grid.
A SImSet is a container for a sequence of unique objects.
A SimSet is an well ordered set of references to SimObjects. A SimObject can be a member of any number of SimSets and acts independently of any SimSet it is in.
The SimSet's member objects are stored initially in the order of insertion (add()), and can be removed (remove()), retrieved (getObject()), and queried (isMember()).
The SimSet can have all its members counted (getCount()), printed (listObjects()), and removed (clear()).
A member can be reordered via bringToFront() and pushToBack(), or re-ordered relative to another via reorderChild().
I have looked thru the code of a sim set but I found it a bit daunting. I trying to imagine when I would and how (eventually) use this.
#10
10/08/2009 (7:07 pm)
you read it, yes... but i see no sign of understanding.
#11
that is why I am asking.
I understand the thing you asked me to understand, and I do, but looked at the code and could not quite grasp it. Can you give me an example of how one would use this in code, or more specifically how would one write it.
To me, at this point in time, this... is just gobbledee gook.
10/08/2009 (7:17 pm)
correct, that is why I am asking.
I understand the thing you asked me to understand, and I do, but looked at the code and could not quite grasp it. Can you give me an example of how one would use this in code, or more specifically how would one write it.
To me, at this point in time, this... is just gobbledee gook.
///i know here he calls a new SimSet which is Fruit, it is equal to $s. ///echo is a call and response, ask, $s.getCount() this will return the number of objects in the set. $s=new SimSet(Fruit); ==>echo($s.getCount()); ///I know what 0 is, but not why it is used here. 0 ///here he declares all simObjects linking them to global variables, tho I dont know what f0 would be. Can ///you answer that for me please? ==>$f0=new SimObject(Apple);$f1=new SimObject(Pear);$f2=new SimObject(Orange);$f3=new SimObject(Fig);$f4=new SimObject(Persimmon); ///unsure of what permission is. ///now he is adding the simObjects to the simSet $s. ==>$s.add($f0);$s.add($f1);$s.add($f2); ==>$s.add($f3);$s.add($f4); ///I am not sure why echos getCount here. ==>echo($s.getCount()); 5
#12
Think of this sample as an example. If you think about it if you just created a simset and you ran a function of get count you would assume that it is empty. The zero reflects the output you would get from the getCount() function.
$f0 is nothing more then what the author wanted to call his simobject. It is no different then $f1 or $anythingYouWant.
Again the last line is to show you if you got the count of the simset it would contain five now. Since you understand the code above it, getting the count should be selfexplanatory, the five is just the results.
Then finally it was persimmon not permission. The best thing I can tell you is that if something does not make sense, read it again. If it still does not make sense read it again but very slowly. In the above example the author is adding fruit to his fruit simset, that makes sense. Each simobject is a fruit including a persimmon.
Things to take away from this:
1. Echo sends statement to the console
2. Example codes are examples sometimes showing the results as if they were executed
3. If something does not make sense, read it again - but read it don't skim it
4. Variable names can be whatever you want them to be but should be something that makes sense - in this example f means fruit and the number the number of the item
5. Programmers use zero to start out counts and elements, usually because arrays start with zero along with binary code....etc.....
6. A simset is an well ordered set of references to SimObjects.
7. Simobject is well an object
Your question on how one would write the code, it is shown to you, just remove the 0 and 5. How one could use it, there are many ways to use a simset but it is best to look up TGB reference on simset for the answers.
I hope that helps you some.
Pubily
10/09/2009 (1:21 pm)
Rennie,Think of this sample as an example. If you think about it if you just created a simset and you ran a function of get count you would assume that it is empty. The zero reflects the output you would get from the getCount() function.
$f0 is nothing more then what the author wanted to call his simobject. It is no different then $f1 or $anythingYouWant.
Again the last line is to show you if you got the count of the simset it would contain five now. Since you understand the code above it, getting the count should be selfexplanatory, the five is just the results.
Then finally it was persimmon not permission. The best thing I can tell you is that if something does not make sense, read it again. If it still does not make sense read it again but very slowly. In the above example the author is adding fruit to his fruit simset, that makes sense. Each simobject is a fruit including a persimmon.
Things to take away from this:
1. Echo sends statement to the console
2. Example codes are examples sometimes showing the results as if they were executed
3. If something does not make sense, read it again - but read it don't skim it
4. Variable names can be whatever you want them to be but should be something that makes sense - in this example f means fruit and the number the number of the item
5. Programmers use zero to start out counts and elements, usually because arrays start with zero along with binary code....etc.....
6. A simset is an well ordered set of references to SimObjects.
7. Simobject is well an object
Your question on how one would write the code, it is shown to you, just remove the 0 and 5. How one could use it, there are many ways to use a simset but it is best to look up TGB reference on simset for the answers.
I hope that helps you some.
Pubily
#13
oh,
i seezzle.
Oh I see, what would a Simset be tho? A group of enemies? A group of heros?
What would its most, or common application be?
So is the echo used by programmers to simply see if things are running right? Just send out a request for the status of something?
DAmn Dyslexia, see, that is what I do wrong, in learning. I read things thinking they say one thing when they mean something else. I must pay more attention to what exactly I am reading.
Thanks.
PS.
Ok so I have just read it all over and you offer great advice, the above tho is my celebratory response, this is after reading what I took away with it. Either way, much appreciated, muchos gracias.
Ren
10/09/2009 (3:14 pm)
Quote:
The zero reflects the output you would get from the getCount() function.
oh,
i seezzle.
Quote:
$f0 is nothing more then what the author wanted to call his simobject. It is no different then $f1 or $anythingYouWant.
Oh I see, what would a Simset be tho? A group of enemies? A group of heros?
What would its most, or common application be?
Quote:
Again the last line is to show you if you got the count of the simset it would contain five now. Since you understand the code above it, getting the count should be selfexplanatory, the five is just the results.
So is the echo used by programmers to simply see if things are running right? Just send out a request for the status of something?
Quote:
Then finally it was persimmon not permission.
DAmn Dyslexia, see, that is what I do wrong, in learning. I read things thinking they say one thing when they mean something else. I must pay more attention to what exactly I am reading.
Thanks.
PS.
Ok so I have just read it all over and you offer great advice, the above tho is my celebratory response, this is after reading what I took away with it. Either way, much appreciated, muchos gracias.
Ren
#14
10/09/2009 (3:17 pm)
ps. A good question for me is, how would you most use the console type editor?
#15
I think one would use it to check code and make sure everything was alright. You know, send an echo call to see if everything is fully loaded or if you know, "the circuits are working".
Would this be a decent comparison?
10/09/2009 (6:12 pm)
Perhaps I was a bit light in my description of what I was going after. BUt a better description, and how I think this could work is.. that I was wondering how one uses it on a day to day basis.I think one would use it to check code and make sure everything was alright. You know, send an echo call to see if everything is fully loaded or if you know, "the circuits are working".
Would this be a decent comparison?
Torque Owner rennie moffat
Renman3000
it is for a three shooter but not for TGB it goes for something else, TGE I believe, so obviously in 3D. So some different things that re guiding it, this ins one that I would like to use, but I know the code is obviously.
But in it, there is only one projectile called, originally, the other are two "spreads" set to go out on different angles to the original. So.. I am wondering how I should/could best translate this into TGB behaviors.
Obviously, There much difference the code still escapes me. For instance but over all, he is choosing one object and having spread in 3 directions, seems simple enough, but I still cant get how he has made one object fire three times in TGB?
// Get the weapons projectile spread and ensure it is never 0 // (we need some spread direction even if it is extremely tiny) %spread = %this.projectileSpread; %spread = %spread $= "" ? 0.001 : %spread; %spread = %spread <= 0 ? 0.001 : %spread; // Determine if we are using a shotgun class weapon or not // If we are using a shotgun, set the number of projectiles we are going to fire to 12 %shellcount = 1; if(%projectile.isShotGun) %shellcount = 12; // Create each projectile and send it on its way for(%shell=0; %shell<%shellcount; %shell++) { // Get the muzzle vector. This is the dead straight aiming point of the gun %vector = %obj.getMuzzleVector(%slot); // Get our players velocity. We must ensure that the players velocity is added // onto the projectile %objectVelocity = %obj.getVelocity(); // Determine scaled projectile vector. This is still in a straight line as // per the default example %vector1 = VectorScale(%vector, %projectile.muzzleVelocity); %vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor); %velocity = VectorAdd(%vector1,%vector2);