Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data not coming out right
#1
Well here's the deal. I have found a way to eliminate a lot of grid pairing placements... you know, coordinates, that's the word... of like (200,300) for my game where the 'trees' are located on the map. I place all the coordinates in a file called 1.plc and so on for each screen and open it....

so I do like this to input the data:

Code:
OPEN "1.plc" FOR RANDOM AS #1
FOR I = 1 to 5
READ PLACEX(I)
READ PLACEY(I)
PUT #1, , PLACEX(I)
PUT #1, , PLACEY(I)
NEXT I
CLOSE #1
DATA 0,0,100,20,300,200,56,23,32,89

This theory worked for one screen. So I made a program to create the rest of the files, some 30 in all I think. Well, now the problem is that QBasic rounds or does something stupid with the numbers, because when you call them back in the different program they come out being some crazy numbers. Such as, with 0. it is a number so damned close to zero that it might as well be.

1.34950 E -49

See what I mean? Well, when you try to assign the above to the coordinate plane you get an error message.

THUS - - - > The question is, WHY does Qbasic do this, and HOW do I fix it. Thank you.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
Nova,
I don't see any type declaration. One possibility might be if you wrote the data as one type, say INTEGER, and read it as another, say SINGLE. If you did this, you would probably run out of data, unless you've written all of the data to one file. If you have written all of the data to one file, you might be reading from the wrong place in the file. Either way the value you are getting is not an integer, even though all of your data appears to be integers. You might want start by dimensioning PlaceX and PlaceY as integers in both programs.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#3
Yeah, that's a *very* small number, so you'll have to make the numbers into integers Smile

And have you specified a file structure for your random file (the origional use of TYPE)?
Reply
#4
Errm, I didn't use TYPE....

I said this essentially:

Code:
DIM PLACEX(50)  'make sure there's enough...
DIM PLACEY(50)
OPEN "1.plc" FOR RANDOM AS #1
FOR I = 1 TO 10
READ PLACEX(I)
READ PLACEY(I)
PUT #1, , PLACEX(I)
PUT #1, , PLACEY(I)
NEXT I
CLOSE #1
DATA 0,0,100,20,30,50,32,59,239,54,38,185,123,456,123,543
DATA 10,9,8,7
'NOTE: I MADE THESE UP ^ ^ ^

That's what I did to make the ".plc" files.... I did it around 50 times I figure...

Then in the program, the actual 'game' I dimmed the placex and placey as so

Code:
'$DYNAMIC
DIM SHARED PLACEX(50) 'does it matter if they are
DIM SHARED PLACEY(50)'shared?
OPEN "1.plc" FOR RANDOM AS #1
FOR I = 1 to 10
GET #1, , PLACEX(I)
GET #1, , PLACEY(I)
NEXT I
CLOSE #1
HarLoadPut "EVGRNTREE", MyArray() 'harloadput is a
FOR I = 1 to 6                                     'sub to load .put files
PUT (PLACEX(I),PLACEY(I)), MyArray, PSET
NEXT I
HarLoadPut "BRCHTREE", MyArray()
FOR I = 7 to 10
PUT (PLACEX(I), PLACEY(I)), MyArray, PSET
NEXT I

Which, by the way, is A LOT more efficient than my old method....
Code:
HarLoadPut "EVGRNTREE", MyArray()
PUT (0,0), MyArray, PSET
PUT (123,456), MyArray, PSET
PUT (1,2), MyArray, PSET
PUT (3,4), MyArray, PSET
PUT (5,6), MyArray, PSET
PUT (7,8), MyArray, PSET
HarLoadPut "BRCHTREE", MyArray()
PUT (9,10), MyArray, PSET
PUT (20,30), MyArray, PSET
PUT (40,50), MyArray, PSET
PUT (60,70), MyArray, PSET

You have to realize that in a usual screen there are about 30 items, so that would equate to 30 PUT statements, and it was, and is, just a big ol' mess.

So do you want me to reorginize somehow? Consider this when replying: I am a newbie. Answer me like you would a newbie. Unless it is somewhat technical, I could kind of understand...Yeah, so thanks! This game means a lot to me...
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#5
Nova,
Try putting this:
Code:
DEFINT A-Z
at the start of all your modules. It will make all variables integers, unless you dimension them otherwise (Note: if you do need some variables to be single precision or long integers you will have to dimension them). Now we know that we are working with integers. Make a new data file. Put a test line in your code to print the values you read from the file:
Code:
'$DYNAMIC
DIM SHARED PLACEX(50) 'does it matter if they are
DIM SHARED PLACEY(50)'shared?
OPEN "1.plc" FOR RANDOM AS #1
FOR I = 1 to 10
GET #1, , PLACEX(I)
GET #1, , PLACEY(I)
'---Test code ---
locate I, 1: PRINT PLACEX(I); PLACEY(I);
'---End Test Code----
NEXT I
CLOSE #1
Compare the values with what you expected. If They are the same then your file handling is okay, and you check further down the line. If not, see if you can see a pattern in the errors.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#6
Yeah, I've done that before. When you print the code within the same program it always works...
Code:
DIM PLACEX(50) AS INTEGER
DIM PLACEY(50) AS INTEGER
'lets pretend there's data ... ok?
OPEN "1.PLC" FOR RANDOM AS #1
FOR I = 1 TO 10
PUT #1, , PLACEX(I)
PUT #1, , PLACEY(I)
NEXT I
CLOSE #1

'and then...

OPEN "1.PLC" FOR RANDOM AS #1
FOR I = 1 TO 10
GET #1, , PLACEX(I)
GET #1, , PLACEY(I)
PRINT PLACEX(I), , PLACEY(I)
NEXT I
CLOSE #1

That always comes out right. However, if you start a new program and do just the bottom portion (with DIM PLACEX/Y(50)) it comes out as really really small numbers or just off by some unimportant decimal point. The only REAL problem is the zeros and the 320s and the 200s, because they are at the edge of the screen. All of the other coordinates can be off by a little bit and it won't matter, but QBasic gets upset when it has to post at a place that is an extremely small integer.

NOTE: I am gonna try changing all of the 0's and 320's and 200's to 1's 319's and 199's... and see if that helps. Unless someone can find a way to make the data come out right. Thanks for your guys' help tho. :bounce:
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#7
Nova,
if you use DEFINT A-Z you shouldn't be getting anything off by decimal places. Everything should be integers (whole numbers).
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#8
Nova,
I tried both programs. The data retrieved from the file was the same as the data put in it. Sorry I didn't try this earlier. You had a comment in your code:
Code:
DIM SHARED PLACEX(50) 'does it matter if they are
DIM SHARED PLACEY(50)'shared?

Having it shared through out the module could be your problem. If you change arrays called PLACEX() or PLACEY() in any of your subs, it changes it throughout the module. It is better to pass them through the parameter list of the sub, or use the line
Code:
SHARED PLACEX(), PLACEY()
at the beginning of those subs that you want to share these arrays.

If you need to change values in the sub but don't want to change the arrays outside of it, you should use BYVAL in the parameter list.
Code:
SUB MYSUB(BYVAL PLACEX(), BYVAL PLACEY(), Parameter3, ...)
'Code
'Code
END SUB
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#9
Make a map file with different characters in it based on what you want in different locations, and read from it and place your tiles accordingly.

eg: map.map:

1111214315431
1414254261111
1211165265211
1415641116512

Code:
DEFINT A-Z
DIM SHARED Map(1 TO 13, 1 TO 4)
DIM SHARED Tiles(1 TO howevermanytilesyouhave)

LoadTiles   ' Imaginary sub that loads your tile pics into the Tiles Array
OPEN "map.map" FOR INPUT AS #1
FOR Y = 1 TO 4
  INPUT #1, row$
  FOR X + 1 TO 13
    Map(X, Y) = MID$(row$, X, 1)
  NEXT X
NEXT Y

' Placing the tiles
FOR Y = 1 TO 4
  FOR X = 1 TO 13
    PUT(X * 20 - 20, Y * 20 - 20), Tiles(Map(X, Y)), PSET
  NEXT X
NEXT Y

Much better for making heaps of maps Smile

BTW: You use types like:

TYPE MapType
PLACEX AS INTEGER
PLACEY AS INTEGER
END TYPE

DIM Map AS MapType

OPEN "1.plc" FOR RANDOM AS #1 LEN = LEN(MapType)
' FOR statement
GET #1, , Map.PLACEY
GET #1, , Map.PLACEY
CLOSE #1
Reply
#10
And having the TYPE helps... how?
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)