Results 1 to 14 of 14

Thread: Help. Trying To Make Game

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Help. Trying To Make Game

    Hello I Need A Bit Help Please.
    Tryed To Code This For 1 Week Still Doesnt Work.
    I Almost Done It. this Is My Code

    Hoster:

    Code:
    Privat Sub Form_Load()
    Sock.LocalPort = "3000"
    Sock.Listen
    End Sub
    
    Privat Sub Form_KeyPress(KeyAscii As Integer)
    Dim CarPos1 As String
    CarPos1 = Car1.Top
    If KeyAscii = 119 Then
    Car1.Top = Car1.Top - 10
    Sock.SendData CarPos1
    End If
    End Sub
    
    Private Sub Sock_ConnectionRequest(ByVal requestID As Long)
    Sock.Accept requestID
    End Sub
    
    Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
    Dim CarPos2 As String
    Sock.GetData CarPos2
    Car2.Top = CarPos2
    End Sub
    Client:

    Code:
    Privat Sub Form_Load()
    Sock.RemoteHost = "83.84.250.99"  ' My IP Address
    Sock.RemotePort = "3000"
    Sock.Connect
    End Sub
    
    Privat Sub Form_KeyPress(KeyAscii As Integer)
    Dim CarPos2 As String
    CarPos2 = Car2.Top
    If KeyAscii = 119 Then
    Car2.Top = Car2.Top - 10
    Sock.SendData CarPos2
    End If
    End Sub
    
    Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
    Dim CarPos2 As String
    Sock.GetData CarPos2
    Car2.Top = CarPos2
    End Sub
    
    Private Sub Sock_Connect()
    MsgBox("Connected")
    End Sub
    Theres An Error On It. But I Dont Know What It Is
    Could Someone Please Help Me Thnx

  2. #2
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Help. Trying To Make Game

    What is it supposed to do?
    What is it not doing?
    If there is an error, what does it say?
    Have you used the debugger on the client and the server to see what is going on?
    Why do you first put car2.top in carpos2, then change car2.top and then send carpos2 on the client?
    Why do you first put car1.top in carpos1, then change car1.top and then send carpos1 on the server?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    I'm Trying To Make A Kind Of Drag Racing Game.
    When I Press The W Button It Goes Forward
    Then It Sends The Position Of The Hoster
    and On The client It Send The Psition Of the Client

    So Like An Online Drag Racing Game

    Car1 Is An Picture
    Car2 Is An Picture

    When I Connect With The Client To Hoster It Says
    Run-Time error '40020' Or Something

  4. #4
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Help. Trying To Make Game

    in the host use this in the ConnectionRequest

    VB Code:
    1. If Sock.State <> sckClosed Then Sock.Close
    2. Sock.Accept requestID


    and in the client, the wrong car will move

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    Haha Thnx Man, If You Need Help I'll Help You.
    Even If i'm Not Good Programmer
    Last edited by XCustoms; Feb 9th, 2007 at 09:25 AM.

  6. #6
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Help. Trying To Make Game

    you'll need to check the Sock.State before sending anything.

    when exiting, each player window should send some sort of *closing* message to the other player window and catch it in the Sock_DataArrival sub, so the other Player socket control will know about the close.(the first player to exit should do this, it would be pointless for the second to do it)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    Thnx
    It says OverFlow I Did Something Wrong Lol.
    I Know How To Fix

    Thnx

  8. #8
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Help. Trying To Make Game

    what says overflow, what line is highlighted in VB?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    Hello, The Game Works Perfect
    Realy Funny, I Added Speed Meter On It

    But The Only Problem Is It Says Overflow

    It Says Overflow When I Hold The "W" Button
    Is It Fixable ?

    When I Tick The "W" Button Slowly Then It Works
    But Then The Game Is Not Cool.

    Maybe Its That It Sends the Pssition Of The Car Too Fast

    But Is It Fixable ?

    Thnx

  10. #10
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Help. Trying To Make Game

    what line is highlighted in VB?

    [EDIT] I do not know what changes you have made.
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    Wel I Cant See What It HighLighet
    When I Play Multiplayer On 1 PC Then It Works Perfect.

    When I Play With Someone Else Then It Says OverFlow
    (OverFlow When I Hold W Button)

    If I Tap W Button It Works Perfect. But Its Not Cool Then

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    This Is The Code:

    VB Code:
    1. Private Sub Form_KeyPress(KeyAscii As Integer)
    2. Dim CarPos1 As String
    3. CarPos1 = Car1.Left
    4. If Car1.Left >= "6480" Then
    5. SPBar.Width = "15"
    6. Mph.Caption = "0"
    7. YW.Visible = True
    8. ElseIf Car1.Left >= "6480" Then
    9. SPBar.Width = "15"
    10. Mph.Caption = "0"
    11. YL.Visible = True
    12. ElseIf Mph.Caption = "50" Then
    13. Mph.Caption = "50"
    14. Car1.Left = Car1.Left + Mph.Caption
    15. Sock.SendData CarPos1
    16. ElseIf KeyAscii = 119 Then
    17. Car1.Left = Car1.Left + Mph.Caption
    18. SPBar.Width = SPBar.Width + Mph.Caption
    19. Mph.Caption = Mph.Caption + 1
    20. Sock.SendData CarPos1
    21. End If
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. Sock.LocalPort = "3000"
    26. Sock.Listen
    27. YL.Visible = False
    28. YW.Visible = False
    29. End Sub
    30.  
    31. Private Sub Sock_ConnectionRequest(ByVal RequestID As Long)
    32. If Sock.State <> sckClosed Then Sock.Close
    33. Sock.Accept RequestID
    34. End Sub
    35.  
    36. Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
    37. Dim CarPos2 As String
    38. Sock.GetData CarPos2
    39. Car2.Left = CarPos2
    40. End Sub

  13. #13
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Help. Trying To Make Game

    can't reproduce error.

    which line errors?

    --also
    why check for Car1.Left >= "6480" twice - maybe the second one should be Car2.

    what do you mean by...?
    VB Code:
    1. ElseIf Mph.Caption = "50" Then
    2. Mph.Caption = "50"

    is this to limit top speed to 50, then

    VB Code:
    1. ElseIf Mph.Caption > "50" Then
    2. Mph.Caption = "50"

    Note: Mph.Caption is a STRING and in the line 'Car1.Left = Car1.Left + Mph.Caption'
    you are ADDING the STRING to a SINGLE. VB will coerce the datatypes to work, but this could develop into a habit that can introduce errors, especially whan you add a string that doesn't have a numeric value.
    Last edited by kewakl; Feb 12th, 2007 at 05:55 AM. Reason: fix closing vbcode tags
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Help. Trying To Make Game

    Oooooo Yeh Thats Why I Never Lose Lol.
    Yeh Its Hard With Programming Lol.

    I Think I Try To Make It With C++ (Hopes I Can Do It)
    I Know 0.5% About C++ Lol.

    Gonna Start To Learn.

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