Support Ummu Coding

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
10,538
Reaction score
4,369
Points
203
Location
Dallas, TX
I think this is right:


Code:
if (Crew.GetCrewMiscIdByName(Crew.GetLastEnteredCrewName())=="ROBOT")SetMeshVisibilityMode( 6, MESHVIS_ALWAYS ); 
 		else  SetMeshVisibilityMode( 6, MESHVIS_NEVER );

I want it to see if ROBOT is the name of a crew member on board. If it is then make #6 mesh visible else not visible.

Thanks
 
* Disclaimer: I have never written a vessel with UMMU support, and have only just looked into its SDK this afternoon...

1. GetLastEnteredCrewName will only return the name of the crew member who was last to ingress - there is a high probability that your "ROBOT" was not the last to enter (unless you have done SetMaxSeatAvailableInShip(1), but it would be poor form to rely on it anyway).

2. GetCrewMiscIdByName returns a string (technically, an array of chars) from the - these are not the names of the crew members, so it would never return "ROBOT".

3. You use the "equal to" operator "==" to compare two char arrays which is not valid. The return value of GetCrewMiscIdByName will be a pointer equal to the memory location of an element in the UmmuMiscID arrayand "ROBOT" will return a pointer to that string (probably in static memory somewhere). These two things will never be equal. Use strcmp or similar instead.

4. Using a hard coded value for the mesh index is a bad idea. You really should use a vessel class member variable to cache the return value of AddMesh.

EDIT: Sorry, I got excited and hit the post button a bit quick... The solution is to call GetCrewMiscIdByName("ROBOT") and check that it returns a non-empty string using strlen:
Code:
if (strlen(GetCrewMiscIdByName("ROBOT")))
     SetMeshVisibilityMode( 6, MESHVIS_ALWAYS );
else
     SetMeshVisibilityMode( 6, MESHVIS_NEVER );
 
Thanks. This worked
Code:
if (strlen([COLOR=Red]Crew.[/COLOR]GetCrewMiscIdByName("ROBOT")))
     SetMeshVisibilityMode( 6, MESHVIS_ALWAYS );
else
     SetMeshVisibilityMode( 6, MESHVIS_NEVER );


On the hard coded value of the mesh index. Not sure otherwise how to do it.
Code:
if ((Crew.GetCrewTotalNumber()==1))SetMeshVisibilityMode( 0, MESHVIS_ALWAYS ); 
        else  SetMeshVisibilityMode( 0, MESHVIS_NEVER ); 
        if ((Crew.GetCrewTotalNumber()==2))SetMeshVisibilityMode( 1, MESHVIS_ALWAYS ); 
        else  SetMeshVisibilityMode( 1, MESHVIS_NEVER );
and so depending on the number of crew displays the number of crew

* Disclaimer: I have never written a vessel with UMMU support, and have only just looked into its SDK this afternoon...

1. GetLastEnteredCrewName will only return the name of the crew member who was last to ingress - there is a high probability that your "ROBOT" was not the last to enter (unless you have done SetMaxSeatAvailableInShip(1), but it would be poor form to rely on it anyway).

2. GetCrewMiscIdByName returns a string (technically, an array of chars) from the - these are not the names of the crew members, so it would never return "ROBOT".

3. You use the "equal to" operator "==" to compare two char arrays which is not valid. The return value of GetCrewMiscIdByName will be a pointer equal to the memory location of an element in the UmmuMiscID arrayand "ROBOT" will return a pointer to that string (probably in static memory somewhere). These two things will never be equal. Use strcmp or similar instead.

4. Using a hard coded value for the mesh index is a bad idea. You really should use a vessel class member variable to cache the return value of AddMesh.

EDIT: Sorry, I got excited and hit the post button a bit quick... The solution is to call GetCrewMiscIdByName("ROBOT") and check that it returns a non-empty string using strlen:
Code:
if (strlen(GetCrewMiscIdByName("ROBOT")))
     SetMeshVisibilityMode( 6, MESHVIS_ALWAYS );
else
     SetMeshVisibilityMode( 6, MESHVIS_NEVER );
 
Thanks. This worked
Code:
if (strlen([COLOR=Red]Crew.[/COLOR]GetCrewMiscIdByName("ROBOT")))
     SetMeshVisibilityMode( 6, MESHVIS_ALWAYS );
else
     SetMeshVisibilityMode( 6, MESHVIS_NEVER );
Ah yes, my bad...

On the hard coded value of the mesh index. Not sure otherwise how to do it.
Code:
if ((Crew.GetCrewTotalNumber()==1))SetMeshVisibilityMode( 0, MESHVIS_ALWAYS ); 
        else  SetMeshVisibilityMode( 0, MESHVIS_NEVER ); 
        if ((Crew.GetCrewTotalNumber()==2))SetMeshVisibilityMode( 1, MESHVIS_ALWAYS ); 
        else  SetMeshVisibilityMode( 1, MESHVIS_NEVER );
and so depending on the number of crew displays the number of crew
So these meshes are of the crew members? Given that you won't be swapping them in and out at high frequency, I think it would be better to load them as globally managed meshes and add/delete them to your vessel as the crew ingress/egress. You will use less system resources that way if there are multiple instances of your vessel in a scenario. Also, don't you want to check their MiscID so you know whether to show the capt/pilot/etc mesh?

Anyway, I also noticed that MiscID==NULL is valid for a crew member, so you might want to use Crew.GetCrewPulseByName("ROBOT")==-1 instead of strlen(Crew.GetCrewMiscIdByName("ROBOT")).
 
Thanks. Now I am confused. The crew all have the same mesh. So they are clones. The one that is different is the Robot.

So what I have is the vessel with 6 chairs. So if the crew =6 the mesh with 6 crew members will appear. If one guy leaves then the mesh of 5 crew will appear and the 6 dissappear.. So one
 
Well, ultimately you can implement it however you want. I just thought that you might have seat positions that are representative of the MiscID, so if you EVA the captain, for example, then the mesh disappears from the front left seat. I also assumed that 1 crew member = 1 mesh, even if they are all clones (you can have multiple instances of the same mesh).

I realised I didn't respond regarding caching the mesh index. What I meant there was that you should have some member variables to hold the return values from AddMesh since Orbiter gives no guarantees as to what the return value will be. So when you add the mesh:

Code:
hMesh5Crew = AddMesh("YourVesselClass\5CrewMesh", &crewMeshPosition);
Then you can use hMesh5Crew later:

Code:
SetMeshVisibilityMode(hMesh5Crew, MESHVIS_ALWAYS);
 
So maybe like this:
Code:
hMesh1Crew = AddMesh("CHARIOTEVA1", &0);
Then you can use hMesh5Crew later:
and this:
Code:
if ((Crew.GetCrewTotalNumber()==1))SetMeshVisibilityMode( hMesh1Crew, MESHVIS_ALWAYS ); 
        else  SetMeshVisibilityMode( hMesh1Crew, MESHVIS_NEVER );
and so forth for the different crew number?

Well, ultimately you can implement it however you want. I just thought that you might have seat positions that are representative of the MiscID, so if you EVA the captain, for example, then the mesh disappears from the front left seat. I also assumed that 1 crew member = 1 mesh, even if they are all clones (you can have multiple instances of the same mesh).

I realised I didn't respond regarding caching the mesh index. What I meant there was that you should have some member variables to hold the return values from AddMesh since Orbiter gives no guarantees as to what the return value will be. So when you add the mesh:

Code:
hMesh5Crew = AddMesh("YourVesselClass\5CrewMesh", &crewMeshPosition);
Then you can use hMesh5Crew later:

Code:
SetMeshVisibilityMode(hMesh5Crew, MESHVIS_ALWAYS);
 
Back
Top