C++ Question Save state issue

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
So this is just kicking me. It is for my Starlab. if the scn the extis set at 1.
Code:
STARLAB:STARLAB
  STATUS Orbiting Earth
  RPOS -590131.397 294.156 6983061.951
  RVEL -7515.2769 0.2728 -635.0537
  AROT -66.490 39.559 -64.966
  VROT 0.0218 -0.0497 -0.0525
  AFCMODE 7
  PRPLEVEL 0:0.999780
  NAVFREQ 0 0
  XPDR 468
  EXT 1 1.0000
END
But when I run it the value is now 0.0000
Code:
void STARLAB::clbkLoadStateEx(FILEHANDLE scn, void* status)
{
    char* line;
    while (oapiReadScenario_nextline(scn, line)) {

        
        if (!_strnicmp(line, "EXT", 3)) {
            sscanf(line + 3, "%d %0.4f", &EXT_status, &EXT_proc);
        }
        ParseScenarioLineEx(line, status);
            UpdateMesh();
            
        }
    
    }

void STARLAB::UpdateMesh()
{
    // update animation states
            

    
    //SetAnimation(anim_CENT, CENT_proc);
    //SetAnimation(anim_hga_azimuth, hga_azimuth_proc);
    //SetAnimation(anim_hga_elevation, hga_elevation_proc);

SetAnimation(anim_RADEXT, EXT_proc);
    SetAnimation(anim_PANELEXT, EXT_proc);
    SetAnimation(anim_hgamove, EXT_proc);
//    SetAnimation(anim_solp_rot, solp_rot_proc);
//    SetAnimation(anim_solR_rot, solp_rotRAD_proc);
    //    SetAnimation(anim_CAMERAELEVATE, CAMERAELEVATE_proc);
    //    SetAnimation(anim_CAMERAROTATE, CAMERAROTATE_proc);

}

void STARLAB::clbkSaveState(FILEHANDLE scn) {



    char cbuf[256];
    SaveDefaultState(scn);
    
    sprintf(cbuf, "%d %0.4f", EXT_status, EXT_proc);
    oapiWriteScenario_string(scn, "EXT", cbuf);

    

}
[\code]
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
253
Reaction score
301
Points
78
Location
On my chair
Code:
   while (oapiReadScenario_nextline(scn, line)) {
        if (!_strnicmp(line, "EXT", 3)) {
            sscanf(line + 3, "%d %0.4f", &EXT_status, &EXT_proc);
        } else {
            ParseScenarioLineEx(line, status);
        }
   }
   UpdateMesh();
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
Thanks. but nope.
Code:
void STARLAB::clbkLoadStateEx(FILEHANDLE scn, void* status)
{
    char* line;
    while (oapiReadScenario_nextline(scn, line)) {
        if (!_strnicmp(line, "EXT", 3)) {
            sscanf(line + 3, "%d %0.4f", &EXT_status, &EXT_proc);
        }
        else {
            ParseScenarioLineEx(line, status);
        }
    }
    UpdateMesh();

    
    }
when it loads it reads as 0.0000
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
253
Reaction score
301
Points
78
Location
On my chair
Alright, format for double is %lf so last chance :
Code:
sscanf(line + 3, "%d %lf", &EXT_status, &EXT_proc);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
Ok. now this:
Code:
sprintf(cbuf, "%d %d %lf", solp_status,solp_rot_status, solp_rot_proc);
    oapiWriteScenario_string(scn, "SOLAR", cbuf);
  
    sprintf(cbuf, "%d %d %lf", solR_status,solp_rotRAD_status, solp_rotRAD_proc);
    oapiWriteScenario_string(scn, "RAD", cbuf);
Code:
int solp_rot_status, solp_status, lighton, TANK, CREWSTATE, solR_status, solp_rotRAD_status, lightON, cargo,crew;
    double   solp_rot_proc, solp_rotRAD_proc;;

but getting
SOLAR 0 1 2078210740608385123520083505726970989772578749320137849151475781798792937071821144951645440101158775536835804552216668920091602004035998109021728302694400.000000
RAD 3 1 2078210740608385123520083505726970989772578749320137849151475781798792937071821144951645440101158775536835804552216668920091602004035998109021728302694400.000000

and then this:
EXT 1 1.000000
SOLAR 1073741824 2 1.000000
RAD 3 2 1.000000
 
Last edited:

Buck Rogers

Major Spacecadet
Joined
Feb 26, 2013
Messages
464
Reaction score
409
Points
63
I'm a total C++ novice so I can't verify this. Searching online I found:

For printf(), the "%lf" is not valid -- it should be "%f".
For scanf(), "%f" for float, "%lf" for double, and "%Lf" for long double.

would this be the same for sprint() and explain the .scn entries?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,863
Reaction score
2,837
Points
203
Location
Dallas, TX
try this. If it CTd send the log. Not sure about the mesh

I asked Brian about the autopilot
 

Attachments

  • marsrover6.2.zip
    93.3 KB · Views: 1
Top