My problem is really simple. My school is having an open house and I promised to do a simple driving game so people can play it there. The idea is to have some kind of championship and reward the fastest driver.
I have two problems with it:
I need a timer for it. How can I make it and is it even possible.
I would need to have the lap time to be shown in the end and the player to be able to write his/her name and phone number and they should be saved on the computer or on a server.
Is it possible to make this kind of game or am I doomed to fail.
I don’t mean to rush anyone, but I would like to have an answer soon. I only have time till next Friday to do it and if it’s not possible with blender, then I have to search for an alterative ways to do it.
It’s definitely possible. For a basic timer, you CAN use a timer property (just add a property to the object and make it of type “Timer” instead of “int”). If you want to save a lap time, when the player completes a lap just copy that property (via python or a copy property actuator) to another variable (probably something called “lap1”).
Saving scores is going to require python, but it most definitely can be done. Look up Python’s Pickle module, which I believe has read/write capabilities. There are also a ton of save/load scripts on this forum, just use the search feature.
OK! I got the timer now and it works fine. Now there is just the little problem with saving those laptimes. I’m really a noob and this is really annoying. I have tried to display the fastest laptime under the current laptime but I don’t really know how to do it. and I would really appreciate if anyone could tell me how to do it. Also I tried to find out if there is a way to ask the player his phone number and name and save those and his laptime.
I tried those and the text input was easy, but I really can’t get the saving part work. I need to get the laptime and player name and phone number in the same txt file so I can then use MySQL to move it on the server. Can anyone help me with this?
You can edit a MySQL database directly with Python, I just don’t know how to do it. I wish I would have picked up that book on writing web applications with Python at the library’s used book sale a couple of weeks ago…
Anyway, could you share the Python script you are using to read from and write to text files? It’s hard to know why it isn’t working for you without being able to see what you’ve got going.
I then tried to change it to meet my needs, but it would have been easyer if I knew what it actually does on every line. I am really noob with python and I know just the basics of Blender. This wouldn’t be a problem if I had more time, but I only have this week. It MUST be done before Friday.
This is the code I tried to change to meet my needs. I got it from a tutorial:
### Add objects to be saved to this list ###
cube = GameLogic.getCurrentScene().getObjectList()["OBCube"]
cubePosi = cube.getPosition()
cubeRot = cube.getOrientation()
### Open the file "Game1.sav" in write mode
saveFile = open("Game1.sav", "w")
### Write header to file
saveFile.write("This is a valid save file
### Write game data to file
for x in range(len(cubePosi)):
saveFile.write(str(cubePosi[x]) + "
for x in range(len(cubeRot)):
for y in range(len(cubeRot[x])):
saveFile.write(str(cubeRot[x][y]) + "
### Close save file
I just don’t any idea, how am I supposed to change to get it save the time. I just don’t get it. I know it can’t be hard, but I just can’t understand it.
I am really a noob with python and this is really getting annoying. I have spent 3 days just trying to figure this out.
I used this code as my timer, if it helps you to help me:
I attach my work so you can get a better picture of my problems.
The thing is that I want to save the time of the whole race to a single file where there will also be the players name and phone number. I just can’t get it to work.
The file is from a tutorial! I have just added the timers and a sensor that ignores the first time you pass the finishline. It restarts when you have completed 4 laps and that is just to show myself where I want the saving to happen.
I would be really happy if anyone could help me with this. I am really a noob with python.
I am now very close! I know I’m on the right track. I just need a little help. If I have a variable “A” and I want to save the value of that variable in the save file, how can I do it. And how do I get the property named “Time” from an object “Plane” to be saved in the same file.
“out_file.write(A)” didn’t work!
and I don’t have any idea how I can get the property as a variable so I can save it.
If there is anyone at all who knows the answer or can help me find it, I would really appreciate it. I just can’t believe there’s no one who can help me. There must be someone who knows the answer.
PLEASE help me! I got two more days to do it so it HAS TO BE done before Monday! I am really scared now. I don’t want to be the one who ruins everything. Please help me!