The button works for me, although it's quite hard to see on some screens as it's set to have a T of only 4, which sometimes causes it to get hidden by other screen elements. You need to set the T to a value > than 30 in order for it to be within the recommended visible area. Try setting it to a T of 40 or something, you can see it fine.
It still doesn't work. I saw youur post yesterday or so and there was a piece of code to get the UCID's from players connecting, maybe it could work then.
But it should work even with 255 - to all players, I don't know, maybe it's because I am running it from 127.0.0.1 and not from the host IP
I did post a reply which was incorrect, so I deleted it. I forgot that setting the UCID to 255 sent the button to everyone on the host.
The code works fine for me as it is. If I copy and paste your code into a new project, add a reference to Spark, start LFS and hit run, I can see the button on the menu screen. I'm not sure what problem you're having.
Well... I am the biggest .NET / c# ever I guess...
I have just downloaded and installt MS Visual Studio 2010 for C#.
But I even cannot get Example1 working... What do I have to do with the spark.dll?? Where do I have to copy it and how do I activate it?
In my first attempt I just unzipped it right on the desktop, started a new project, copy/pasted your example code, rightclicked on the project and clicked "Add Reference" then I selected the spark.dll in the "seach" tab.
But when I start the project (F5) I am getting error messages.
Well at home all worked well - but today at work I am getting that error messages again with the same source (carried it with an USB stick)...
I am using the German version - so my error message translated from me in to English might differ...
I am getting error messages about missing Spark.. - Spark cannot be found - although it´s there and addet... (see attachments)
However... could you give a hint, how to print out splits too with example4? I also would like to only log the driver specified by license name in a config file. But the LAP package only provides PName to compare - and not UName. I tried to bind the NCN and CNL packages too and to store them in a dictionary too - but I did not find a way to store the PName in a variable from the UName taken from the config file...
Here is what I - and a team mate did so far:
using System; using System.IO; using System.Collections.Generic; using Spark; using Spark.Helpers; using Spark.Packets; using System.Xml;
namespace Spark.Example4 { /// <summary> /// Example 4: Helpers. Connects to InSim, requests all players to be sent, the prints out /// the time of each player that completes a lap. /// </summary> class Program { // We store the players in a dictionary with the PLID as the key. // also store connections in a dict with UCID as the key. static InSim _insim; static int c = 0; static string pname; static string lname; static string port; static string logfile; static Dictionary<int, IS_NPL> _players = new Dictionary<int, IS_NPL>(); static Dictionary<int, IS_NCN> _conns = new Dictionary<int, IS_NCN>();
static void Main() {
//specify the config file XmlReader reader = XmlReader.Create("config.xml");
//openeing the main instance reader.ReadStartElement("config");
//reading the needed values in to a variable and closing the element reader.ReadStartElement("name"); lname = reader.ReadString(); reader.ReadEndElement();
reader.ReadStartElement("port"); int port = Convert.ToInt32(reader.ReadString()); reader.ReadEndElement();
//closing the main instance reader.ReadEndElement();
// Create new InSim object. using (_insim = new InSim()) { // Bind handlers. _insim.Bind<IS_ISM>(MultiPlayerInfo); _insim.Bind<IS_NPL>(NewPlayer); _insim.Bind<IS_PLL>(PlayerLeft); _insim.Bind<IS_LAP>(Lap); _insim.Bind<IS_NCN>(NewConn); //added to get a package with UName _insim.Bind<IS_CNL>(ConnLeft); //added to get a package with UName
// Establish the InSim connection. _insim.Connect("127.0.0.1", port);
// Initialize InSim. // Read racer name from file //first attampt to specify a single racer (me) only //StreamReader streamReader = new StreamReader("name.txt"); //lname = streamReader.ReadToEnd(); //pname = _conns[lname.UCID]; //tried to set pname from _conns Dictionary - but does not work //streamReader.Close();
static void MultiPlayerInfo(IS_ISM ism) { // When joined multiplayer request for all players to be sent. _insim.Send(new IS_TINY { ReqI = 255, SubT = TinyType.TINY_NPL }); _insim.Send(new IS_TINY { SubT = TinyType.TINY_NCN, ReqI = 255 }); //not sure if needed when binding NCN package }
static void NewPlayer(IS_NPL npl) { if (_players.ContainsKey(npl.PLID)) { // Leaving pits, just update NPL object. _players[npl.PLID] = npl; } else { // Add new player. _players.Add(npl.PLID, npl); } }
static void PlayerLeft(IS_PLL pll) { // Remove player. _players.Remove(pll.PLID); }
static void Lap(IS_LAP lap) { // Get the player who has completed the lap. var npl = _players[lap.PLID]; // Get lap number. var done = lap.LapsDone; // Get lap time string. var ltime = StringHelper.TimeString(lap.LTime); DateTime dt = DateTime.Now; // Print to console. //if (npl.PName == pname) //deactivated because using PName is not easy to type in name.txt and UName is not available in LAP package { Console.WriteLine("{0} | lap#: {1} | Laptime: {2}", npl.PName, done, ltime); //just activated for debugging using (System.IO.StreamWriter file = new System.IO.StreamWriter(@logfile, true)) { file.WriteLine("{0} | lap#: {1} | Laptime: {2}", npl.PName, done, ltime); } } }
//counting c - but no need any more I guess static int counter() { c++; return (c); } } }
Yes of course it's possible. System timers are part of System and not the InSim protocol reference. It should work somewhat the same way as on LFS_External, just by modifying it to suit the Players list, from Spark.
Or you could just use the Connections list handler from LFS_External to make it all super-easy for you!
Yes, it works perfectly in a GUI app (that's kinda what it's designed for). You should not call the InSim.Run() method though, as it says in the method intellisense you should only use it in a Console application (and even then it's optional).
Exactly why it is closing I don't know, but I would imagine that an exception is being thrown on the background thread, likely a cross-thread exception. You should hook up an event to InSimError and see what, if anything, is being thrown. Otherwise you may need to debug it.
In fact I addressed the InSim.Run() and cross-thread issues before.
Did you hook up an event to InSimError to catch any background exceptions? You might need to post your source code, or at least some code that reproduces the problem.
hey darktimes i tried to use your spark cruise code but my problem is loading the database when i close and re-open it the database doesn't even load its like reset to zero. somehow im finding out the Close Save Users.
I have to say, this library is everything I expected it to be and more(literally, more) from my experience with it the last 3 days.
For those 3 days, I just had the best coding experience I've ever had so far. I totally love this library. This is why you're one of my idols, DarkTimes.
As for running it in a GUI application - I did just that. But I made a new project, if that matters. I never had to execute the .Run command tho.
And, since my InSim knowledge is not very wide, may I have my moment of dullness, please: Does setting a MCI interval mean that the connection will be kept alive, or do I have to send a packet from the app's side too? So far, from my experience, this is enough, but I'm not sure if it is the right way of doing it.
Spark keeps the connection alive automatically. The interval specifies the number of milliseconds between MCI or NLP packets, so an interval of 500 would be one packet every half second. If you're not using MCI/NLP packets you can set the interval to zero.
How are you exiting the program? If you run it in debug mode and close it by just ending the debug session, the database won't be saved. Also when you rebuild the app it will overwrite the database, but you can change that by right-clicking on SparkCruise.sdf in the Solution Explorer, selecting Properties and setting the Copy to Output Directory option to Copy if newer.
I might rewrite the cruise example, as I've learned a crap-bunch about the Entity Framework since I originally wrote it.