Results 1 to 10 of 10

Thread: Highscore

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Highscore

    How would i get a high score table, that records the name of the player and their score, then save it into a file named "score.ini" located in the application's path?

    Then, be able to look at the highscore table and see all the names and scores there by loading the scores in "score.ini"?

  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Highscore

    Heres for the reading and writing of an INI file

    http://www.vbforums.com/showthread.php?t=349993

    for the recording of score, we will need to see more code, or more info on the program

  3. #3

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Highscore

    Err... Would it be shorter if i wrote it into another file, say a .txt file or another extension that could be made up?

    More info:
    The two variables i need to record are "name" and "efficiency". At the end of a game, a screen will pop up asking for their name. After pressing ok, another screen will pop up, showing the top ten scorers and their names.

    I was thinking maybe using this code and a listbox:

    VB Code:
    1. dim full as string
    2. full = efficiency & " " & name
    3. list1.additem format(full,"")
    Would this work?
    Last edited by ajames; Dec 3rd, 2005 at 04:38 PM.

  4. #4
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Highscore

    Declare the variables in a global module...

    Public Full as string,

    but im not to sure about the list of scores, *whistle* here dg, hack, joacim etc, here boy!

    Maybe the big boys can help you, no pun intended

  5. #5
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Highscore

    You can just read and write a file:

    VB Code:
    1. 'include Microsoft Scripting Runtime
    2. Public fsObj As FileSystemObject
    3.  
    4. 'in form load
    5. Set fsObj = New FileSystemObject
    6.  
    7. Public Sub SaveScore(Name As String, Score As Integer)
    8.    Dim ts As TextStream
    9.    Set ts = fsObj.OpenTextFile(App.Path & "\score.ini", ForAppending)
    10.    ts.WriteLine (Name & " = " & Score)
    11.    ts.Close
    12.    Set ts = Nothing
    13. End Sub
    14.  
    15.  
    16. Public Sub LoadScore(Name As String, Score As Integer)
    17.     Dim ts As TextStream
    18.     Listbox1.Clear
    19.     If fsObj.FileExists(App.Path & "\score.ini") Then
    20.         Set ts = fsObj.OpenTextFile(App.Path & "\score.ini", ForReading)
    21.         Do While Not ts.AtEndOfStream
    22.            Listbox1.Add ts.ReadLine
    23.         Loop
    24.         ts.Close
    25.         Set ts = Nothing
    26.     Else
    27.         MsgBox "No high scores yet"
    28.     End If
    29. End Sub

    Of course this doesn't actually check if a score belongs in the high score list, nor does it sort them by score.
    Last edited by umilmi81; Dec 4th, 2005 at 10:54 AM.

  6. #6

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: Highscore

    Quote Originally Posted by umilmi81
    VB Code:
    1. 'include Microsoft Scripting Runtime
    2. Public fsObj As FileSystemObject
    1)When i put this anywhere on the form, it comes up with an error of "user defined type not defined". Where do i put it?

    2) How would i sort the rest of the code?

  7. #7
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Highscore

    You need to add Microsoft Scripting Runtime, Scrrun.dll to your References.

    Public fsObj As FileSystemObject

    Put it at the top of the Form code window or in a Module if more than one Form uses it.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Highscore

    Attached is the code to a small VB game. It contains a class called CHighscore that you can use in your program to save highscores, however it saves to the registry instead of a file. You can use the game as an example on how to use the class. Please don't comment to much about the game itself, it doesn't use any back buffering so it's kind of flickery. I made it in a couple of hours just to show my brother that you can use VB to create simple games in a very short time.
    Attached Files Attached Files

  9. #9
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Highscore

    score.ini? in pure text? I would think you might want to encrypt it and call is data.ini so people want cahnge it to 999,999,999 unless its your own small game and you need no use to cheat...
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  10. #10
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Highscore

    Quote Originally Posted by ajames
    1)When i put this anywhere on the form, it comes up with an error of "user defined type not defined". Where do i put it?
    lol!

    Come on man, look at the comment right above the statement

    'Include Microsoft Scripting Runtime

    Go to the "Project" menu, and click "References". Scroll down the list until you get to Microsoft Scripting Runtime. Then check the box, and say ok.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width