Results 1 to 11 of 11

Thread: The Key to great games...

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Unhappy The Key to great games...

    I have some code (below) from a tutorial. It's for an old fasioned INI file. I have been quite taken with it. In fact I have thought up a scripting technique for games!!

    The problem is to be honest I don't really understand it suffieciently to modify it.

    What I want to enclude is an additional key. So as opposed to Key/SubKey/Value I want MajorKey/MinorKey/SubKey/Value.

    Can this be done. I'm assumeing so. I just don't know how.


    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetPrivateProfileString Lib "kernel32" _
    4. Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    5. ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
    6. ByVal nSize As Long, ByVal lpFileName As String) As Long
    7. Private Declare Function WritePrivateProfileString Lib "kernel32" _
    8. Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    9. ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    10.  
    11. ' Functions
    12. Function GetFromINI(sSection As String, sKey As String, sDefault_
    13.                                         As String, sIniFile As String)
    14.     Dim sBuffer As String, lRet As Long
    15.     ' Fill String with 255 spaces
    16.     sBuffer = String$(255, 0)
    17.     ' Call DLL
    18.     lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
    19.     If lRet = 0 Then
    20.         ' DLL failed, save default
    21.         If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
    22.         GetFromINI = sDefault
    23.     Else
    24.         ' DLL successful
    25.         ' return string
    26.         GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
    27.     End If
    28. End Function
    29.  
    30. ' Returns True if successful. If section does not
    31. ' exist it creates it.
    32. Function AddToINI(sSection As String, sKey As String, sValue As_
    33.                                       String, sIniFile As String) As Boolean
    34.     Dim lRet As Long
    35.     ' Call DLL
    36.     lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
    37.     AddToINI = (lRet)
    38. End Function

    What I intend to do is define a standard "level" that is all the same all over. House type #1. Street type #1, walls at X,Y,Z.., etc. and then program by exeption!

    What thinks you... ...wait no - how do i do it (add an extra Key-Level)?

    [edit]That's better not half mile wide now[/edit]
    Last edited by Matt_T_hat; Apr 8th, 2002 at 06:04 PM.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The INI system is a relic from 16-bit windows. The functions are only provided for backwards compatibilty and may just vanish one day. And they are inflexible: if you want to add sub-keys, you have to write your own functions.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    ini might be old, but I think it's much better for a game or some simple program to store its settings in a text file (Being in its own folder!!!) instead of overloading the registry even more!
    Sanity is a full time job

    Puh das war harter Stoff!

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    no, why, the registry is intended for exactly that...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I think it's good habit to not spam the system if you don't need to.
    If you do a real app well put your dlls and stuff anywhere you need but for most of those little games&apps that are discussed here I think it's best if you can just delete them completely by just removing the folder they are in. Also it is nice if you reinstall your system and the old apps still work without having to reinstall them. I also hate how long it takes to search the registry on a system that hasn't been reinstalled for a while... . There is even games that put their savegames into the registry (I guess they were shareware not real commercial games, but still I think that's waste even if its just about 20vars...)
    Sanity is a full time job

    Puh das war harter Stoff!

  6. #6

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by /\/\isanThr0p
    ini might be old, but I think it's much better for a game or some simple program to store its settings in a text file (Being in its own folder!!!) instead of overloading the registry even more!
    That's why I was so taken with it.

    So help me out here if I want to add extra levels of keys, I need to create my own functions... I kinda guessed I would. So I would start by typing
    Code:
    Private function(...
    Um.....

    Pointers???
    ?
    'What's this bit for anyway?
    For Jono

  7. #7

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    I'm not being ungreatfull.

    I just re read my post and it does look that way

    I'm just haveing a bad brain day.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I agree, things that you are likely to remove soon shouldn't write anything into the registry. Savegames there are very rude. But real commercial-quality apps should store their settings there.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I totally agree CornedBee
    and for matt

    I didn't think you were rude or anything. The fact is you thread is turning to chit chat

    oh well let's try to change that
    I think you would need to start from 0 since I don't think the old functions will work that great with new ones...
    but once you got it set up it will probably be really powerful...

    but then who needs cascading keys? nobody really cares how the information is stored as long as it comes out right and it is not to unefficent...
    so what I propose for you to do is not to make sub keys but just do it like that:
    Code:
    [key]
    setting=number
    IgotSubkey="key2SubKey"
    [key2SubKey]
    so that is not exactly like a subkey but it works like one in the end...
    Sanity is a full time job

    Puh das war harter Stoff!

  10. #10
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Sentience (the game I'm writing) uses its own scripting files to store information.

    I agree with Misanthrop that a games scripts should be in the directory with the game, although I do use the registry to store key game settings (such as the resolution, the game directorys location etc)

    Although the scripts that are with Sentience are named ".ini" they are really little more than CSV's with some custom formatting.

    For example, one of the scripts:

    If the line starts with '[' as in [System] then it symbolises the end of the previous section and the start of a new one. Anything between the []'s is the section header. If a line starts with " ' " (single apostrophe) it's to be ignored.

    You can write your own scripting engine quite easily.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  11. #11

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    So I've heard. Can you point me at some examples and perhaps some tutorials. I want to keep it basic, but I want to be able to program a wide range of EXEPTIONS. This is where I have run aground some what in the quest for the best way to do this.

    ?
    'What's this bit for anyway?
    For Jono

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