Results 1 to 15 of 15

Thread: Direct Play - Doesn't like loops!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Unhappy Direct Play - Doesn't like loops!

    Hi, I made a small program to test out direct play, however if I use a loop, direct play doesn't send or recieve messages. How can a game not have at least one loop? What I do is setup a loop to check for the GetKeyState and then move some picture around. Direct Play doesn't recieve this, however when I take out the loop and just use click events or keydown, everything works fine. There must be a trick to this Can someone help me please? Thanks.

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Have a DoEvents in your loop?

    Z.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Yep, lots

  4. #4
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Maybe if you posted the code? I have no problems using DirectPlay with a game loop.

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by Machaira
    Maybe if you posted the code? I have no problems using DirectPlay with a game loop.
    That's my reaction as well, though im running a regular winsock system, instead of DPlay =).

    Z.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Unhappy

    Ok, it goes like this:

    Code:
    Sub MainLoop()
    Do
    DoEvents
    
    
    Show
    'If GetKeyState(vbKeyLeft) < -5 Then SendM
    'If GetKeyState(vbKeyLeft) < -5 Then SendM2
    If GetKeyState(vbKeyLeft) < -5 Then ML1
    'If GetKeyState(vbKeyLeft) < -5 Then ML2
    If GetKeyState(vbKeyEscape) < -5 Then End
    
    DoEvents
    Loop
    End Sub
    So it checks to see if the left key is pressed it it is go to ML1

    Code:
    Sub ML1()
    Dim dpMsg As DirectPlayMessage
    
    If gPlayerIDs(1) Then
    Picture1.Left = Picture1.Left - 10
    
    Set dpMsg = gObjDPlay.CreateMessage
            'Call dpMsg.WriteLong(MSG_TURNGREEN)
            Call dpMsg.WriteLong(MSG_MOVEp)
            Call gObjDPlay.Send(gMyPlayerID, DPID_ALLPLAYERS, DPSEND_GUARANTEED, _
            dpMsg)
            
    End Sub
    It checks if the player ID is 1 then allow for the picture movement and send a message to the other computer.

    This is basically it, everything else I don't need to post because it works, just without the loop. So If I took out mainloop and added click events or key down events on the picture and still keep the exact same code for ML1 then everything works. Its just the loop. Any ideas?

    Thanks.

  7. #7
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    You're not checking to see if the player ID is 1, you're checking to see if the value of element 1 in the gPlayerIDs array is True. That's assuming of course that gPlayerIDs is an array. How are you checking for messages?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    I know about the player ID thing, Ive changed it already and it works now. But sending/recieving still doesn't work with a loop

    Basicly in a big public sub in a module I declate some stuff, but basically its:

    Code:
        Select Case MsgType 
    Case MSG_MOVEp
               frmGameBoard.Picture1.Left = frmGameBoard.Picture1.Left - 10
               
               Case MSG_MOVEp2
              frmGameBoard.Picture2.Left = frmGameBoard.Picture2.Left - 10
    thats all to it. I don't see how a loop affects it but it does.

  9. #9
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    I dont think anyone is going to be able to help you, unless you post your project (or rip out everything but the dplay stuff, and post that). Otherwise we are just grabbing at straws.

    Z.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Question

    Ok, sorry about that, sometimes I'm just not cofortable posting entire projects cause its kind of asking too much Here it is anyways. It based entirely on MS's Memory Game, the only thing I did was take out the logic of that game and place my own logic (click on the red and green pictures to make them move left) and added a loop(which makes everything not work)

    Thanks again.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Forgot the attachment
    Attached Files Attached Files

  12. #12
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Whew, there are a bunch of potential problems. I did change some things, but I don't have the time to fix them all. The chat works from the host to the other player, but it won't work the other way since you never update the global variable holding the number of players on the non-host player, so the chat form can never be shown.

    Also, the loop in the game board form is unnecessary and caused problems. Entering a loop while the Load event is firing is a serious no-no.

    Another thing - NEVER, repeat, NEVER use End to stop an application that is ending normally. ALWAYS, unload all the forms and destroy any objects as necessary. If the original used End, they should be shot.

    I haven't looked at this example in ages, so I'm not sure what you changed from the original.
    Attached Files Attached Files

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Question

    Hey thanks, but that still doesnt solve my problem. Later on I want to port this code into my game this is why I need it to work with a loop. Is it possible to have two loops? What if I added another loop into the Globals module because the one thats already there only works "While MsgCount > 0" I need another loop that will work all the time. How can I put in two loops? Thanks.

    P.S I'll make note to not put END to stop an application

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Ok never mind, I didn't realize there was already a second loop in there. Haha

    Thanks anyways.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Unhappy

    Ah no, the "while MsgCount > 0" affects my second loop. It screws up the pictures. For example, if you are the host, you are allowed to move picture1, but on the other computer the second picture moves and vise versa. Any ideas on how to take out that WHILE thing? If I take it out I get an error that MS built in for error checking.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width