Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / ahhh, errors!!!

Author
Message
Barbarian
17
Years of Service
User Offline
Joined: 11th Dec 2006
Location:
Posted: 29th Oct 2007 10:22 Edited at: 29th Oct 2007 10:41
how can i read data from a txt file and assign it to an array? are there any dgdk functions which can handle that? also, it should only read it one character at a time
Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 29th Oct 2007 11:35
That should be build-in methods in your programming language. DGDK dont need to have functions for this.

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine
http://noggs.netopcom.dk/forum/default.asp - Forum for the game
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Oct 2007 02:13
As Niels Henriksen has mentioned - whether you're using C++ or C# - There should be ways for you to do file i/o either available in one of the "Standard" or "Common" libraries that are normally distributed with your development environment.

However, TGC were rather thorough - perhaps for a certain degree of backward compatibility, perhaps to help people "migrate" from their familiar BASIC environment to the sometimes unwieldy land of C++ and C## - perhaps just out of pure thoughfulness - there is quite a suite of file handling and file system commands to help you get going.

Note that their generosity stops there. You will need to learn how to utilize Arrays (AFAIK) in your language of choice - and if we are talking C++ - the recommended "Path" is the STDLIB which has ways you can use dynamic arrays (like in Darkbasic kind of) and use things called collections and/or lists. This isn't a CakeWalk - but its one of those study sessions you probably won't regret.

I personally didn't dive in - I learned enough to know what it was - and I decided to write my own array management - but it was all part of me wanting to understand the knitty - gritty as I was just REALLY TRYING to use C++ for the first time (Prior to this I was only dabbling now and then).

I still need to learn the STDLIB myself - but I just got a few books to help - so I should have a good "resource" when I decide its my time

Good Luck
Jason

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Oct 2007 02:14
Barbarian
17
Years of Service
User Offline
Joined: 11th Dec 2006
Location:
Posted: 30th Oct 2007 03:45 Edited at: 30th Oct 2007 03:51
thanks for the replies. before i say anything else i should probably mention that i'm using DarkGDK (c++). the reason i wanted to know if there was a native function which could handle that kind of stuff was because i'm trying to make a map system similar to that in the "dark dungeon" fps sample; except that instead of having the map embedded into the code i can have it in txt files for easy changing. I have tried out darkbasic a few times but i'm not really a fan of BASIC languages, so i decided to buy dgdk instead. normally i'd use fstream for file input/output but i wasn't sure if that'd work as i would need the "main" function as the entry point. anyway, thanks for the advice, i'll look into using stdlib.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 30th Oct 2007 11:39 Edited at: 30th Oct 2007 11:42
If anyone wants to load or save arrays, it is not that difficult, but I understand that i/o commands can seem strange sometimes.

This is a function replacement I made for load array:




And save array:



This is an example of integer array usage:



By the way, Barbarian, I think the title of the thread is a little misleading, perhaps 'how can i read data from a txt file and assign it to an array' would have been better.

[Edit : Woops, it looks like from a long time ago. Just replace any 'SDK' with 'GDK' to update it ]
MikeyK65
17
Years of Service
User Offline
Joined: 14th Dec 2006
Location: Cheltenham, UK
Posted: 31st Oct 2007 02:01
Unfortunately using the GDK you will have to access the operating system IO using the inbuilt file functions of C++.

"fopen" will open a file stream
then you will need to use "fread" to read characters from that stream.

Hope this helps?

Cheers
Mike
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Oct 2007 21:49
I could have swore - I there is - FileIO routines that came with DarkGDK C++ for this kind of thing. Its in the reference chm file.

RPDan
17
Years of Service
User Offline
Joined: 29th Apr 2007
Location:
Posted: 1st Nov 2007 18:43
DarkGDK does have functions to do this, but with something so simple it is probably better to use the functions provided with the mscorlib dll or the c standard library - they will be quicker at runtime.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Nov 2007 19:39
Agreed.

It is a valid option though.

Hmm... makes me wonder what I have to do now in C++ to do low level block reads/writes for faster throughput on big files ...hmmm

Barbarian
17
Years of Service
User Offline
Joined: 11th Dec 2006
Location:
Posted: 3rd Nov 2007 00:53
Quote: "By the way, Barbarian, I think the title of the thread is a little misleading, perhaps 'how can i read data from a txt file and assign it to an array' would have been better."


yeah, originally this post was about an actual error that i got when compiling, but i solved that problem shortly after i posted; so i decided to hijack my own thread to solve this problem instead of starting a new one.

anyway, i managed to get it to work, thanks for the help everyone.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Nov 2007 07:06
Quote: "Hmm... makes me wonder what I have to do now in C++ to do low level block reads/writes for faster throughput on big files ...hmmm"

The lowest level functions for reading/writing blocks of data are ReadFile and WriteFile.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 5th Nov 2007 19:23
Thanx for That Benjamin!

I have used the equiv in FreePascal and its amazing how FAST you can do stuff with if you put the time in to setting up a little system to use it correctly!

and for simple simple - you can make file copy functions with these that run circles around "windows explorer" because it has a small buffer - but you can make 64k ones - and watch files SCREAM! Even multi-gig files get HUGE octane boost - thanks for the links

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Nov 2007 21:05
You're welcome.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)

Login to post a reply

Server time is: 2024-11-16 20:28:06
Your offset time is: 2024-11-16 20:28:06