The online racing simulator
How would I go about flagging multiple styles for a button?

For example, if I wished to set it dark with left align. Is there any way to send both ISB_DARK and ISB_LEFT?

Quote from DarkTimes :Bitwise OR operator



Great job on the lib by the way.

I was a bit intimidated by the workings of insim before, dealing with packets etc. - but this has been a great tool to work from to understand how things work.

Sure, no problem.

I updated pyinsim for InSim 5. As always it's on CodePlex.
I have no freaking idea what is casuing this, but it's bothering me, and hopefully you can help

I don't know what I did or didn't do to cause this. But here's the thing:
I have all my imports at the beginning of my file. Including import time for a lottery system. Problem is, when I try to use it, unless I have import time in the chunk of code for the cmd_lottery, I get an error that crashes the insim.
AttributeError: 'int' object has no attribute 'time'

It's bothering me. Any ideas why this would happen DarkTimes?
Sounds like a scope issue, is there a variable named time somewhere? It sounds like you're redefining the variable time to be an int.

Like this:

import time

# Redefine time to be an int
time = 10

# AttributeError: 'int' object has no attribute 'time'
print time.time()

#82 - SJB
Just started developing with pyinsim yesterday, its great!

How can I get the username of someone who wrote something? I got the mso.UCID and mso.PLID but how does the query for the username looks like?

Regards, SJB
You need to store the connection list that is sent by the game and then you can pull information out of that when you need it. Have a look at the '' script in the examples folder.
Quote from DarkTimes :Sounds like a scope issue, is there a variable named time somewhere? It sounds like you're redefining the variable time to be an int.

Like this:

import time

# Redefine time to be an int
time = 10

# AttributeError: 'int' object has no attribute 'time'
print time.time()

I can't seem to find the problem. Can I PM you the code to see if you can find the issue?
Any plans to update Pyinsim for the new insim packets?
Yeah, sorry, I've been busy. I added the new packets to the repository a week or so ago, but I've not had time to test them yet. I'll try and do that today.
Heya, I've pushed a release onto CodePlex for pyinsim 2.0.4.

  • Updated to LFS 0.6B
  • Now deals better with corrupt packets
  • General tweaks
I've tested the packets and they seem to work OK, but let me know if you have any problems. I removed a lot of unnessesary stuff from and there's a chance I might have removed something important by mistake. Hopefully not...

Here is an example that prints out the contents of each AutoX object whenever a layout is loaded or edited.

import pyinsim

def autox(insim, axm):
# Print out each object.
for obj in axm.Info:
print vars(obj)

# Init InSim with AXM flags.
insim = pyinsim.insim('', 29999, Admin='',

# Bind AXM event.
insim.bind(pyinsim.ISP_AXM, autox)

# Start the packet receive loop.

Here is an example of setting the player cars to open-wheelers only.

import pyinsim

# Init InSim.
insim = pyinsim.insim('', 29999, Admin='')

# Set all player cars to open-wheelers.
insim.send(pyinsim.ISP_PLC, UCID=255,

# Receive packets.

If you need examples of other stuff, give us a shout, although it should be pretty self-explanatory.
Incidentally, as some people have worked out, you can follow pyinsim (and InSim.NET) on CodePlex to get automatic email notifications whenever a new version is released. Just sign up to CodePlex and click the 'follow' button above the releases panel. I use this for other projects I'm interested in, it's quite useful actually.
DarkTimes I love you! Thanks for the update!
Quote from learjet45 :DarkTimes I love you! Thanks for the update!

DarkTimes is on the cusp of getting groupies.
Hey if people wanna love me I'm not gonna complain!

In seriousness though, I do spend a lot of hours working on these programs with very little feedback, so I'm grateful that people do occasionally find them useful.
I've been wanting to do an example of using a database with pyinsim for a while, so I knocked up a quick script today. It's a simple lapper app that tracks a users fastest lap on track and stores it in a SQLite database. SQLite is great for this as it comes as part of the Python installation, meaning you don't need to do any setup to use it. Right now the script is very simple, it just sends a message whenever you cross the start/finish line, but I hope to update it more when I have some free time. I'm not a database whizz, so my SQL code might not be the best, but for as simple an app as this it should suffice.

import sqlite3
import pyinsim

# Constants.
DB_NAME = 'lapper.db'
HOST = ''
PORT = 29999
ADMIN = ''
NAME = 'PyLapper'

# Class to represent the database.
class LapperDB(object):
def __init__(self, db_name):
self.db_name = db_name

def __enter__(self):
self.db = sqlite3.connect(self.db_name)
self.db.text_factory = str # Set text-mode to ASCII
self.db.row_factory = sqlite3.Row
return self

def __exit__(self, type, value, traceback):

def table_exists(self, table_name):
return self.db.execute('SELECT name FROM sqlite_master WHERE name=?', [table_name]).fetchone()

def init_db(self):
# Create laps table if it does not exist.
if not self.table_exists('laps'):
self.db.execute('CREATE TABLE laps (uname TEXT, track TEXT, car TEXT, ltime INT)')

def get_lap(self, uname, track, car):
conn = self.db.execute('SELECT ltime FROM laps WHERE uname=? AND track=? AND car=?', [uname, track, car])
return conn.fetchone()

def add_lap(self, uname, track, car, ltime):
self.db.execute('INSERT INTO laps (uname, track, car, ltime) VALUES (?, ?, ?, ?)', [uname, track, car, ltime])

def update_lap(self, uname, track, car, ltime):
self.db.execute('UPDATE laps SET ltime=? WHERE uname=? AND track=? AND car=?', [ltime, uname, track, car])

def commit(self):
# Save changes to database.

# Globals.
connections = {}
players = {}
track = None

def joined_multiplayer(insim, ism):
# When joined host ask for all players/connections.
insim.send(pyinsim.ISP_TINY, SubT=pyinsim.TINY_NCN, ReqI=1)
insim.send(pyinsim.ISP_TINY, SubT=pyinsim.TINY_NPL, ReqI=1)

def state_changed(insim, sta):
# Keep track of current track.
global track
track = sta.Track

def new_connection(insim, ncn):
connections[ncn.UCID] = ncn

def connection_left(insim, cnl):
del connections[cnl.UCID]

def new_player(insim, npl):
players[npl.PLID] = npl

def player_left(insim, pll):
del players[pll.PLID]

def lap_completed(insim, lap):
# Get player/connection from list.
npl = players[lap.PLID]
ncn = connections[npl.UCID]

# Open DB connection.
with LapperDB(DB_NAME) as db:
# Get lap for this car/track.
row = db.get_lap(ncn.UName, track, npl.CName)
if not row:
# No lap exists.
db.add_lap(ncn.UName, track, npl.CName, lap.LTime)
insim.sendm('first lap on %s/%s' % (track, npl.CName), ncn.UCID)
elif lap.LTime < row['ltime']:
# New fastest lap.
db.update_lap(ncn.UName, track, npl.CName, lap.LTime)
insim.sendm('fastest lap: %s' % pyinsim.timestr(lap.LTime), ncn.UCID)
# Slower lap.
insim.sendm('slower lap: %s' % pyinsim.timestr(lap.LTime), ncn.UCID)

def error(insim, err):
print 'Error:', err

def closed(insim):
print 'Error: no host connected'

def init(insim):
print 'Connected to host (%s:%d)' % (insim.hostaddr[0], insim.hostaddr[1])

def main():
print NAME
print ''.rjust(len(NAME), '-')

# Init DB and create laps table.
print 'Initializing database...',
with LapperDB(DB_NAME) as db:
print 'done'

# Init InSim and bind events.
insim = pyinsim.insim(HOST, PORT, Admin=ADMIN, IName=NAME)
insim.bind(pyinsim.EVT_ERROR, error)
insim.bind(pyinsim.EVT_CLOSE, closed)
insim.bind(pyinsim.EVT_INIT, init)
insim.bind(pyinsim.ISP_ISM, joined_multiplayer)
insim.bind(pyinsim.ISP_STA, state_changed)
insim.bind(pyinsim.ISP_NCN, new_connection)
insim.bind(pyinsim.ISP_CNL, connection_left)
insim.bind(pyinsim.ISP_NPL, new_player)
insim.bind(pyinsim.ISP_PLL, player_left)
insim.bind(pyinsim.ISP_LAP, lap_completed)

# On connecting request state and host packet.
insim.send(pyinsim.ISP_TINY, SubT=pyinsim.TINY_SST, ReqI=1)
insim.send(pyinsim.ISP_TINY, SubT=pyinsim.TINY_ISM, ReqI=1)

# Start packet receive loop.

if __name__ == '__main__':

I'm sure I've linked to this before, but this is an excellent free Python ebook. This was the tutorial that taught me how to code Python. I wrote the first version of pyinsim about an hour after I starting reading this.
I love you even more. <3

And with that you've inspired me to work on connecting python and a MySQL database as I know absolutely nothing about SQLite with PHP, but I have enough crappy PHP code that used MySQL databases that I might be able to do something with it.
SQLite is basically just a cut down version of SQL. It allows you to add a simple file based database to your app without having to worry about the complexities of setting up a proper SQL server. Apart from a few different API calls and a few missing commands, SQLite should be extremely familiar to anyone who's used MySQL or MSSQL. Also it's built into the Python standard library, which means there is absolutely no configuration required to start using it, you just import the sqlite3 module and start executing commands.

For .NET there is SQL Compact, which is the cut-down version of Microsoft SQL Server, which is basically the same thing and is built into the .NET 4.0 API.
Quote from DarkTimes :An extension that turns Visual Studio 2010 into a Python IDE. Supports IronPython and CPython.

They've released a new update for this. It's actually getting quite good, although the autocomplete still isn't perfect and it still has one or two bugs. I might move development of pyinsim from Eclipse PyDev to Visual Studio now, as I can keep all my projects together and I really like the Visual Studio Mercurial plugin. The Mercurial plugin for Eclipse is so confusing I can't understand how to use it.
Er anyone els having a issue getting onto or ????

The site is not loading and i just get the following

Oops! Google Chrome could not connect to
Try reloading: www.*python.*org/*getit/*releases/*3.*2/*
Additional suggestions:
Access a cached copy of www.*python.*org/*getit/*releases/*3.*2/*
Search on Google:

Now i know my internet is fine because im on LFS forum lol !!

Any place i can download it ?

Edit that lol. i found it on a site called FILEHIPPO lmao