Wolf3d Haven Forum

Please log in or register. Smile
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


    Coding Help with Keys please

    Share

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 1:02 pm

    I need some help. What I am trying to do is have a certain sound and phrase appear on screen only when I pick up the gold key on a certain level. Here is my code so far. The only problem is the sound and phrase appear when I pick up the gold key AND the silver key on this level. Again, I only want this stuff to happen when the gold key is picked up. Here is my code so far:

    WL_AGENT.C
    Code:
    case    bo_key1:
        case    bo_key2:
        case    bo_key3:
        case    bo_key4:
            GiveKey (check->itemnumber - bo_key1);
            SD_PlaySound (KEYPICKUPSND);
           
            if(gamestate.mapon==13);//episode 2 level 4
            GiveKey (check->itemnumber - bo_key1);
            GiveExtraMan ();
            SD_PlaySound (ACHIEVESND);
                GetMessage("*FROM THE BELLY OF THE BEAST AWARD!*\nExtra Man Added!");
                   
            break;

    It was my understanding the bo_key1 is the gold key and bo_key 2 is the silver key. I have already tried swapping the bo_key1 for bo_key 2 and still the sound and message appears for both keys. Help me please!



    http://jayngoware.com/

    Andy
    Seasoned Wolfer
    Seasoned Wolfer

    Number of posts : 280
    Registration date : 2007-12-22

    Re: Coding Help with Keys please

    Post by Andy on Fri Mar 26, 2010 1:20 pm

    Try this:

    WL_AGENT.C
    Code:
    case bo_key1:
    case bo_key2:
    case bo_key3:
    case bo_key4:
    GiveKey (check->itemnumber - bo_key1);
    SD_PlaySound (KEYPICKUPSND);

    if(gamestate.mapon==13);//episode 2 level 4
    {
    GiveKey (check->itemnumber - bo_key1);
    GiveExtraMan ();
    SD_PlaySound (ACHIEVESND);
    GetMessage("*FROM THE BELLY OF THE BEAST AWARD!*\\nExtra Man Added!");
    }

    break;

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 1:30 pm

    Hmm. Nope. I added the brackets like your code showed and still no difference. I tried using an else statement, but kept getting errors. Not sure what to do, but I think we are close...

    EDIT: Not sure that it matters, but on this level you pick up the silver key first. But, that really shouldn't make a difference.

    Also, I thought about linking all that code to the boss itself. When the boss dies all that stuff would happen. However, I want to hear the boss dying sound and then when you pick up the key I want to hear the achievement sound. So, that's why I can't code it there..since two digital sounds cant play at same time...



    http://jayngoware.com/

    Andy
    Seasoned Wolfer
    Seasoned Wolfer

    Number of posts : 280
    Registration date : 2007-12-22

    Re: Coding Help with Keys please

    Post by Andy on Fri Mar 26, 2010 1:51 pm

    Then try this:

    WL_AGENT.C
    Code:
    case bo_key1:

    if(gamestate.mapon==13);//episode 2 level 4
    {
    GiveKey (check->itemnumber - bo_key1);
    GiveExtraMan ();
    SD_PlaySound (ACHIEVESND);
    GetMessage("*FROM THE BELLY OF THE BEAST AWARD!*\\nExtra Man Added!");
    break;
    }

    case bo_key2:
    case bo_key3:
    case bo_key4:

    GiveKey (check->itemnumber - bo_key1);
    SD_PlaySound (KEYPICKUPSND);

    break;

    I think the first break must be inside the brackets, I'm not 100% sure right now...

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 2:04 pm

    Ugh. Nothing seems to be working. And I just noticed that now the code works on EVERY level I pick up a gold or silver key on. Sheesh. Maybe my if(gamestate.mapon==13) code is the problem.

    I was looking at this link too Boss and key drops. I tried using the "else" statement the way it appears in this code and still got the error "Misplaced else"....

    Ok, Andy I tried your latest code and that works. Only, every gold key in the game now has the sound effect and on screen message happen when I pick it up...



    http://jayngoware.com/

    Andy
    Seasoned Wolfer
    Seasoned Wolfer

    Number of posts : 280
    Registration date : 2007-12-22

    Re: Coding Help with Keys please

    Post by Andy on Fri Mar 26, 2010 2:11 pm

    If the 'break' is in the brackets, it should not go further. I did edit the code several times before my final post.
    Should there be a ';'(semicolon) after the if statement? Try removing that.

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 2:29 pm

    Ok, when I remove the semicolon after the if statement the sound and on screen message doesn't appear at all. For any gold keys on any levels.
    When I keep the semicolon after the if statement the sound and on screen message appears for all gold keys on all levels..

    So, I am thinking I am almost there, just maybe the (gamestate.mapon==13) is wrong or something?



    http://jayngoware.com/

    Andy
    Seasoned Wolfer
    Seasoned Wolfer

    Number of posts : 280
    Registration date : 2007-12-22

    Re: Coding Help with Keys please

    Post by Andy on Fri Mar 26, 2010 3:00 pm

    @jayngo26 wrote:Ok, when I remove the semicolon after the if statement the sound and on screen message doesn't appear at all. For any gold keys on any levels.
    When I keep the semicolon after the if statement the sound and on screen message appears for all gold keys on all levels..

    So, I am thinking I am almost there, just maybe the (gamestate.mapon==13) is wrong or something?
    That seems kind of odd. Ifs are not supposed to have semicolons after them, and if brackets follow an if, everything within the brackets should be executed if the condition in the if is met. Your if statement looks fine. There may be a typo in your code yet. Here is how I would do it (final version):

    Code:
    case bo_key1:

    if(gamestate.mapon==13) //episode 2 level 4
    {
    GiveKey (check->itemnumber - bo_key1);
    GiveExtraMan ();
    SD_PlaySound (ACHIEVESND);
    GetMessage("*FROM THE BELLY OF THE BEAST AWARD!*\\nExtra Man Added!");
    break;
    }

    case bo_key2:
    case bo_key3:
    case bo_key4:

    GiveKey (check->itemnumber - bo_key1);
    SD_PlaySound (KEYPICKUPSND);

    break;

    The bracketed stuff only gets executed if the mapon==13. It should also break so that the default key stuff doesn't happen aftterwards. If mapon is not 13, all keys should have the default behavior, and the break occurs then. Try cutting and pasting this, and do a 'rebuild all'. If that doesn't work, someone else will have to help us.

    Andy

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 3:41 pm

    I copy and pasted your code Andy and nothing happens when the gold key is picked up. No sound and no on screen message.
    I then added the semicolon back to the end of the "if" statement and now all gold keys play the sound and on screen message.

    This is very weird as I thought this code looked good. Thanks for trying. Maybe if somebody else read's this post we can figure out an answer to this...



    http://jayngoware.com/

    Andy
    Seasoned Wolfer
    Seasoned Wolfer

    Number of posts : 280
    Registration date : 2007-12-22

    Re: Coding Help with Keys please

    Post by Andy on Fri Mar 26, 2010 4:25 pm

    The switch structure only allows individual statements; apparently a "bracketed if" causes problems. Try this then:
    Code:
    case bo_key1:

    if (gamestate.mapon==13)
    GiveKey (check->itemnumber - bo_key1);
    if (gamestate.mapon==13)
    GiveExtraMan ();
    if (gamestate.mapon==13)
    SD_PlaySound (ACHIEVESND);
    if (gamestate.mapon==13)
    GetMessage("*FROM THE BELLY OF THE BEAST AWARD!*\\nExtra Man Added!");

    if (gamestate.mapon==13)
    break;

    case bo_key2:
    case bo_key3:
    case bo_key4:

    GiveKey (check->itemnumber - bo_key1);
    SD_PlaySound (KEYPICKUPSND);

    break;
    The only peculiar thing here (that may not work) is the conditional break.
    See: C++ Language Tutorial - Control Structures and scroll down to "The selective structure: switch" for more information.

    Andy

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Fri Mar 26, 2010 6:07 pm

    Ahh, that didn't work either Andy. With this latest code there is no sound or on screen message when the gold key is picked up. Thanks for all the help though.

    I don't have time right now to mess with this anymore, but I still think this might be a if/else answer.

    If anybody out there know's please help!



    http://jayngoware.com/

    Guest
    Guest

    Re: Coding Help with Keys please

    Post by Guest on Fri Mar 26, 2010 11:21 pm

    Hi Carl!



    Last edited by Chokster37 on Sat Feb 08, 2014 11:26 am; edited 1 time in total

    jayngo26
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    Re: Coding Help with Keys please

    Post by jayngo26 on Sat Mar 27, 2010 5:00 am



    Chokster-sometimes I think you do your best work when you are all "hopped up on madness".

    (gamestate.mapon + 10*gamestate.episode) == 13

    I knew my problem was within that line and I also had a sneaking suspicion that I needed an if/else. Thanks for immplementing it in the correct form. Oh, yah, and just so you know...it works!

    BUT, let's not forget that (gamestate.mapon + 10*gamestate.episode) == 13 << The 13 actually means 14. So, I guess that would mean that it IS NOT Friday the 13th and Satan was not here...



    http://jayngoware.com/

    Sponsored content

    Re: Coding Help with Keys please

    Post by Sponsored content Today at 12:24 pm


      Current date/time is Sat Dec 10, 2016 12:24 pm