The online racing simulator
Help about the coordinates stuff python
I managed to get the hello insim program working. How could I now do almost the same program but that shows me coordinates that my car is. I should use MCI packet, but I don't know exactly how. :/ Could anyone help me.

I tried to change the MSTs to MCI but that didn't work. :S
Here is the original Hello insim program:

import pyinsim

# Initialize InSim.
insim = pyinsim.insim('127.0.0.1', 29999, Admin='password')

# Send message packet to LFS.
insim.send(pyinsim.ISP_MST, Msg='Hello, InSim!')

# Run pyinsim.
pyinsim.run()

Quote from martzz :I managed to get the hello insim program working. How could I now do almost the same program but that shows me coordinates that my car is. I should use MCI packet, but I don't know exactly how. :/ Could anyone help me.

I tried to change the MSTs to MCI but that didn't work. :S
Here is the original Hello insim program:

import pyinsim

# Initialize InSim.
insim = pyinsim.insim('127.0.0.1', 29999, Admin='password')

# Send message packet to LFS.
insim.send(pyinsim.ISP_MST, Msg='Hello, InSim!')

# Run pyinsim.
pyinsim.run()


Firstly you need to enable MCI updates when you create the InSim connection.

insim = pyinsim.insim('127.0.0.1', 29999, Flags=pyinsim.ISF_MCI,
Interval=1000, Admin='password')

This tells LFS to send MCI packets once every 1000 milliseconds (1 second). Next you need to give pyinsim a function to call when a MCI packet is received.

def multi_car_info(insim, mci):
for info in mci.Info:
print 'X: %d Y: %d Z: %d' % (info.X, info.Y, info.Z)

insim.bind(pyinsim.ISP_MCI, multi_car_info)

The MCI handler loops through each car in the packet and prints out its XYZ coords. The full example would be:

import pyinsim

def multi_car_info(insim, mci):
for info in mci.Info:
print 'X: %d Y: %d Z: %d' % (info.X, info.Y, info.Z)

insim = pyinsim.insim('127.0.0.1', 29999, Flags=pyinsim.ISF_MCI,
Interval=1000, Admin='password')

insim.bind(pyinsim.ISP_MCI, multi_car_info)

pyinsim.run()


Big thanks to you!

FGED GREDG RDFGDR GSFDG