Modified Weapon issue
by John "Mythic" Henry · in Torque Game Engine · 07/16/2005 (12:13 pm) · 5 replies
Alrighty, looked all over, just can't figure this oneout...
Basic:
-------
Created a New ItemData Block for a fishingpole
Created a Bait Box..
Can Use this Item properly
Can pickUp and Mount Item properly
Can Throw Item from Inventory properly
CANNOT Mount this Item from Inventory....
==============================
Alrighty then:
1: I can load up with Multiple items properly in Inventory.
2: I can switch between a Sword and Crossbow no problem.
3: I can start with a FishPole mounted from an Object PickUp call -- (Collide and it mounts and fishes)
4: I can switch to Sword/Crossbow with a FishPole as starting weapon from a collide
5: I cannot Switch to a Fishpole at ALL!
Heres the Trace below and relevant code blocks..
As far as I can tell, It doesn't seem to recognise the Name FishPole as a DataBlock correctly,
yet it does in the same call using a Sword or Crossbow...
(Trace Output for FishPole)
Attempt with a FishPole in Inventory
--------------------------------------
Trace
-------
It's something to do with the DataBlocks as I can surmise from this..
The problem is that I can't see any reason for the FishPole NOT to work like the Sword or Crossbow..
I'm stumped here...
The FishPole works in all respects as the crossbow with just some Minor changes...
It should work..
The Functions should all be getting the Exact same thing.
It should only be getting the NAME of the DataBlock for each type (Sword/Crossbow/FishPole)
and should then have access to that DataBlock the same way for each type??
I'm banging my head here...
I always wack the DSO's after changes to Scripts..
I use loads of Debug Echo's and traces...
The Logic of the Code I've added and created (Some my own, some from others) is clear
and should be working as it shows...
Lost and in a complete state of Mind Numbness here...
Is there something I am missing for when the Server Initialises and Creates these DataBlocks?
My FishPole.cs file is compiled right after the Crossbow.cs file... So the DataBlocks should both be present?
I've got no Script errors reported either...
As this is all in Script areas, I can't use the VC Debugger (One reason I don't like Scripts).
I'll post my Code next...
Basic:
-------
Created a New ItemData Block for a fishingpole
Created a Bait Box..
Can Use this Item properly
Can pickUp and Mount Item properly
Can Throw Item from Inventory properly
CANNOT Mount this Item from Inventory....
==============================
Alrighty then:
1: I can load up with Multiple items properly in Inventory.
2: I can switch between a Sword and Crossbow no problem.
3: I can start with a FishPole mounted from an Object PickUp call -- (Collide and it mounts and fishes)
4: I can switch to Sword/Crossbow with a FishPole as starting weapon from a collide
5: I cannot Switch to a Fishpole at ALL!
Heres the Trace below and relevant code blocks..
As far as I can tell, It doesn't seem to recognise the Name FishPole as a DataBlock correctly,
yet it does in the same call using a Sword or Crossbow...
(Trace Output for FishPole)
Attempt with a FishPole in Inventory
--------------------------------------
Trace
-------
Entering InventoryListView::OnUseItem()
<------------ InventoryGui.gui OnUseItem() ----------->
Selected = FishPole
Index = 0
Current Index : 0
Current Count : 1
Leaving InventoryListView::OnUseItem() - return
Entering serverCmdUse(1436, FishPole)
<------------ inventory.cs serverCmdUse() ----------->
Entering ShapeBase::use(1466, FishPole)
<------------------ Inventory.cs ShapeBase::use() ---------->
Shape FishPole
Shape ID 1424
common/server/scripts/inventory.cs (57): Unable to find object: '' attempting to call function 'getName'
Shape Image
common/server/scripts/inventory.cs (58): Unable to find object: '' attempting to call function 'getId'
Shape Image ID
common/server/scripts/inventory.cs (59): Unable to find object: '' attempting to call function 'getName'
Shape Image Ammo
common/server/scripts/inventory.cs (60): Unable to find object: '' attempting to call function 'getId'
Shape Image Ammo ID
<---- Inventory Check ---->
Entering ShapeBase::getInventory(1466, FishPole)
Leaving ShapeBase::getInventory() - return 1
Inventory Count 1
Entering ShapeBase::getInventory(1466, FishPole)
Leaving ShapeBase::getInventory() - return 1
common/server/scripts/inventory.cs (67): Unknown command onUse.
Object FishPole(1424) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
Leaving ShapeBase::use() - return
Leaving serverCmdUse() - return-----------------------------------------------------It's something to do with the DataBlocks as I can surmise from this..
The problem is that I can't see any reason for the FishPole NOT to work like the Sword or Crossbow..
I'm stumped here...
The FishPole works in all respects as the crossbow with just some Minor changes...
It should work..
The Functions should all be getting the Exact same thing.
It should only be getting the NAME of the DataBlock for each type (Sword/Crossbow/FishPole)
and should then have access to that DataBlock the same way for each type??
I'm banging my head here...
I always wack the DSO's after changes to Scripts..
I use loads of Debug Echo's and traces...
The Logic of the Code I've added and created (Some my own, some from others) is clear
and should be working as it shows...
Lost and in a complete state of Mind Numbness here...
Is there something I am missing for when the Server Initialises and Creates these DataBlocks?
My FishPole.cs file is compiled right after the Crossbow.cs file... So the DataBlocks should both be present?
I've got no Script errors reported either...
As this is all in Script areas, I can't use the VC Debugger (One reason I don't like Scripts).
I'll post my Code next...
About the author
Recent Threads
#2
---------------------------
07/16/2005 (12:18 pm)
Relevant Code Blocks---------------------------
datablock ItemData(BaitBox)
{
category = "Ammo";
className = "Ammo";
shapeFile = "~/data/shapes/fishingpole/bait.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
pickUpName = "Bait";
};
exec("~/data/shapes/fishingpole/fishpole.cs");
datablock ItemData(FishPole)
{
category = "Weapon";
className = "Weapon";
shapeFile = "~/data/shapes/FishingPole/FishPole.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
pickUpName = "a Fishing Pole";
image = FishPoleImage;
itemType="melee";
trayIcon = "fishnpole.jpg";
};
datablock ShapeBaseImageData(FishPoleImage)
{
shapeFile = "~/data/shapes/FishingPole/FishPole.dts";
emap = true;
mountPoint = 0;
eyeOffset = ".5 .5 -3";
correctMuzzleVector = false;
className = "WeaponImage";
item = FishPole;
ammo = BaitBox;
projectile = CrossbowProjectile;
projectileType = Projectile;
<---------------------SNIP Extra Stuff------------------>
};commands.csfunction serverCmdInvUseItem(%client, %Index, %amount)
{
%player = %client.player;
%player.use( %Index );
}
function InventoryListView::OnUseItem()
{
echo("<------------ InventoryGui.gui OnUseItem() ----------->" );
echo("Selected = "@$SelectedItem );
%Index = $Inventory.getIndexFromKey($SelectedItem);
echo("Index = "@%Index );
if( %Index == -1 )
{
echo("Invalid Index");
}
else
{
echo("Current Index : "@%Index );
echo("Current Count : "@$Inventory.getValue(%Index) );
}
commandToServer('Use', $SelectedItem );
}Final Calls that Mount the Weapon from Inventoryfunction serverCmdUse(%client,%data)
{
echo("<------------ inventory.cs serverCmdUse() ----------->" );
%client.getControlObject().use(%data);
}
function ShapeBase::use(%this,%data)
{
echo("<------------------ Inventory.cs ShapeBase::use() ---------->");
echo("Shape "@%data.getName());
echo("Shape ID "@%data.getId());
echo("");
echo("Shape Image "@%data.image.getName());
echo("Shape Image ID "@%data.image.getId());
echo("Shape Image Ammo "@%data.image.ammo.getName());
echo("Shape Image Ammo ID "@%data.image.ammo.getId());
echo("<---- Inventory Check ---->");
echo("Inventory Count "@%this.getInventory(%data));
if (%this.getInventory(%data) > 0)
return %data.onUse(%this);
return false;
}
function Weapon::onUse(%data,%obj)
{
echo("<------------------ Weapon.cs Weapon::onUse() ---------->");
echo("Current Weapon "@%obj.getMountedImage($WeaponSlot).getName());
echo("Current Mounted Image ID "@%obj.getMountedImage($WeaponSlot));
echo("Weapon "@%data.pickUpName);
echo("Weapon ID "@%data.getId());
echo("Weapon Image "@%data.image.getName());
echo("Weapon Image ID "@%data.image.getId());
echo("Weapon Image Ammo "@%data.image.ammo.getName());
echo("Weapon Image Ammo ID "@%data.image.ammo.getId());
if (%obj.getMountedImage($WeaponSlot) != %data.image.getId())
{
ServerPlay3D(WeaponUseSound,%obj.getTransform());
%obj.mountImage(%data.image, $WeaponSlot);
}
echo("New Weapon "@%obj.getMountedImage($WeaponSlot).getName());
echo("New Mounted Image ID "@%obj.getMountedImage($WeaponSlot));
}
#3
Looking over my Own Echo's I spotted that the ShapeID is getting garbled for the fishpole..
Picking up FishPole (No other Weapons)
Trying to (use) from inventory
And theres the problem... On the second part, we sent the Info to USE the Fishpole..
and the Shape ID ( OBJECT.getID() ) call comes back with a BAD ID
Wheres as it doesn't have a problem with the Sword or Crossbow and the ID stays
the same throughout...
Any Help would be appreciated... Working with a modified Head version (3 weeks old).
07/16/2005 (3:04 pm)
I'm closer to finding the Glitch, and it does look like a glitch somewhere..Looking over my Own Echo's I spotted that the ShapeID is getting garbled for the fishpole..
Picking up FishPole (No other Weapons)
<------------------ Inventory.cs ShapeBase::use() ----------> Shape FishPole Shape ID 142 <------------------ Weapon.cs Weapon::onUse() ----------> common/server/scripts/weapon.cs (52): Unable to find object: '0' attempting to call function 'getName' Current Weapon Current Mounted Image ID 0 Weapon a Fishing Pole Weapon ID 142
Trying to (use) from inventory
<------------ inventory.cs serverCmdUse() -----------> <------------------ Inventory.cs ShapeBase::use() ----------> Shape FishPole Shape ID 1424 common/server/scripts/inventory.cs (58): Unable to find object: '' attempting to call function 'getName' Shape Image not available
And theres the problem... On the second part, we sent the Info to USE the Fishpole..
and the Shape ID ( OBJECT.getID() ) call comes back with a BAD ID
Wheres as it doesn't have a problem with the Sword or Crossbow and the ID stays
the same throughout...
Any Help would be appreciated... Working with a modified Head version (3 weeks old).
#4
I expect many others have run into at sometime.
It's all to do with the way the Script system handles variables/strings/datablocks:
My mission file section that caused problem:
The Correct way to do it and AVOID the "Bug" or "Feature", your choice:
Heres what happens with the First one:::
Call the %data.use(%Index) and it Finds the First one:
The Named ITEM ( item(FishPole) ) --> ID = 1424
Not the DataBlock (FishPole) --> ID 142
You generally DON'T run into it with the Sample Crossbow Script as the
Basic Mission sets it up this way:
So watch what you name things in the Scripts...
It is FAR Too easy to make this mistake...
The Scripting system has no locks/checks/balances on what you do like most programming languages.
My recommendation is to setup a Specific Naming convention for yourself
All DataBlocks named like so:
datablocks : "dbFishingPole"
ImageData : "idFishingPole"
And stick to it...
Use simplier names for the Items if you need to, but setup things this way
and this simple but Damned annoying issue won't happen down the road.
07/16/2005 (4:07 pm)
Found the issue and a simple one too...I expect many others have run into at sometime.
It's all to do with the way the Script system handles variables/strings/datablocks:
My mission file section that caused problem:
new SimGroup(FishingData) {
new Item(Bait) {
position = "24.6318 -663.307 258.649";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "BaitBox";
collideable = "0";
static = "1";
rotate = "0";
count = "20";
};
new Item(FishPole) {
position = "35.2428 -678.964 257.212";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "FishPole";
collideable = "0";
static = "1";
rotate = "0";
count = "1";
};The Correct way to do it and AVOID the "Bug" or "Feature", your choice:
new SimGroup(FishingData) {
new Item() {
position = "24.6318 -663.307 258.649";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "BaitBox";
collideable = "0";
static = "1";
rotate = "0";
count = "20";
};
new Item() {
position = "35.2428 -678.964 257.212";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "FishingPole";
collideable = "0";
static = "1";
rotate = "0";
count = "1";
};Heres what happens with the First one:::
Call the %data.use(%Index) and it Finds the First one:
The Named ITEM ( item(FishPole) ) --> ID = 1424
Not the DataBlock (FishPole) --> ID 142
You generally DON'T run into it with the Sample Crossbow Script as the
Basic Mission sets it up this way:
new Item(RepeatCrossbow) {
position = "-29.4853 -618.673 262.726";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Crossbow";
collideable = "0";
static = "1";
rotate = "0";
count = "1";
};So watch what you name things in the Scripts...
It is FAR Too easy to make this mistake...
The Scripting system has no locks/checks/balances on what you do like most programming languages.
My recommendation is to setup a Specific Naming convention for yourself
All DataBlocks named like so:
datablocks : "dbFishingPole"
ImageData : "idFishingPole"
And stick to it...
Use simplier names for the Items if you need to, but setup things this way
and this simple but Damned annoying issue won't happen down the road.
#5
Excellent working modding those BTW.
07/16/2005 (6:20 pm)
Hey thats a nice catch and a good idea, I'll try that sometime.Excellent working modding those BTW.
Torque 3D Owner John "Mythic" Henry
EveronWorlds
Entering InventoryListView::onSelect(1316, 2, Sword 1) Leaving InventoryListView::onSelect() - return Entering GameManager::update(1427) Leaving GameManager::update() - return 1427 Entering GameManager::update(1427) Leaving GameManager::update() - return 1427 Entering InventoryListView::OnUseItem() <------------ InventoryGui.gui OnUseItem() -----------> Selected = Sword Index = 2 Current Index : 2 Current Count : 1 Leaving InventoryListView::OnUseItem() - return Entering serverCmdUse(1436, Sword) <------------ inventory.cs serverCmdUse() -----------> Entering ShapeBase::use(1466, Sword) <------------------ Inventory.cs ShapeBase::use() ----------> Shape Sword Shape ID 137 Shape Image SwordImage Shape Image ID 138 Shape Image Ammo CrossbowAmmo Shape Image Ammo ID 55 <---- Inventory Check ----> Entering ShapeBase::getInventory(1466, Sword) Leaving ShapeBase::getInventory() - return 1 Inventory Count 1 Entering ShapeBase::getInventory(1466, Sword) Leaving ShapeBase::getInventory() - return 1 Entering Weapon::onUse(Sword, 1466) <------------------ Weapon.cs Weapon::onUse() ----------> Current Weapon FishPoleImage Current Mounted Image ID 143 Weapon a sword Weapon ID 137 Weapon Image SwordImage Weapon Image ID 138 Weapon Image Ammo CrossbowAmmo Weapon Image Ammo ID 55 Entering ServerPlay3D(WeaponUseSound, -55.0809 -645.666 259.319 0 0 1 3.78802) Leaving ServerPlay3D() - return Entering WeaponImage::onMount(138, 1466, 0) Entering ShapeBase::getInventory(1466, CrossbowAmmo) Leaving ShapeBase::getInventory() - return 20 Leaving WeaponImage::onMount() - return 20 New Weapon SwordImage New Mounted Image ID 138 Leaving Weapon::onUse() - return Leaving ShapeBase::use() - return Leaving serverCmdUse() - return Entering InventoryListView::OnUseItem() <------------ InventoryGui.gui OnUseItem() -----------> Selected = Crossbow Index = 3 Current Index : 3 Current Count : 1 Leaving InventoryListView::OnUseItem() - return Entering serverCmdUse(1436, Crossbow) <------------ inventory.cs serverCmdUse() -----------> Entering ShapeBase::use(1466, Crossbow) <------------------ Inventory.cs ShapeBase::use() ----------> Shape Crossbow Shape ID 56 Shape Image CrossbowImage Shape Image ID 93 Shape Image Ammo CrossbowAmmo Shape Image Ammo ID 55 <---- Inventory Check ----> Entering ShapeBase::getInventory(1466, Crossbow) Leaving ShapeBase::getInventory() - return 1 Inventory Count 1 Entering ShapeBase::getInventory(1466, Crossbow) Leaving ShapeBase::getInventory() - return 1 Entering Weapon::onUse(Crossbow, 1466) <------------------ Weapon.cs Weapon::onUse() ----------> Current Weapon SwordImage Current Mounted Image ID 138 Weapon a crossbow Weapon ID 56 Weapon Image CrossbowImage Weapon Image ID 93 Weapon Image Ammo CrossbowAmmo Weapon Image Ammo ID 55 Entering ServerPlay3D(WeaponUseSound, -55.0809 -645.666 259.319 0 0 1 3.78802) Leaving ServerPlay3D() - return Entering WeaponImage::onMount(93, 1466, 0) Entering ShapeBase::getInventory(1466, CrossbowAmmo) Leaving ShapeBase::getInventory() - return 20 Leaving WeaponImage::onMount() - return 20 New Weapon CrossbowImage New Mounted Image ID 93 Leaving Weapon::onUse() - return Leaving ShapeBase::use() - return Leaving serverCmdUse() - return