Results 1 to 11 of 11

Thread: Getsetting/Savesetting Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Getsetting/Savesetting Help

    for my advanced higher computing course in school, i am required to do a little project, i've peiced together, with help form google a pong game, but its not quite enough to pass, ive been told i need some use of saving to a database, unfortunately, my teacher doents know anything about programming.
    so far i have

    Dim X As Integer
    Dim Y As Integer
    Dim Score As Integer
    Dim highscore As Integer
    Dim bestscore As Integer





    Private Sub Form_Load()
    Ball.Left = 2500
    Ball.Top = 1300
    X = -50
    Y = -50
    Timer1 = False
    start.Visible = True
    intro.Visible = True
    intro.Caption = "Instructions; move the mouse to catch the ball, press enter to pause the game."
    highscore = 0


    bestscore = GetSetting(Pong.vbp, "highscore", "score")
    SaveSetting Pong.vbp, "highscore", "score", bestscore




    End Sub

    Private Sub Form_MouseMove(Button As Integer, shift As Integer, X As Single, Y As Single)
    pad.Left = X - pad.Width / 2
    End Sub

    Private Sub Reset_Click()
    Ball.Left = 2500 'reset the balls position
    Ball.Top = 1300
    X = -50 'reset the speed
    Y = -50 'reset the speed
    Reset.Visible = False
    Score = 0 'reset the score
    ScoreCard.Visible = False
    Continue.Visible = False
    lblhighscore.Visible = False
    lblbestscore.Visible = False
    ScoreCard.Caption = "Score: " & Score 'show the score on our label
    Me.Caption = "Score: " & Score 'show the score as our forms caption
    Timer1.Enabled = True 'start the timer again to get the ball moving




    End Sub

    Private Sub Timer1_Timer()
    Ball.Move Ball.Left + X, Ball.Top + Y
    If Ball.Top <= 0 Then
    Y = Y * -1
    End If
    If Ball.Left <= 0 Then
    X = X * -1
    End If
    If Ball.Left + Ball.Width >= Me.ScaleWidth Then
    X = X * -1
    End If
    If Ball.Top + Ball.Height >= pad.Top Then
    If (Ball.Left + Ball.Width < pad.Left) Or (Ball.Left > pad.Left + pad.Width) Then 'If the ball
    'is to the left or right of the pad then
    Me.Caption = "Game Over" 'set the forms captino to read 'Game Over'
    ScoreCard.Visible = True
    lblhighscore.Visible = True
    lblbestscore.Visible = True
    Reset.Visible = True 'make the reset buttone visible
    Timer1.Enabled = False 'pause the program
    Else
    Y = Y * -1.05 'speed up the ball
    X = X * 1.05
    Score = Score + 1 'add 1 more hit to the score
    ScoreCard.Caption = "Game Over, Score: " & Score 'show the score on our label
    Me.Caption = "Score: " & Score 'show the score as our forms caption
    If Score > highscore Then highscore = Score
    If highscore > bestscore Then bestscore = highscore
    lblhighscore.Caption = "This Session's Best Score: " & highscore
    lblbestscore.Caption = "All Time High Score: " & bestscore

    If (Ball.Left + Ball.Width / 2) < (pad.Left + pad.Width / 2) Then 'if the ball is to the left
    'of the pads centre then
    If X > 0 Then 'if it is going right
    X = X * -1 'make it go left
    End If
    Else 'the ball must be on the right of the pad
    If X < 0 Then 'if it is going left
    X = X * -1 'make it go right
    End If
    End If
    End If
    End If

    End Sub

    Private Sub form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Timer1 = False 'pauses the game
    Reset.Visible = True 'shows the reset + continue button
    Continue.Visible = True
    lblhighscore.Visible = True
    lblbestscore.Visible = True
    lblhighscore.Visible = True
    intro.Visible = True
    End If
    End Sub

    Private Sub continue_click()
    Timer1 = True 'continues the game, and hides the buttons

    Reset.Visible = False
    Continue.Visible = False
    lblhighscore.Visible = False
    lblbestscore.Visible = False
    intro.Visible = False
    End Sub

    Private Sub start_click()
    Timer1 = True
    start.Visible = False
    intro.Visible = False
    End Sub


    as my code, , but the part i'm struggling with with the getsetting/savesetting


    bestscore = GetSetting(Pong.vbp, "highscore", "score")
    SaveSetting Pong.vbp, "highscore", "score", bestscore

    to be honest, iv no clue how to do it, and with bestscore as my value i'm tryign to save, as an integer, i wonder if anyone could break it down for me?
    thanks

    excuse te typos im trying to get this post up fast as i'm late for maths

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Getsetting/Savesetting Help

    Don't know about the rest of your code, but I'm surprised
    these two lines will even compile:
    Code:
    bestscore = GetSetting(Pong.vbp, "highscore", "score")
    SaveSetting Pong.vbp, "highscore", "score", bestscore
    All of the arguments are expected to passed as strings, so
    change Pong.vbp to "Pong" or App.ExeName.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: Getsetting/Savesetting Help

    right ok, i wasnt sure i was playign around with it for ages, and VB jsut found less errors when i called if pong vbp, thanks will try it now see how it goes

    but ye, im VERY new to computing crashed higher last year, was easymode, and advanced higher seems to have jsut hit me, its especially hard with a teacher that doesnt knwo the 1st thign about programming...
    so ye, ive no clue wat i'm doin with the getsetting/savesetting bit

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: Getsetting/Savesetting Help

    ok, with it changed to this

    bestscore = GetSetting(App.EXEName, "highscore", "score")
    SaveSetting App.EXEName, "highscore", "score", bestscore

    it still aint happy, any idea why?

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: Getsetting/Savesetting Help

    being perfectly honest, ive no clue what the section and the key are supposed to be, if someone could explain this it would make life a little easier, cos atm i have random relative strings thrown in there

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: Getsetting/Savesetting Help

    i also tried bestscore.value, i thought it might be cleared that the bestacore value is an integer, but its still not happy

  7. #7
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Getsetting/Savesetting Help

    vb Code:
    1. it still aint happy, any idea why?
    Ain't happy, doesn't give much to go on.
    Open the Immediate (debug) window, Ctrl-G &
    type ?App.ExeName
    and see if you get what you expect.
    In the SaveSetting call, try CStr(bestscore)

  8. #8
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Getsetting/Savesetting Help

    Quote Originally Posted by LRPaterson View Post
    not quite enough to pass, ive been told i need some use of saving to a database

    what type of database do you need to use?

    get setting and savesetting use the registry., my programming course required an actual database file

    a text file can be used for most

    say your text file is:
    highscorelayername
    lastscorelayername

    ---->
    99999:James
    321:frank



    Code:
    dim ifile as integer, sFile as string, aSet() as string
    ifile  = freefile
    open app.path & "\scores.txt" for input as #ifile
    input #ifile, sfile
    close #ifile
    
    'either one should work, crlf is for windows etc vbnewline for unix etc
    'aSet() = split(sFile,vbnewline)
    aSet() = split(sFile,vbcrlf)
    
    if ubound(aSet()) > 0 then
         dim aScore() as string
         
         ' high score
          
         ascore()=split(aSet(0))
         labelscore.caption = ascore(0)
         labelname.caption = ascore(1)
    
    
         'last score
    
         ascore()=split(aSet(1))
         labelscore.caption = ascore(0)
         labelname.caption = ascore(1)
    end if
    then save the scores its simply

    Code:
    ifile = freefile
    open app.path & "\Scores.txt" for output as #ifile
    print #ifile, "STRING TO PRINT" 
    close #ifile
    im sure you can work out the string to print etc? vbcrlf is a new line

    but then if u need an ACCESS database? [i needed access in my project, but if its not told... then...


    also

    Code:
    OPTION EXPLICIT
    ALWAYS!!! add that to the VERY TOP LINE of ANY code

    it will make vb throw an error if you put a typo - which are normally about 50-70% of most of the simple coding problems... and maybe your "bestscore" isnt being declared or so on
    Wayne

  9. #9
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Getsetting/Savesetting Help

    also, looking at your code...

    why do u save the best score after fetching it? it isnt going to change,? -- and if you make a break point at "SaveSetting" ---> click the bar to the left of the save setting line, the line then goes deep black, with a red circle next to it,

    run the code.... when it breaks, run ur mouse over bestscore to see what the value is set to - it comes up in a tooltip....


    i think u need a default value set on the get setting function too,,, - i prefer ini files, so much cleaner for an uninstall - or if app breaks just delete the settings to make it back to a clean start etc....

    - will edit it in a sec when my codin machine has booted


    [edited]
    Code:
        S = GetSetting("NAME OF APP", "SECTION", "KEY", "DEFAULT VALUE")
    
        savesetting "NAME OF APP","SECTION","KEY","VALUE TO SAVE"
    i dont know if you have used a regedit before?



    your info is stored in "Settings"...

    on this example "ZoneMap" is the name of app, "ProtocolDefaults" is the section., "DVD" (on the right) is the key

    so say you want to get the setting for DVD its

    DVD = getsetting("ZoneMap","ProtocolDefaults","DVD")

    if DVD is not set, it will be blank, - if you always want something, you set the default

    DVD = getsetting("ZoneMap","ProtocolDefaults","DVD",0)

    so in this case, if it is blank, it will return zero.... (you want to use this for your application)


    then saving it is the same just reverse

    savesetting "ZoneMap","ProtocolDefaults","DVD"

    only use yours....

    ie:

    Pong\Scores\High
    :
    savesetting "Pong", "Scores", "High", iHighScore
    Attached Images Attached Images  
    Last edited by wpearsall; Sep 8th, 2009 at 08:34 AM.
    Wayne

  10. #10

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    6

    Re: Getsetting/Savesetting Help

    thanks wayne looks usefull, i think im gonna have to do this at school, since my school wont let me regedit, but yea funnily enoguh i was using that for soemthign completely non-related the other day, i'll let you know how it turns out

  11. #11
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Re: Getsetting/Savesetting Help

    Quote Originally Posted by LRPaterson View Post
    since my school wont let me regedit,
    most school / office pc's dont save the reg settings unless it is an admin account - you login on a guest account on the machine... etc...

    also: You dont need to regedit... i used that as an example of the setup of the functions -

    but like i said, ask your teacher what the use of database has to be...

    i just made a simple computer booking system etc for the library... 50 computers, 50 command buttons. 50 records in a mdb file [computers] a cpl of fake students [students]
    then if there was a student id in the "student" field on the "computers" table it was in use. - a quick loop through computers table to set the command button for the respective pc to red [in use] / green [free]
    <<< i know thats not much use for you, but basically when it says database, even though the registry is a database, the marker wants to see some more use of functions etc. not just simply resorting to "GetSetting and SaveSetting" - etc GL all the same though
    Wayne

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