API Question Beacon code is right, but in simulation mode it does not render

MJR

C++ developer in the mix
Addon Developer
Tutorial Publisher
Donator
Joined
Mar 19, 2008
Messages
2,447
Reaction score
5
Points
0
Location
United States
As the title says, I compiled the beacon code right, but it does not show up. Here is what I have.

Code:
double Lights = 0;
double switched = 0;
double duration;   //   strobe duration
double tofs;       //   strobe time offset
BEACONLIGHTSPEC beacon1;

Code:
static BEACONLIGHTSPEC beacon1;
    static VECTOR3 beacon1pos = {-19.81932,-11.73627,-6.477392};
    static VECTOR3 beacon1col = {0.043, 0.161, 0.992};
    
        beacon1.shape = (BEACONSHAPE_STAR);
        beacon1.pos = &beacon1pos;
        beacon1.col = &beacon1col;
        beacon1.size = (2.1);
        beacon1.falloff = (0.6);
        beacon1.period = (1.13);
        beacon1.duration = (0.9);
        beacon1.tofs = (0.6);
        beacon1.active = false;
        
        AddBeacon (&beacon1);

Code:
int Spacecraft::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
    if (!down) return 0; // only process keydown events

    // if (KEYMOD_SHIFT (kstate)) {

        switch (key) {
            
        case OAPI_KEY_K: // Engine start
        
        if( engstart == 0 )
        {
            engstart = 1;
            

            
            return 1;
        }
                    
            if( engstart == 1 )
        {
            engstart = 1;
            
            return 1;
        }
        
        if( engstart == 2 )
        {
            engstart = 3;
            
            
            
            return 1;
    
        return 0;

        case OAPI_KEY_G: // Lights
        
        if( Lights == 0 )
        {
            Lights = 1;
            switched =1;
                    
            return 1;
}

        if( Lights == 1 )
        {
            Lights = 0;
            switched = 1;
                    
            return 1;
}
    
    } 
    return 0;
}
            
}
The simulation mode runs fine, but when I press the command button nothing happens. I am sure it is a simple thing that can be fixed. Just wished I could fix it before starting a new thread. I edited the offset of the beacon multiple times to see if that was the case and had no success.
 
I don't see where in your code you are switching the "beacon1.active" from false to true. Is it switched somewhere?
 
I don't see where in your code you are switching the "beacon1.active" from false to true. Is it switched somewhere?
Aha! I knew I was leaving something. Let me add that part of the code and get back to you.

---------- Post added at 08:00 PM ---------- Previous post was at 07:36 PM ----------

All is well, but I get an unresolved external error. It is a pain in the neck. I put the function "Lighting" under the vessel class to show it is in there.

Code:
void Spacecraft::clbkPostStep (double simt, double simdt, double mjd)
 {
    if (Lights == 1 && switched == 1)
 {
     beacon1.active = true;
     beacon2.active = true;
     switched = 0;
     Lighting();

    }
if (Lights == 0 && switched == 1)
{
    beacon1.active = false;
    beacon2.active = false;
    switched = 0;
    Lighting();
}

 

     if (engstart == 1)
    {
    if (iopt >1 )iopt = 0;
    iopt = iopt + engrot;
    
    engrot = engrot + 0.0005;
    
    if (engrot > 0.1333)
    {
        engstart = 2;
        
        engrot = 0.1333;
    }
    
    
    SetAnimation (anim_eng, iopt);
    }


    // Engine on
    
    if (engstart == 2)
    {
    if (iopt >1 )iopt = 0;
    iopt = iopt + 0.1333;
    
    SetAnimation (anim_eng, iopt);
}
   // Engine stop
    
    if (engstart == 3)
    {
    if (iopt >1 )iopt = 0;
    iopt = iopt + engrot;
    
    engrot = engrot - 0.0005;
    
    if (engrot <= 0)
    {
        engstart = 0;
        
        engrot = 0;
    }

    SetAnimation (anim_eng, iopt);
}



 }

I can get it to work only if I declare it as true, but that is not so great because I want the user to be in control of the actions.

Code:
>Spacecraft.obj : error LNK2001: unresolved external symbol "private: void __thiscall Spacecraft::Lighting(void)" (?Lighting@Spacecraft@@AAEXXZ)
1>C:\Users\Essie\Documents\Visual Studio 2008\Projects\Space\Release\Spacecraft.dll : fatal error LNK1120: 1 unresol

Regardless of these little errors here and there, I think I am doing good with the code and I am understanding it. :thumbup:
 
Last edited:
Does your header know there is a Lighting member func in the cpp file?
 
To fix it I changed the code from this....

Code:
    if (Lights == 1 && switched == 1)
 {
     beacon1.active = true;
     beacon2.active = true;
     switched = 0;
     Lighting();

    }
if (Lights == 0 && switched == 1)
{
    beacon1.active = false;
    beacon2.active = false;
    switched = 0;
    Lighting();
}

To this...

Code:
    if (Lights == 1 && switched == 1)
 {
     beacon1.active = true;
     beacon2.active = true;
     switched = 0;
     void Lighting();

    }
if (Lights == 0 && switched == 1)
{
    beacon1.active = false;
    beacon2.active = false;
    switched = 0;
    void Lighting();
}

And apparently I had a jacked up static indicator that was located in the beacon code. So I got all that figured out. Thanks.
 
I don't understand your code. Is Lighting a method declared and defined in the class, or something else? Isn't your code working the same way when you remove "void Lighting();" from there?
 
I don't understand your code. Is Lighting a method declared and defined in the class, or something else? Isn't your code working the same way when you remove "void Lighting();" from there?
Haven't tried it without it yet, but I am assuming it is the same thing with or without.
 
Haven't tried it without it yet,
You have, because in your latest code snippet you never call function Lighting(), you just declare it twice. Incidently, the fact that you are no longer calling the function is the reason why the linker error went away.
but I am assuming it is the same thing with or without.
Why do you assume that? Doesn't your Lighting() function contain any useful code?

It strikes me that you could do with a bit more basic understanding of C or C++ instead of your rather slow trial and error approach. At least to the point where the compiler and linker error messages are sufficiently meaningful to you to direct you to the cause of the problem. Maybe a textbook or online training course?
 
You have, because in your latest code snippet you never call function Lighting(), you just declare it twice. Incidently, the fact that you are no longer calling the function is the reason why the linker error went away.

Why do you assume that? Doesn't your Lighting() function contain any useful code?

It strikes me that you could do with a bit more basic understanding of C or C++ instead of your rather slow trial and error approach. At least to the point where the compiler and linker error messages are sufficiently meaningful to you to direct you to the cause of the problem. Maybe a textbook or online training course?
Lighting() function is in the code already. Knowing how simple it is to list, I didn't put it here because that wasn't the problem I had. Nonetheless I got it to work and when I get back from work I will try it like you guys are suggesting to.
 
Lighting() function is in the code already. Knowing how simple it is to list, I didn't put it here because that wasn't the problem I had. Nonetheless I got it to work and when I get back from work I will try it like you guys are suggesting to.
The last bit of code you posted doesn't "work." It may compile, but "works" and "compiles" are very different.
 
Back
Top