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.
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?
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?
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.
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)
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.
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
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.