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.

DarkBASIC Professional Discussion / Crazy "open to read" problem...

Author
Message
Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 24th Oct 2003 23:52
Hi there,

In my new game I use "open to read" to load in the level data. It was all working fine and dandy for ages, but then I decided to split up my functions into separate files. They went from all the functions at the end of my main source into a few different .dba files (so they can be shared with the editor), included via the Pro IDE.

Now whenever I run the program I get the "file does not exist" message on runtime. But if I try to load the file before calling the function in the included file (e.g. at the start of my main source file) it works fine.

Is this a DB bug, in that files cannot be loaded if the function doing the loading is in a separate file? Or am I being silly? Anybody?

Cheers,

Wrig
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Oct 2003 03:13
Any example code by any chance ?


Avatar & Logo by Indi. Insert witty comment here...
Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 25th Oct 2003 23:56
Ermm I'm not sure any example code is needed (or would be easy to show). Just know that "open to read" works whilst inside the main source file (main.dba), but not when the function is in another file (functions.dba).

Wrig
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 26th Oct 2003 00:20
I think here smaple source would help. The DBP IDE has an odd way of deaing with includes, sometimes it's the smallest thing which affects it

(ps wrig- can you have a look at the demo of MiS and tell me what you think? its on my web site (button below) - thanks)

Fishie says:
"Those who fail to prepare prepare to fail"
"Rules are for the guidance of the wise and the blind obdeniency of the fools"
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 26th Oct 2003 10:37
as long as you add the external file over files tab and not using #include which doesn't really work anymore in DBP, there is no problem.

Dell Inspiron 8200,P4-M 1,7ghz, GF4 440go (45.23 - DX9b), 1GB RAM
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 26th Oct 2003 10:45
I have experienced some weird things happening with the OPEN TO READ and OPEN TO WRITE commands. It seems quite sporadic though so hard to track down.

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 26th Oct 2003 10:53
yeah i've noticed some bugs with the file commands ... one of the users asked for my help on them so i gave them the answer just to find out it didn't work anymore.

totally baffled me to why cause i could've sworn it was working before U5.x


To Survive You Must Evolve... This Time Van Will Not Escape His Fate!
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 26th Oct 2003 13:47
I have a problem with opening a large number of files (about 3800..one after the other), and then replaceing all instances of chr$13 with chr$32 in the file by copying bytes to a temp file and then replaceing any 13 with 32 during the copy (after skipping the header bytes).
On XP the whole thing runs fine and finishes in a reasonable time (1hr15mins approx), under win98 it gets to some files (not of unusual size or anything as far as I can tell) and then spends from 3 to 6 minutes parseing them, (obviously it isn`t doing that), but the run will finaly complete and all the files are uncorrupted, so I can`t see whats happening here.
It seems as though sometimes it takes a while to realise it has reached the end of the file, I Included the code if anyone is interested, it was just a quick hack to allow me to modify some text files with the software I have (that won`t allow me to strip characters from text I wanted to reformat)
.
It was intended to dropped in a folder with all the files in it and it would just trog through the whole lot and modify them.

Mentor.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 26th Oct 2003 14:55
I've experienced this problem myself but I found the problem due to the fact that if I had any sort of type conversions from lets say, a floating point variable to an integer variable, or passing in a float accidentally as a parameter of a function that expected an integer just before the call to Open To Read function, it would always complain that the file didn't exist! In your function that contains the Open To Read function call, check that all your variable types are correct and that you do not pass a Boolean type as one of the parameters into your (User) function.

I.e.

Function MyFunc( nID as Integer, bFlag As Boolean )
...
...
Open To Read nID, strMyFile
EndFunction

This definately causes a problem for Load Image aswell.

Hope it helps

APEX!


Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 26th Oct 2003 22:40
Thanks for all the advice, it's all good stuff. I will test all of the suggestions as soon as I get two ticks and post the results in this thread.

Cheers again,

Wrig
Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 26th Oct 2003 22:50
BTW David, MiS plays nicely. The only problem (as I'm sure you're aware) is the REALLY low framerate. I get average 6fps here, so that obviously needs tuning up. Apart from that, nice job! Send me an e-mail and we can talk more about it!

Wrig
Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 27th Oct 2003 17:17
Nope, nothing seems to work. It's ridiculous, I can do the following:

open to read fName$,1
close file 1
loadLevel(fName$)

and it works fine. However, if I take the "open to read fName$,1" line and put it inside of "loadLevel(fName$)" it will fail (cannot find file). I can even ignore the parameter and specify the raw path myself (which I know exists), but it will still fail if called from inside the function.

I think my compiler might be broken

@David89: Yes I'm using the IDE include instead of the code based one. Shouldn't be a problem, in fact if I don't use INCLUDEs at all I still get the issue. It seems to be with the functions now instead of the includes.

@ApexNOW: Tried your suggestions (in several different guises), but I wasn't doing any type casting to start with unfortunately. It was "int's" all the way!

Definately something strange going on with DBPro, but I can't get my cd to reinstall for another two weeks 'till I get back from university. Doh...

Wrig
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Oct 2003 18:20
Wriggler, could you just post the actual function you're calling? I don't need the rest of what's needed but if your LoadLevel function is calling other user functions, could you post them aswell. I'm sure this is a problem related to what I've had before, I just need to see the code to see if I can spot the problem

APEX!


Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 27th Oct 2003 19:08
in main.dba:

`...
cNumOfImgs = loadLevel(curLevel)
`(cNumOfImgs and curLevel are both ints)
`...



in func.dba:

`Load level from file
function EditorLoadLevel(lev as integer)
fName$ = str$(lev)
fName$ = "Data\Level\"+fName$+".dat"

`CRASHES HERE!`
open to read 1,fName$
read string 1,temp$
cNumOfImgs = val(temp$)

`...

close file 1
endfunction


func.dba is included as part of main.dba via the editor.

Wrig
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 27th Oct 2003 19:51
have you tried changing
open to read 1,fName$
to
open to read 1,"filename.dat"
with filename.txt the name of the file with the level data just to make sure it is not a problem with something other than the open to read command.
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Oct 2003 20:36 Edited at: 27th Oct 2003 20:45
[Edited for clarification]

Wriggler, Ok, first problem is that your function must return a value, according to that post, it doesn't. Secondly, can you declare the variables Temp$ and fName$ as

Local Temp As String
Local fName As String

at the beginning of the function,

Also, how did you declare cNumOfImgs? Was it declared as a global in Main.dba, because if it was, your function will not pick it up in the func.dba file so this will never be assigned correctly. Either declare this as a local variable in the function and ensure that you return the value by...

EndFunction cNumOfImgs


Try this and see if it works.

APEX!


Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 27th Oct 2003 21:22
@the_winch: Yup, and still no change. It does indeed seem to be a problem in the "open to read" command.

@ApexNOW: Cheers for the help mate. My actual function does return a value, it's just that I forgot to type it in that post. Whoops.

Declaring the variables locally shouldn't make a difference, but I tested anyway. And the problem still occurs.

Oh and the third point is null because I do actually return the value (my bad for forgetting to write it in).

I'm going to write some test functions and see if I can figure it out... it's crazy...

Wrig
APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Oct 2003 22:01
Hmmm, most odd. I'm sorry if my suggestions didn't work :/ It's got to be something that happens before the call to the function, but I just can't pin it down.

APEX!


Wriggler
23
Years of Service
User Offline
Joined: 17th Sep 2002
Location:
Posted: 27th Oct 2003 22:24
Yes there must be something going on. My initial thought was that there was a stray "cd\..." command somewhere which would make the relative path wrong. I looked for ages and found nothing, but even when using absolute paths it still doesn't load. 'Tis a very silly problem...

Oh well, back to the compo entry until I can get my DBPro CD...

Wrig
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 28th Oct 2003 01:13
One other thing, some of the data types cause problems when you use them in functions.
If you are declaring anthing other that integers and strings as local inside the function try changing them to integers or strings and see if the problem persists.

You might want to try moveing or deleteing the dbpro file out of the directory and load the source and let the ide create a new dbpro file. If it still has the problem just move the old one back.

Login to post a reply

Server time is: 2026-07-26 16:04:10
Your offset time is: 2026-07-26 16:04:10