Game Development Community

Help needed accessing objects of a datablock

by John \"Johnny Action\" Aho · in Torque Game Engine · 04/01/2004 (2:25 pm) · 4 replies

I'm having problems in torquescript making changes to an individual object. For example setting forward motion to zero or disabling a vehicle. I can make it happen but I end up stopping all trucks, not just one truck.

Or say I want to create a big rubber bouncy wall, and reverse the motion of objects that hit it. Instead of changing all player's velocities, I would just want to change the velocity of the object that collided with it, not all datablocks that are declared from that object.

Thanks in advance,
John Aho

#1
04/01/2004 (2:53 pm)
Hi John,

Datablocks can be a bit tricky to learn. I just went through a similiar process recently. You'll have to change the way you think of scripting a little bit. A lot of the GG community helped me, so let me see if I can briefly summarize in one paragraph something useful. :)

All objects of the same type are created from the same datablock, ie: all players come from the PlayerBody datablock. I think you got that part. The trick is that they are *always* tied to that datablock, as in when you reference an instance object's datablock, you are actually referencing the datablock itself. So, if you change a datablock value in-game, you will change that value for all objects created by that datablock, since all of their velocity values or speed values are tied directly to one datablock. Thus, your problem of having all cars stop by changing the datablock velocity.

To change a value set by a datablock during a game dynamically, you need to do some C++ coding to setup how that value is used in the engine. In terms of velocity and the bouncy ball, there may be ways of doing it in script, but I'm not totally sure how to. Here's a thread where I basically had the same problem you did, and the community explained it to me, although a took me a bit to understand it. :) There's a couple good resource posted their by others about how datablocks work.
#2
04/01/2004 (2:54 pm)
Do a search for "datablock" on the GG site, under forums, that will give you tons of good info as well. Also, you can google search this site like this:

accessing datablocks site:www.garagegames.com
#3
04/01/2004 (3:10 pm)
Yup, you cant do it with the datablocks.

Datablocks are kinda like the variables that get passed into a constructor. If you need specific instances of a class to have different properties you have to code accessor script methods. Take a look at the "dynamic and individualized gravity" resource for tips on how to go about doing this. I also belive that changing datablocks at run-time is a big no-no.

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1723

-s
#4
04/01/2004 (3:17 pm)
Sweet, Thanks for the tips guys. That's exactly the information I was looking for.

I guess I'm just used to classes, and objects of those classes in c++.
Now that I see that code example I'm all good.