Results 1 to 14 of 14

Thread: help with high scores in my game

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking

    I need help making a high scores list in my game
    The form is named frmHighScores
    there are 2 listboxes that need sorted
    lstUsers
    lstCash
    i want it to sort through lstCash and put them in order from greatest to least then put lstUsers the way it should be with the cash list
    i also need it to save on the form unload and open it on the form load
    i dont care if anybody can do it with the registry or a text file as long as somebody can do it
    is this possible at all
    somebody please help me

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    lstCash.Sorted = True
    is what you need. But i would suggest putting useers and cash in the same list box, just have cash be first then the name. This would save you alot of coding.

    Gl,
    D!m
    Dim

  3. #3

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking well thanks but i need more

    thanks
    i had just changed it and put em in the same list before you said that and decided to sort em but i still need the saving of em and adding new ones when users get a new high score i may be able to get but maybe not

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Would I be correct in saying you have 2 lists

    Code:
    list1     list2
    20        joe
    30        bert
    10        mark
    and you want them sorted on the first list like so:
    Code:
    list1     list2
    30        bert
    20        joe
    10        mark

    It would be easiest to use a ListView with cash in the first column,users in the second and sorted on the first column

    I you really want to use 2 lists it should be possible but requires a lot more code!.


    Mark
    -------------------

  5. #5

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking yes

    yes
    thats how i wanted em sorted and i never thought of using a listview
    thanks for the idea
    that may prove to be a lot easier
    thanks

  6. #6

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking i need somethin now

    i have a problem
    i never used listview
    if you can tell me how to set it up for 2 columns
    1st cash
    2nd users
    then have it sort em and all and have a max number of 10 and if ya can how to save it to the registry then i would be happy
    but how do i set it up for cash users and a max count of 10

  7. #7
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Size the listbox so only 10 can fit in each column and set the sorting to true...but i have no clue how you would arange it so they lign up corectly. Stick to 1 listbox and have the cash first, then the name and have the listbox sorted. Then when a new high score is reached added like this.
    Code:
    Dim user as String
    user = Text1.Text ' or whereever you store the user name
    Dim cash as String
    cash = Text2.Text ' see comment above
    'Then
    List1.AddItem cash & "-" & user
    I thin that about does it.
    Adding to the registry?? that would take an API
    Code:
    'In Gen Decl
    Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Public Const REG_CREATED_NEW_KEY=&H1                      ' 
    'Then call it from the the form and place it whereever.
    I hope that helped you a bit,
    D!m

    PS. Oh yeah instead of sizing to fit only 10 you can do something like this when adding new scores.
    Code:
    If List1.ListCount = 10 Then
        MsgBox "Too Many Scores"
    End If

    [Edited by Dim on 07-14-2000 at 04:54 AM]
    Dim

  8. #8
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    One step at a time please hankshlump!


    Here's how to use a listview
    Listview is in Microsoft Windows Common Controls

    add it into your project
    incase you aren't familiar...
    Project->Components select it from the list


    Drop a Listview onto your form

    right click and select Properties

    set View to lvwReport
    click the "Column Headers" tag
    click "Insert Column"
    enter Cash in the text field

    click "Insert Column"
    enter Users in the text field

    to add an item:

    Code:
    Dim itmx As ListItem
    
    Set itmx = ListView1.ListItems.Add(, , "20")
    itmx.SubItems(1) = "Mark"
    to update a user who is already on the list

    Code:
    Sub updateScore(strCash As String, strUser As String)
    Dim itmx As ListItem
    
    Set itmx = ListView1.FindItem(strUser, lvwSubItem)
    itmx.Text = strCash
    ListView1.Sorted = True
    
    End Sub
    Mark
    -------------------

  9. #9
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    YOU DON'T NEED APIs TO SAVE TO TO REGISTRY!

    For simple apps use Savesetting() and GetSetting()

    look in the help files for usage.



    Mark
    -------------------

  10. #10

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking saving part

    ok
    now i got that all fixed cept one problem left
    the saving to the registry
    heres what i used to save my mp3 player's playlsit but this is different cause its a listview not a listbox
    heres what i have
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    For iIndex = 0 To lstHighScores.ListItems.Count + 1
    Call SaveSetting(App.Title, "settings", iIndex, lstHighScores.ListItems.item)
    Next
    End Sub
    the problem i have is that i dont know exactly what thing to save (lsthighscores.listitems.item)

  11. #11
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    The easiest way is to put it all in one string with delimiters which are unlikely to occur in someone's name.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim itmx As ListItem
    Dim strTemp As String
    Dim scores() As String
    Dim i As Integer
    Dim strUser As String
    Dim strCash As String
    strTemp = GetSetting(App.Title,"settings", "HighList")
    
    scores() = Split(strTemp, "|")
    
    For i = 0 To UBound(scores()) - 1
    
    strUser = Left(scores(i), InStr(scores(i), ",") - 1)
    strCash = Mid(scores(i), InStr(scores(i), ",") + 1)
    
    Set itmx = lstHighScores.ListItems.Add(, , strCash)
    itmx.SubItems(1) = strUser
    Next
    
    
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
    Dim strTemp As String
    Dim iindex  As Integer
    For iindex = 1 To lstHighScores.ListItems.Count
    strTemp = strTemp & lstHighScores.ListItems.Item(iindex).Text & "," & lstHighScores.ListItems.Item(iindex).SubItems(1) & "|"
    
    Next
    
    SaveSetting App.Title,"settings", "HighList", strTemp
    
    End Sub
    Mark
    -------------------

  12. #12

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking almost

    that almost works like it saves and loads and all but when i go to the form again viewing the scores the first one is right then second the cash and user are reversed third right fourth reversed and so on and so on

  13. #13

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking saving one at a time

    is there any way to save em indivisually like
    Code:
    Private Sub Form_Unload()
    SaveSetting app.title, "settings", "score1", lsthighscores.listitems.item(0)
    SaveSetting app.title, "settings", "score2", lsthighscores.listitems.item(1)
    'continue that til all 10 are saved
    End Sub
    and then load em the same way like
    Code:
    Private Sub Form_Load()
    lsthighscores.listitems.item(0) = getsetting(app.title, "settings", "score1")
    'contine til the end
    End Sub
    just wondering if you can cause i did that before with my web browser but i dont know about with a listview


  14. #14

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    36

    Talking ITS OVER PEOPLE

    HOORAY FOR ME
    i did it
    i got it to save and only have the top10 scores on there
    it loads right too
    heres what i did
    Code:
    Private Sub Form_Load()
    Me.Icon = frmDealing.Icon
    lstHighScores.Clear
    Dim iIndex As Integer
    Dim sItem As String
    iIndex = 1
    Do
        sItem = GetSetting(App.Title, "settings", iIndex, "")
        If Len(sItem) Then
            lstHighScores.AddItem sItem
            iIndex = iIndex + 1
        End If
    Loop While Len(sItem)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Dim iIndex As Integer
    For iIndex = 0 To 9
    Call SaveSetting(App.Title, "settings", iIndex, lstHighScores.List(iIndex - 1))
    Next
    lstHighScores.Clear
    End Sub
    i hope that helps you guys too so ya dont gotta do it over again

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