RecvNetMsg.htm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>RecvNetMsg()</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. None.
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. First off, this ONLY works when you have joined a network game via StartNetGame or JoinNetGame and you have created a player via CreateNetPlayer (you must create a player, even if it is just to lurk). <br />
  21. <br />
  22. This returns a TRUE value if a message was received, FALSE if none has been received. This will typically go inside a function that is constantly being checked for message and decode and handle them. You will use NetMsgType, NetMsgFrom, NetMsgTo, and NetMsgData$ to get the important information from the message and act on it. <br />
  23. <br />
  24. The example requires that you run it on a remote machine while the local computer runs the example in the SendNetMsg command.
  25. </td>
  26. </tr>
  27. </table>
  28. <h1><a href=../2d_examples/RecvNetMsg.bb>Example</a></h1>
  29. <table>
  30. <tr>
  31. <td>
  32. ; RecvNetMsg() example <br />
  33. ; -------------------- <br />
  34. ; Run this program on the REMOTE computer to 'watch' <br />
  35. ; the activity of the SendNetMsg example. Run that <br />
  36. ; example on local machine. <br />
  37. ; <br />
  38. ; This program will tell you when a player involved in <br />
  39. ; the game hits a wall ... <br />
  40. <br />
  41. ; We'll use this instead of JoinHostGame - make it easier <br />
  42. StartNetGame() <br />
  43. <br />
  44. ; Create a player - a player must be created to <br />
  45. ; receive mesages! <br />
  46. playerID=CreateNetPlayer("Shane") <br />
  47. <br />
  48. ; Loop and get status <br />
  49. While Not KeyHit(1) <br />
  50. <br />
  51. ; Check to see if we've received a message <br />
  52. If RecvNetMsg() Then <br />
  53. <br />
  54. ; if we did, let's figure out what type it is <br />
  55. ; we know it will be a user message, though <br />
  56. msgType=NetMsgType() <br />
  57. <br />
  58. ; 1-99 means a user message <br />
  59. If msgType>0 And msgType<100 Then <br />
  60. <br />
  61. ; Let's see who the message was from <br />
  62. msgFrom=NetMsgFrom() <br />
  63. <br />
  64. ; Let's get the message! <br />
  65. msgData$=NetMsgData$() <br />
  66. <br />
  67. ; Print the message <br />
  68. Print msgData$ <br />
  69. End If <br />
  70. End If <br />
  71. Wend <br />
  72. </td>
  73. </tr>
  74. </table>
  75. <br>
  76. <a target=_top href=../index.htm>Index</a><br>
  77. <br>
  78. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=RecvNetMsg&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  79. </html>