PDA

Click to See Complete Forum and Search --> : Help. Trying To Make Game


XCustoms
Feb 8th, 2007, 04:28 PM
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:

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:

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

jeroen79
Feb 9th, 2007, 02:50 AM
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?

XCustoms
Feb 9th, 2007, 06:03 AM
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

kewakl
Feb 9th, 2007, 07:49 AM
in the host use this in the ConnectionRequest

If Sock.State <> sckClosed Then Sock.Close
Sock.Accept requestID


and in the client, the wrong car will move :D

XCustoms
Feb 9th, 2007, 08:14 AM
Haha Thnx Man, If You Need Help I'll Help You.
Even If i'm Not Good Programmer :)

kewakl
Feb 9th, 2007, 09:02 AM
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)

XCustoms
Feb 9th, 2007, 09:11 AM
Thnx :)
It says OverFlow I Did Something Wrong Lol.
I Know How To Fix :)

Thnx

kewakl
Feb 9th, 2007, 10:51 AM
what says overflow, what line is highlighted in VB?

XCustoms
Feb 10th, 2007, 12:17 PM
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

kewakl
Feb 10th, 2007, 08:23 PM
what line is highlighted in VB?

[EDIT] I do not know what changes you have made.

XCustoms
Feb 11th, 2007, 05:56 AM
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 :(

XCustoms
Feb 11th, 2007, 05:58 AM
This Is The Code:

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim CarPos1 As String
CarPos1 = Car1.Left
If Car1.Left >= "6480" Then
SPBar.Width = "15"
Mph.Caption = "0"
YW.Visible = True
ElseIf Car1.Left >= "6480" Then
SPBar.Width = "15"
Mph.Caption = "0"
YL.Visible = True
ElseIf Mph.Caption = "50" Then
Mph.Caption = "50"
Car1.Left = Car1.Left + Mph.Caption
Sock.SendData CarPos1
ElseIf KeyAscii = 119 Then
Car1.Left = Car1.Left + Mph.Caption
SPBar.Width = SPBar.Width + Mph.Caption
Mph.Caption = Mph.Caption + 1
Sock.SendData CarPos1
End If
End Sub

Private Sub Form_Load()
Sock.LocalPort = "3000"
Sock.Listen
YL.Visible = False
YW.Visible = False
End Sub

Private Sub Sock_ConnectionRequest(ByVal RequestID As Long)
If Sock.State <> sckClosed Then Sock.Close
Sock.Accept RequestID
End Sub

Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
Dim CarPos2 As String
Sock.GetData CarPos2
Car2.Left = CarPos2
End Sub

kewakl
Feb 11th, 2007, 10:11 AM
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...?

ElseIf Mph.Caption = "50" Then
Mph.Caption = "50"

is this to limit top speed to 50, then


ElseIf Mph.Caption > "50" Then
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.

XCustoms
Feb 11th, 2007, 06:32 PM
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.