# ProblemAnimation state and status correctly written to scenario file, but can't be read?

#### Thunder Chicken

Donator
I am sprucing up some code in Kev33's Mirage 2000 model and am trying to save and read animation states to the scenario file.

I am writing the animation status and state using clbkSaveState:

C++:
void Mirage2000::clbkSaveState(FILEHANDLE scn)
{
VESSEL2::clbkSaveState(scn);

//Write canopy animation status and state

oapiWriteScenario_int(scn, "canopy_anim_status", canopy_anim_status);
oapiWriteScenario_float(scn, "canopy_anim_state", canopy_anim_state);
}

This seems to be working properly as I get the following in the scenario file:

Code:
K-Mirage2000:K33\K-Mirage2000
STATUS Landed Earth
POS -80.6832361 28.5978592
ALT 2.401
AROT 66.737 33.746 9.912
AFCMODE 7
PRPLEVEL 0:1.000000
NAVFREQ 94 481
canopy_anim_status 1  //canopy opening
canopy_anim_state 0.537892  //canopy 53.8% open
END

But clbkLoadStateEx doesn't seem to be able to read those lines from the scenario with this code:

C++:
void Mirage2000::clbkLoadStateEx(FILEHANDLE scn, void *status)
{
char *line;
{
//Load canopy animation status and state

if (!_strnicmp(line, "canopy_anim_status", 19))
{
sscanf(line + 19, "%li", &canopy_anim_status);
}
else if (!_strnicmp(line, "canopy_anim_state", 18))
{
sscanf(line + 18, "%lf", &canopy_anim_state);
}
else
{
ParseScenarioLineEx(line, status);
}
}
}

I'm not quite sure what is going on. The scenario loads, but the canopy animation status and state are in the position of their initialized state (UINT canopy_anim_status = 0 and double canopy_anim_state = 0.0).

Last edited:

#### diogom

##### Well-known member
I've been doing the same for loading parameters and it has always worked so far, the method itself seems fine. But aren't you counting one extra character in the strings? (I've been doing it like "ANIM", 4)
I wonder though if it could also be something with using underscores in the names of the parameters: https://docs.microsoft.com/en-us/cp...trnicmp-l-wcsnicmp-l-mbsnicmp-l?view=msvc-170 under "Remarks", not entirely sure what that means myself, but they're at least different.

So maybe it's not quite reading 19 or 18 characters, and thus never loading the values. Not sure about it, but it's the one difference I see to what I usually do.

#### Thunder Chicken

Donator
You're right. I was hovering over the variables which gives this "helper"

I've been beating my head against this all day, and never thought about actually counting the characters. Gah...

Thanks!

#### diogom

##### Well-known member
Ah, that'll do it. It can be a bit misleading, it's counting the null terminator at the end of each string. So effectively you type 18 useful characters, but it needs that last null character to indicate the string is over, so the "array" needs to be 19 characters long.

C++ Question Moving beacon in play
Replies
0
Views
431
Replies
1
Views
1K
Replies
3
Views
2K
Replies
21
Views
4K