Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

EO3 Sending the contents of variables to and from client/server?


IFX
 Share

Recommended Posts

So my question is pretty much exactly the same as above. For simplicity I'll explain this quickly, using Q as my variable.

I have 3 If statements, checking to see if a player doesn't exist, if a player exists and is offline, and if a player exists and is online. 

and in each situation it sets "Q" to be a phrase. each phrase fitting the context. "I'm sorry, but the player is offline" or whatever else fits.

Now this is where I encounter the problem. I need to send "Q"'s context, what "Q" is set to be, to the client. And you cant just simply do "buffer.writestring Q", that errors. And Buffer.Writestring "Q" would just send the letter Q. So what do I do?

I've tried googling it a dozen different ways. and have come up dry. So is there a way to fix it? or do I just need 3 different buffers?
Link to comment
Share on other sites

If you want to send a message to the player from the client then there already exists a mechanism for this in the engine. The method is called PlayerMsg. It has normally 3 parameters index, the message and colour. Index is the player index, message the message and the colour is the colour you want to send the message in. The colour constants are found in… well modConstants. Search for Red or something in modConstants and you can see all the different colours. 

Now to answer how you would normally send data, the could would be something like this

```

Dim Buffer as ClsBuffer ' Declare our buffer
dim str as string, int as integer, bte as byte, lng as long
str = "A random string"
int = 1
bte = 2
lng = 3

Set = buffer new clsbuffer ' Create our buffer
buffer.writelong PacketHeader ' This is the packetheader variable. It usually starts with C or S
buffer.writestring str ' Write a string (2 bytes / char + 4 bytes for the length of the string)
buffer.writebyte bte ' Write a byte (1 byte)
buffer.writelong lng ' Write a long (4 bytes)
senddatato index, buffer.toarray ' Convert the buffer to a byte array and send it to the player ' with the given index
set buffer = nothing ' Free memory

```
For reading you'd do something like this **variable = buffer.readlong**. It can be ReadLong, ReadString, ReadByte or ReadInteger. 

For now, you don't need to understand how the clsBuffer class works…. it just works. As you progress learning VB6 you'll figure it out.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...