Is there a way to get a list of all objects and everything else in console when you run the game?
by Vlad I · in Torque Game Builder · 05/15/2012 (4:08 am) · 11 replies
I have some objects being made in my game through script.
Some are read out from a .sav file and brought into the scenes.
I want to delete some but can not find their names.
Is there a way to get a list of all objects and everything else in console when you run the game?
Some are read out from a .sav file and brought into the scenes.
I want to delete some but can not find their names.
Is there a way to get a list of all objects and everything else in console when you run the game?
About the author
#2
Very neat function! thnx.
But unfortunately it doesn't resolve my problem. In the console when I execute listAllObjects() it doesn't show the items in my inventory slots. It only shows the list of what I put in the TGB editor. But not what is read out from my .sav file and added.
I have some items in my inventory slots and I want to remove one of them.
I can see the items in the inventory on the screen when I run my game, and I know the name of the item I want to remove. I try to safeDelete in the script using but console says it cannot find such object.
05/15/2012 (6:16 am)
Hi Patrick!Very neat function! thnx.
But unfortunately it doesn't resolve my problem. In the console when I execute listAllObjects() it doesn't show the items in my inventory slots. It only shows the list of what I put in the TGB editor. But not what is read out from my .sav file and added.
I have some items in my inventory slots and I want to remove one of them.
I can see the items in the inventory on the screen when I run my game, and I know the name of the item I want to remove. I try to safeDelete in the script using but console says it cannot find such object.
#3
I tried this :
05/15/2012 (6:23 am)
I have this function in ItemSystem.csfunction RemoveItem(%this)
{
$cursorObject.safeDelete();
//NOTE: THIS IS DEMO CODE, CHANGE THIS FOR WHATEVER YOU NEED IT TO DO.
$inventoryItem[$cursorObject.reference].delete();
%this.safeDelete();
//this is NOT demo code, you need to use this after you have successfully used an item.
Canvas.showCursor();
$cursorActive = true;
$inventoryTotal -= 1;
}but this is only for the mouse as item use (when you have an item as mouse), and you use it on an object it is supposed to work on the screen, then it delets itself and updates the inventory.I tried this :
function RemoveItem(%this)
{
Cage01.safeDelete();
//NOTE: THIS IS DEMO CODE, CHANGE THIS FOR WHATEVER YOU NEED IT TO DO.
$inventoryItem[Cage01.reference].delete();
%this.safeDelete();
Cage01.safeDelete();
//this is NOT demo code, you need to use this after you have successfully used an item.
//Canvas.showCursor();
$cursorActive = true;
$inventoryTotal -= 1;
}with no avail.
#4
If I recall correctly, the inventory system in your game has a global variable that is constrained at 21 objects.
Try this:
05/15/2012 (6:51 am)
Vlad,If I recall correctly, the inventory system in your game has a global variable that is constrained at 21 objects.
Try this:
function listAllObjects()
{
%objCount = sceneWindow2d.getSceneGraph().getCount();
for(%i = 0; %i < %objCount; %i++)
{
echo(sceneWindow2d.getSceneGraph().getObject(%i).getName());
}
for(%count1 = 0; %count1 < 21; %count1 ++)
{
if(isObject($inventoryItem[%count1]))
{
echo($inventoryItem[%count1]);
}
}
}The problem I see is that your inventory items don't actually have names... so you'll see some numbers come up. These are TGB's internal identification. You can call .safeDelete() on those numbers or directly on the object that you're echo'ing out in the above code.
#5
For instance I want to delete Cage01 and lets assume it is the number 2270 the item I picked up first and it was added and given that number, what if I pick up Cage01 after I picked up smth. else the number might be different. I wouldn't be able to pass what to delete. Just bare with me I'll check it.
05/15/2012 (7:01 am)
Yes, you are correct as usual :). Some numbers came up 3 to be exact 2270,2271,2272 these are 3 items in my inventory slots. Bare with me I'll try to delete them. However the numbers might be different .For instance I want to delete Cage01 and lets assume it is the number 2270 the item I picked up first and it was added and given that number, what if I pick up Cage01 after I picked up smth. else the number might be different. I wouldn't be able to pass what to delete. Just bare with me I'll check it.
#6
05/15/2012 (7:09 am)
It is impossible to track the numbers they all change to different ones, every time I go to any scene, even go back , and it gives different numbers smth. like 2836, 2837, 2838, and in another it is all changed again. So when I tried to safeDelete 2270 it gave me that it couldn't find that object obviously.
#7
05/15/2012 (7:15 am)
Definitely... It's a sign that the approach is wrong I guess. How are you trying to remove the item from the inventory?
#8
One idea was to make a schedule after onMouseDown and quickly assign Cage01 as $cursorObject (
05/15/2012 (7:29 am)
At the moment I'm stuck.One idea was to make a schedule after onMouseDown and quickly assign Cage01 as $cursorObject (
$cursorObject = Cage; RemoveItem(Cage01);)and call this function in it RemoveItem(Cage01):
function RemoveItem(%this)
{
$cursorObject.safeDelete();
//NOTE: THIS IS DEMO CODE, CHANGE THIS FOR WHATEVER YOU NEED IT TO DO.
$inventoryItem[$cursorObject.reference].delete();
%this.safeDelete();
//this is NOT demo code, you need to use this after you have successfully used an item.
Canvas.showCursor();
$cursorActive = true;
$inventoryTotal -= 1;
}But it can't find such objects since they are numbers randomly given in every scene load by function loadInventory()
#9
and then it calls
Here is my case:
I have to find Cage01 and Net01 to enter a barn and catch all the scorpions in there. Without these 2 objects you can not enter the Barn.
So they both should be in the inventory and clearly visible to the players or they would be confused.
After I found these 2 items I enter the Barn, then I use Net01 to catch all the scorpions, Net01 gets deleted and a window appears all "All Scorpions are Caught" behind the close button I hid new item object CageWithScorpions01. So when you click it, it adds up to the inventory and later I need to use it on an old guy to prove him that his Barn is cleared of infestation :)
Hence there is a need to get rid off the empty cage, since its purpose has been served, and now I have a new cage full of scorpions.
But of course the empty Cage01 should be in your inventory in order to enter the Barn.
Can't think of a way around it.
05/15/2012 (7:48 am)
The thing is the inventory system deletes items from the inventory only by the use of mouse, this is the end part of function item::onMouseDown(%this, %modifier, %worldPosition, %clicks) in ItemSystem.cs//This checks if we have clicked an item that is in the inventory
if(%this.usable == true && %this.pickup == false && $cursorActive == true)
{
//if it is we dismount the item, hide the cursor, set cursorActive to false and make the new cursorObject as this item.
%this.dismount();
$cursorObject = %this;
Canvas.hideCursor();
$cursorActive = false;
}
} and then it calls
function RemoveItem(%this)
{
$cursorObject.safeDelete();
//NOTE: THIS IS DEMO CODE, CHANGE THIS FOR WHATEVER YOU NEED IT TO DO.
$inventoryItem[$cursorObject.reference].delete();
%this.safeDelete();
//this is NOT demo code, you need to use this after you have successfully used an item.
Canvas.showCursor();
$cursorActive = true;
$inventoryTotal -= 1;
}So somehow it passes that object(or in our case number) and makes it as cursor and then deletes it when clicked on the object it is supposed to be clicked on .Here is my case:
I have to find Cage01 and Net01 to enter a barn and catch all the scorpions in there. Without these 2 objects you can not enter the Barn.
So they both should be in the inventory and clearly visible to the players or they would be confused.
After I found these 2 items I enter the Barn, then I use Net01 to catch all the scorpions, Net01 gets deleted and a window appears all "All Scorpions are Caught" behind the close button I hid new item object CageWithScorpions01. So when you click it, it adds up to the inventory and later I need to use it on an old guy to prove him that his Barn is cleared of infestation :)
Hence there is a need to get rid off the empty cage, since its purpose has been served, and now I have a new cage full of scorpions.
But of course the empty Cage01 should be in your inventory in order to enter the Barn.
Can't think of a way around it.
#10
I can get rid off the empty cage and bring the full of scorpions one to the old guy, but it is not desirable, since I have a whole hiddden object level where you need to find it.
05/15/2012 (8:14 am)
How would go about this? I can get rid off the empty cage and bring the full of scorpions one to the old guy, but it is not desirable, since I have a whole hiddden object level where you need to find it.
#11
I can see it is using that Image.
It would be easier if it is done that way.
05/15/2012 (8:23 am)
Is there a way to access .sav file and change IconCage01ImageMap for another IconCageWithScorpions01ImageMap?I can see it is using that Image.
It would be easier if it is done that way.
Torque Owner RollerJesus
Dream. Build. Repeat.
I'm not aware of anything built it but you could use this:
function listAllObjects() { %objCount = sceneWindow2d.getSceneGraph().getCount(); for(%i = 0; %i < %objCount; %i++) { echo(sceneWindow2d.getSceneGraph().getObject(%i).getName()); } }Just put that function in a script file that is executed so it gets compiled, then use it by opening the console and typing: