FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Delphi problem! (Language is Pascal)





Battle_Off
I program in Delphi, and am quite good at it.

I am in the process of making a game called Battle Off. (hence my username) it will go on my website, and can be downloaded for free.

I have multiple data files ('.dat') in which data about your character, the monsters etc, is stored.

At the moment there is one folder called Battle_Off (so. J:/Battle_Off/), where all images, files and other stuff is saved.

Something I'd like to do is to be able to save these data files in separate folders.

For example, If a new user makes a character, I want it to be saved in a folder called users (so J:/Battle_Off/users/)

I also have made a program that creates the monsters, so you run the program and it finds the number of monsters. so if it finds 3 monsters, then they will be seen as 'monster_1.dat'; 'monster_2.dat' etcetc.

I would also like to save these in a directory called monsters, so J:/Battle_Off/monsters/

I have done a bit of research on the net, and have been unable to find anything.

If anyone has any tips or ideas, can you please help me out.
HamsterMan
Could you be more specific what the problem is.

This is a very simple way of saving text files in a folder based on user names.

UserNames: Array[0..1] Of String;
UserNames[0] := 'Roger';
UserNames[1] := 'Bob';

Procedure TMainForm.SaveUserInfo(User: Word);
Var
Txt: TextFile;
FileName: String;
Begin
FileName := 'J:\Battle_Off\' + UserNames[User] + '\WhateverNameTheDatFileShouldHave.dat';

Try
AssignFile(Txt, FileName);
Rewrite(Txt);
WriteLn(Txt, 'nananananana');
CloseFile(SaveFile);
Except On E: Exception Do
CloseFile(SaveFile);
ShowMessage('Error saving ' + FileName + '!!1');
End;

Alternatively you can use
FileName := ExtractFilePath(Application.ExeName) + UserNames[User] + '\WhateverNameTheDatFileShouldHave.dat';
if you want to use folders located in the same directory as the executable.

Additional... This code will let you list all the files of a specific type in a directory.

Procedure TMainForm.LoadFilesByMask(lst: TStringList; Const SpecDir, WildCard: String);
Var
intFound: Integer;
SearchRec: TSearchRec;
Begin
lst.Clear;
intFound := FindFirst(SpecDir + WildCard, faAnyFile, SearchRec);
While intFound = 0 Do
Begin
lst.Add(SpecDir + SearchRec.Name);
intFound := FindNext(SearchRec);
End;
FindClose(SearchRec);
End;

Procedure TMainForm.ListMonsters();
var
FileList: TStringList;
Begin
FileList := TStringList.Create();
LoadFilesByMask(FileList, 'J:\Battle_Off\monsters\', '*.dat');
//FileList now contains a list of all the dat files in the monster directory.
End;
Battle_Off
OK, more specific.

In HTML, If you want to access an image, you type

<img src="images/picture.jpg"/>

where 'images' is a folder name that is in the folder of the html file, and 'picture.jpg' is the name of the image.

Well I want to be able to do the same thing, but in Delphi,

AssignFile(datafile, 'monsters/monster_1.dat');

where monsters is a folder within the Delphi project directory and monster_1.dat is a data file in the directory of monsters.

Is it possible to do that, easily.
HamsterMan
Then what I just wrote is what you need.

Just ask if there is anything in the code you don't understand.
Battle_Off
IT WORKS, Fantastic, thnaks a lot mate.
Related topics
What computer languages you know?
an annoying problem - PLEASE help
Programming links, info, and tutorials
My name is..
Bush’s Openly Religious Language
ASP Problem
What if your beliefs are wrong?
Game Maker
Writing
Delphi IDE by CodeGear for PHP coding !!!
i want to learn programing
About pascal programming language
New to programming, which language do I choose?
Why do people hate goto statements so much?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.