|
-
Apr 8th, 2002, 05:55 PM
#1
Thread Starter
Fanatic Member
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:
Option Explicit
Private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
' Functions
Function GetFromINI(sSection As String, sKey As String, sDefault_
As String, sIniFile As String)
Dim sBuffer As String, lRet As Long
' Fill String with 255 spaces
sBuffer = String$(255, 0)
' Call DLL
lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
If lRet = 0 Then
' DLL failed, save default
If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
GetFromINI = sDefault
Else
' DLL successful
' return string
GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
End If
End Function
' Returns True if successful. If section does not
' exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As_
String, sIniFile As String) As Boolean
Dim lRet As Long
' Call DLL
lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
AddToINI = (lRet)
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.
-
Apr 9th, 2002, 09:50 AM
#2
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.
-
Apr 9th, 2002, 10:20 AM
#3
Frenzied Member
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!
-
Apr 9th, 2002, 10:34 AM
#4
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.
-
Apr 9th, 2002, 10:57 AM
#5
Frenzied Member
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!
-
Apr 9th, 2002, 11:18 AM
#6
Thread Starter
Fanatic Member
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???
-
Apr 9th, 2002, 11:31 AM
#7
Thread Starter
Fanatic Member
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.
-
Apr 9th, 2002, 11:43 AM
#8
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.
-
Apr 9th, 2002, 12:01 PM
#9
Frenzied Member
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!
-
Apr 9th, 2002, 12:53 PM
#10
PowerPoster
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...
-
Apr 19th, 2002, 05:56 AM
#11
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|