A better way - Datablock[array]?
by Davis Ray Sickmon, Jr · in Torque Game Engine · 04/22/2004 (8:37 pm) · 12 replies
In Trajectory Zone, I've got like 15 types of ammo, which means 15 different datablocks for each facet of the ammo. I like extensability. I'd love to do weapons just like I do tweaks and gametypes, and just have me a directory that the engine loops through and loads all the ammo types. The problem is - I've yet to see a good way to load them in a somewhat abstract fashion. What I mean is, it would be great to simply do:
datablock ProjectileData(CrossbowProjectile[$loadedAmmoTypes])
{ ....instead ofdatablock ProjectileData(CrossbowProjectile1)
{ ....And just $loadedAmmoTypes++ between loading each file. Later, if I need to address a datablock, it's just CrossbowProjectile[%ammoNumber]. Of course, the engine will have nothing to with such a style of doing things. I've experemented a bit, and finally just walked away from the idea. But I thought I'd ask - am I missing something obvious, like an elegant way of handling an arbitrary number of ammo types (or datablocks in general) in an array or similar fashion? It's not a highly important item, but, would be rather cool to be able to do.About the author
#2
04/23/2004 (7:46 am)
You can. In the TSE demo we have some neat helper functions that basically emit datablocks on the fly like that.
#3
04/23/2004 (4:32 pm)
Any examples??
#5
When will the TSE demo be ready? :)
04/24/2004 (12:13 am)
Quote:You can. In the TSE demo we have some neat helper functions that basically emit datablocks on the fly like that.
When will the TSE demo be ready? :)
#6
(Careful - Ben's probably heard that question enough times already that he's building a hit list to be executed at the next IGC ;-)
04/24/2004 (3:07 am)
You sure that TSE's scripting engine didn't just a slight tweak to get that working?datablock ProjectileData("CrossbowProjectile" @ $loadedAmmoTypes)
{.... results in a synatx error. (Just to make sure it wasn't a typo, I removed the spaces between " @ $ - still errored.) Same goes for building up the string first like:%loadingProjectile = "CrossbowProjectile" @ $loadedAmmoTypes;
datablock ProjectileData(%loadingProjectile)
{....(Careful - Ben's probably heard that question enough times already that he's building a hit list to be executed at the next IGC ;-)
#7
04/24/2004 (9:50 am)
Try this:%foo = "datablock ProjectileData(CrossBowProjectile" @ $loadedAmmoTypes @ ") { };";
exec(%foo);
#8
04/24/2004 (5:35 pm)
Ben's method should work fine. I did something simliar in the Show Tool.
#9
So anyway - It doesn't harf on the datablock at all, but suddenly it spews out:
04/24/2004 (11:44 pm)
I messed around with this a bit, and came up with an interesting problem - here's the example code (note: It's not even dynamic yet, I just used an existing weapon to play with directly, then make it dynamic later):%loadWeapon = "datablock ProjectileData(CrossbowProjectile6) { projectileShapeName = \"" @
"~/data/shapes/ammo/MIRV/projectile.dts\"" @
"; directDamage = 50; radiusDamage = 25;" @
" damageRadius = 4; explosion = BomberExplosion;" @
" particleEmitter = BomberBoltEmitter;" @
" landscapeSmoke = BomberLandscapeEmitter;" @
" muzzleVelocity = ShotPowerSlider.value;" @
" velInheritFactor = 1.0; armingDelay = 0;" @
" lifetime = 60000; fadeDelay = 5000;" @
" bounceElasticity = 0.7; bounceFriction = 0;" @
" isBallistic = true; gravityMod = 0.7;" @
" hasLight = true; lightRadius = 20;" @
" lightColor = \"1.0 1.0 0\"; };";
eval(%loadWeapon);(Note the use of EVAL, not EXEC - the latter loads a file and executes it, the former is used to evaluate a string as code. Ben typo'ed it, but I thought I'd explain that one real quick just in case someone trys this and can't figure out why it doesn't work :-)So anyway - It doesn't harf on the datablock at all, but suddenly it spews out:
<input> (0): Preload failed for CrossbowProjectile6: ProjectileData::load Couldn't load shape "~~/data/shapes/ammo/MIRV/projectile.dts"Eh? Works just fine when not dynamically loaded. Am I miss handling the quotes using \", or did I miss something else obvious :-)
#10
If so its adding an extra tilde at the beginning.
04/25/2004 (1:05 am)
Hmm interesting. Is that a direct paste of the error?If so its adding an extra tilde at the beginning.
#11
If the the /data folder and the script that loads the dynamic information are under the same MOD path (ie. starter.fps) you can use expandFilename("~/path/to/file.fil");
04/25/2004 (1:34 am)
You can only use the relative paths in a file you exec().If the the /data folder and the script that loads the dynamic information are under the same MOD path (ie. starter.fps) you can use expandFilename("~/path/to/file.fil");
%loadWeapon = "datablock ProjectileData(CrossbowProjectile6) { projectileShapeName =
\"" @
expandFilename("~/data/shapes/ammo/MIRV/projectile.dts") @
"\"; directDamage = 50; radiusDamage = 25;" @
" damageRadius = 4; explosion = BomberExplosion;"
@
" particleEmitter = BomberBoltEmitter;" @
" landscapeSmoke = BomberLandscapeEmitter;" @
" muzzleVelocity = ShotPowerSlider.value;" @
" velInheritFactor = 1.0; armingDelay = 0;" @
" lifetime = 60000; fadeDelay = 5000;" @
" bounceElasticity = 0.7; bounceFriction = 0;" @
" isBallistic = true; gravityMod = 0.7;" @
" hasLight = true; lightRadius = 20;" @
" lightColor = \"1.0 1.0 0\"; };";
eval(%loadWeapon);
#12
04/25/2004 (10:14 am)
LabRat to the rescue! ;)
Torque Owner Dylan Sale
datablock ProjectileData("CrossbowProjectile"@$loadedAmmoTypes)I have no idea if that is valid syntax, but its an idea...Then you could do
Again, dunno if that is valid...