Getting your selection's name?
by Zergcow · in RTS Starter Kit · 03/24/2008 (12:36 pm) · 4 replies
I am setting up my buildings based on the world domination mod where each building type has its own GUI hud. But I am trying to make my dynamic HUDs even more dynamic by finding the buildings ID wich is a 12 digit number saved as a dynamic field and using it in the buttons.
So for now i am trying to make the button return the ID when pressed. but nothing i do works. i dont know what to do to get the datablock and then the ID. I was trying
anyone want to help me out here? I have been playing around with resolveGhostID--on the client, this console method returns an ObjectID that is associated with a GhostID sent from the server. resolveObjectFromGhostIndex--on the server, this console method returns an ObjectID that is associated with a GhostID sent from a client. getGhostID--on the server, this console method returns the GhostID associated with a server side simulation object for this connection. But i am not having much luck.
here is my function i have been playing with... (the building has a dynamic field called sid in it already with a value of "123456789012")
So for now i am trying to make the button return the ID when pressed. but nothing i do works. i dont know what to do to get the datablock and then the ID. I was trying
%obj.getDatablock().getSid();but it keeps saying it "cant find ' ' object" So then i tried
%building.getGhostID()but that didnt work either.
anyone want to help me out here? I have been playing around with resolveGhostID--on the client, this console method returns an ObjectID that is associated with a GhostID sent from the server. resolveObjectFromGhostIndex--on the server, this console method returns an ObjectID that is associated with a GhostID sent from a client. getGhostID--on the server, this console method returns the GhostID associated with a server side simulation object for this connection. But i am not having much luck.
here is my function i have been playing with... (the building has a dynamic field called sid in it already with a value of "123456789012")
function ButtonUse()
{
%obj = %building.getGhostID();
echo(%obj.sid);
}About the author
#2
As for uniquely identifying objects, have you tried the setShapeName function? this allows you to give any shapebase derived object a unique name. Now, unfortunately, the RTSUnit pack/unpack functions override the shapebase pack/unpack and the shapename doesn't get networked for them, but it would be trivial to add the functionality back in.
03/25/2008 (10:08 am)
From the errors you're getting, it looks like %building isn't actually a building. Without looking at the code where you are assigning %building, I can't really comment any further.As for uniquely identifying objects, have you tried the setShapeName function? this allows you to give any shapebase derived object a unique name. Now, unfortunately, the RTSUnit pack/unpack functions override the shapebase pack/unpack and the shapename doesn't get networked for them, but it would be trivial to add the functionality back in.
#3
When i place a building it tells me its index and when i select it, it pops up a GUI based on the index. I just cant figure out how to make a button tell me the ID or Name of the building i have selected.
03/25/2008 (10:46 am)
Well it is using the base block and only modifying it for model and size. so here is the base block where it adds it as a building.function serverCmdPlaceBuilding(%conn, %transform, %data, %zTweak)
{
%b = new RTSBuilding()
{
datablock = %data;
scale = "1 1 1";
};
%b.setTransform( %transform );
%b.client = %conn;
%b.setTeam(%conn.getTeam());
%b.setControllingConnection(%conn);
%conn.buildings.add(%b);
%b.playRootAnimation();
echo("serverCmdPlaceBuilding()--building (" @ %b @ "):");
%b.initBuildingActions();
}When i place a building it tells me its index and when i select it, it pops up a GUI based on the index. I just cant figure out how to make a button tell me the ID or Name of the building i have selected.
#4
The only way I can think of (cause I'm relatively new to this) is to pass the reference to the object (in this case, %b) with the function that creates (or shows) the GUI and then store this index as a variable with the GUI. So the GUI itself will always know which building it "belongs" to. If you want one GUI that will show you the name of any building you select... well I have ideas on that, but try this first because I would have to have the selection code in front of me.
In your button example in the first post, the variable %building seems to be appearing from nowhere. That is a local variable with no definition. You could use a global variable to store all of the building references... but don't, that's not a good idea. I could give you an example of how I would implement it, but I'm hoping this will be enough to steer you along... plus I'm a newbie and don't want my coding skills (or lack thereof) being made fun of too much!
06/03/2008 (2:50 pm)
Correct me if I'm wrong, I'm trying to understand what's going on. In serverCmdPlaceBuilding you added a function that creates (or shows) a GUI component? Now when you click on a button on that GUI you want the name of the building designated in the above datablock. The only way I can think of (cause I'm relatively new to this) is to pass the reference to the object (in this case, %b) with the function that creates (or shows) the GUI and then store this index as a variable with the GUI. So the GUI itself will always know which building it "belongs" to. If you want one GUI that will show you the name of any building you select... well I have ideas on that, but try this first because I would have to have the selection code in front of me.
In your button example in the first post, the variable %building seems to be appearing from nowhere. That is a local variable with no definition. You could use a global variable to store all of the building references... but don't, that's not a good idea. I could give you an example of how I would implement it, but I'm hoping this will be enough to steer you along... plus I'm a newbie and don't want my coding skills (or lack thereof) being made fun of too much!
Torque Owner Zergcow
anyone know what i am doing wrong?