[Question] "Dynamic" datablock creation?
by St. · in Torque Game Engine Advanced · 04/18/2009 (8:07 am) · 8 replies
My question is really stupid, but I was hoping that maybe it makes some sense in Torquescript. :)
I need to create many datablocks of a very similar content (lets not get into more details) with just a few slight differences. I'm not really looking forward to copy-pasting that stuff, so the question is if it's possible to create datablocks with "variable names". For example like this:
I've tried doing that in several ways (including the one I mentioned) without success.
Is it really that hopeless?
I need to create many datablocks of a very similar content (lets not get into more details) with just a few slight differences. I'm not really looking forward to copy-pasting that stuff, so the question is if it's possible to create datablocks with "variable names". For example like this:
for(%i = 0; %i < 100; %i++)
datablock ShapeBaseImageData("DatablockName" @ %i)
{
...
}I've tried doing that in several ways (including the one I mentioned) without success.
Is it really that hopeless?
About the author
#3
Thanks, anyway, I'll try to use eval() too.
04/18/2009 (11:03 am)
Hmm... weird. Maybe I just made a stupid typo somewhere then...Thanks, anyway, I'll try to use eval() too.
#4
On the other hand, if you're creating that many datablocks, you might be misusing the datablocks. The point of the datablock is to minimize the amount of data sent across the network by sending a datablock once as a description that may be used in bulk on the client.
If there's only a small difference in a large number of datablocks you may be better of having the differences become part of the actual GameBase objects, so that you don't have to send 100 entire datablocks across the network in order to accomodate a few bytes of variation in each one.
Of course you may have a good, valid reason for doing it this way, but just some food for thought.
04/18/2009 (2:28 pm)
Yes, you'll have to use eval.On the other hand, if you're creating that many datablocks, you might be misusing the datablocks. The point of the datablock is to minimize the amount of data sent across the network by sending a datablock once as a description that may be used in bulk on the client.
If there's only a small difference in a large number of datablocks you may be better of having the differences become part of the actual GameBase objects, so that you don't have to send 100 entire datablocks across the network in order to accomodate a few bytes of variation in each one.
Of course you may have a good, valid reason for doing it this way, but just some food for thought.
#5
04/20/2009 (7:19 am)
Eval works perfectly for this. For many of my projects I use a small set of "datablock builder" functions which use eval() to create datablocks out from information on CSV spreadsheets, which are much easier to deal with for certain things.
#6
I'm not sure exactly what you are doing. But it may be another option.
04/20/2009 (3:05 pm)
Perhaps you could use Datablock Inheritance?I'm not sure exactly what you are doing. But it may be another option.
#7
The validity of the comment "you might be misusing the datablocks" is pretty high too. Wanting to create that many datablocks with really minimal changes between them just makes me wonder what you are trying to achieve.
I know you say "lets not get into more details", but we may be able to assist you further (and in a better way) if you can give *some* further details.
04/20/2009 (3:27 pm)
The above comments are correct in my opinion.The validity of the comment "you might be misusing the datablocks" is pretty high too. Wanting to create that many datablocks with really minimal changes between them just makes me wonder what you are trying to achieve.
I know you say "lets not get into more details", but we may be able to assist you further (and in a better way) if you can give *some* further details.
#8
In the first post I've just tried to "simplify" my goal to get a more precise answer. In fact I am developing database support and I was hoping to combine query results with datablocks for... well, obvious use. :)
In this particular case I was trying to load a table of items (differing only in models and a few characteristics) for the future use in the game.
It's possible that I am misusing datablocks, but I haven't come up with a better solution for that yet.
I'm still learning. :)
Added: I've just found a great solution that illustrates my needs perfectly ( http://www.garagegames.com/community/resources/view/7886 ). I guess my question is automatically answered now.
04/25/2009 (12:09 pm)
Thanks for all your replies.In the first post I've just tried to "simplify" my goal to get a more precise answer. In fact I am developing database support and I was hoping to combine query results with datablocks for... well, obvious use. :)
In this particular case I was trying to load a table of items (differing only in models and a few characteristics) for the future use in the game.
It's possible that I am misusing datablocks, but I haven't come up with a better solution for that yet.
I'm still learning. :)
Added: I've just found a great solution that illustrates my needs perfectly ( http://www.garagegames.com/community/resources/view/7886 ). I guess my question is automatically answered now.
Torque Owner Stefan Lundmark