Hello everybody. I am new to Squirrel, but have used a few other languages similar to it, like Lua and such.
My question is this: I am wanting to load vehicles using the script so I can add more data to it (like the owner of a vehicle, for example). As I am used to Lua, which I can create a table to store this data, I am not sure how this works in Squiirel. I am able to make the tables and such, but im not sure how to index them and create the vehicles. Here is what I have so far:
function LoadVehicleFromSQL() { sqlite_query(database,"ALTER TABLE vehicles AUTO_INCREMENT=1"); local amount = sqlite_query(database,"SELECT count(*) FROM vehicles"); local vehicle = 0; if(amount) { for(i = 1;i = amount;i++) { local query = sqlite_query(database,"SELECT model,x,y,z,a,color1,color2,owner,faction,job,locked,engine,lights FROM vehicles WHERE id = " + i); vData[i] <- {}; vData[i].Model <- sqlite_column_data(query,0); vData[i].X <- sqlite_column_data(query,1); vData[i].Y <- sqlite_column_data(query,2); vData[i].Z <- sqlite_column_data(query,3); vData[i].A <- sqlite_column_data(query,4); vData[i].Color1 <- sqlite_column_data(query,5); vData[i].Color2 <- sqlite_column_data(query,6); vData[i].Owner <- sqlite_column_data(query,7); vData[i].Faction <- sqlite_column_data(query,8); vData[i].Job <- sqlite_column_data(query,9); vData[i].Engine <- sqlite_column_data(query,10); vData[i].Lights <- sqlite_column_data(query,11); sqlite_free(query); vehicle = CreateVehicle(vData[i].Model,Vector(vData[i].X,vData[i],Y,vData[i].Z),vData[i].A,vData[i].Color1,vData[i].Color2); vehicle.Locked = vData[i].Locked; vehicle.SetEngineState = vData[i].Engine vehicle.LightState = vData[i].Lights } } } I am not sure how to index this table (should it be by the increment in the for loop, or by the instance created from the vehicle?)
The only conclusion I have about this is: I create the tables, and index them by ID, not the instance, then I could use vehicle.ID in the index like: vData[vehicle.ID].Model
Any help or information on this is greatly appreciated. I am probably doing it wrong, but Im not sure how to add other info to the vehicle instance (so it could be like vehicle.Owner, or vehicle.Price or something)
Thanks, WtF
|