Qbasicnews.com

Full Version: Problem with INPUT #
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I made a program that writes a map to a file as a string array then I made a program that simply loads it. I tried leaving 2 lines from the top off for a menu in the map loader program. Here is part of the code:

Code:
DIM map$(6)  

      OPEN "map.zul" FOR INPUT AS #1
        INPUT #1, map$(1)    'inputs the map from the file (prints it at
        INPUT #1, map$(2)    'location 1, 1)
        INPUT #1, map$(3)
        INPUT #1, map$(4)
        INPUT #1, map$(5)
        INPUT #1, map$(6)
        INPUT #1, srow         'other variables, for the starting point
        INPUT #1, scol
      CLOSE #1

    LOCATE 3, 1    'locates the line under the 2 lines I left off
    PRINT map$(1)    'prints map (prints at 3, 1)
    PRINT map$(2)
    PRINT map$(3)
    PRINT map$(4)
    PRINT map$(5)
    PRINT map$(6)
    ...........

The problem is that it seems to print an "invisible" copy of the map starting at 1, 1 but it prints the graphics at 3, 1. That means that the player does not detect the walls created at 3, 1; but it detects the "invisible" walls created at 1, 1. The INPUT # commands seem to have created the invisible walls. Is there a way that I can print the map at 3, 1 or loading each string variable then printing it?
Do you have an example of the data file you could throw in here? maybe the problem is in the data file itself...from the code I'm seeing, I'd say it's what it looks like.
Here is the file copied from exactly fromnotepad, without the comments:

Code:
ÛÛÛÛÛÛÛ     'Û = Wall, char 219  
Û     Û     'S = start point
Û     Û    
Û  S  Ã›    
Û     Û    
ÛÛÛÛÛÛÛ    
6                   'row of start point (including 2 lines left out on top)
4                   'column of start point

Oh yeah, and here is how I wrote it to the file:

Code:
OPEN "map.zul" FOR OUTPUT AS #1
  PRINT #1, map$(1)
  PRINT #1, map$(2)
  PRINT #1, map$(3)
  PRINT #1, map$(4)
  PRINT #1, map$(5)
  PRINT #1, map$(6)
  WRITE #1, srow
  WRITE #1, scol
CLOSE #1
Jotz,

Just from looking at what you have posted, it seems like you actually have two problems.
The first problem is that you have'nt placed any "space" within the "output" portion for the menu.
i;e:

OPEN "map.zul" for output as 1
PRINT #1, String$(M,N):Close 1
Where m = the number of characters the menu will use up and N = the ascii chr. you wish to use as a space holder.
I personally use chr$(32) (space bar chr.)
This will use up the space.

The second problem is that you haven't "told" the program where the actual wall is to be.
i,e; IF R = 3 THEN...
or IF C = 1 AND R = 3 THEN...
See what I mean. The program is using the "default" Col./Row within the actual screen limits.

I apologize if I miss read your post.
dadsherm, I have tried the first solution you said, but it still wanted to print it in a different place. But could you explain the second solution a little further?

And simply for everyone, I want to print an array of strings in a place other than 1, 1 that is read from a file.
Hmmm.

I must have really mis-understood. :oops:
If I understand you correctly now, you already used a "filler" of some sort to take up the room set aside for the menu.
When the program opened the file this was saved in, it should have started printing at 1,1 unless of course, you set a different spot for it to print at.
As for the "walls" portion, since you have it starting to print at 3,1
the program should be printing it out the way you "told" it to.
Is this where the problem lies?
If so it's a matter of telling the computer where the "new" boundrie is. In this case Row 3, Col. 1.
The "Locate" command is used to determine where the item is to be printed at. Unfortunately, in this case, it doesn't create a barrier (or wall) of sorts, as in: (THOU SHALL NOT CROSS THIS LINE!)
You will have to tell the computer where the "wall" is for every situation.
To put it another way, you can have LOCATE 3,1 for the first place for it to print, but the second item to be printed will have to be told where to print at.
(i;e, LOCATE 4,1 if this is where you want it), and so on.
There are other ways of doing this, but this is by far the easiest way to understand what's going on.
This is what I meant by "IF Row = 3 THEN..."
For instance you could have it as :
IF Row = 3 Then Row = 7.
This will cause the "s" to drop to the 7th Row while remaining in the same Col.
Likewise, you could have it as :
IF Row = 8 THEN Row = 4
Why 4 instead of 3?
The difference is that you wouldn't want the "s" to land on top of the "wall", so you have it "land" 1 row (or col. Depending which way it's moving), short of the boundrie lines.
(This is the best way to write a "miniture" options "window".
A lot of programs will have the highlited line go to the top or bottom and stop. In order to get the "highlited" line to go back the opposite direction, you use the opposite button.
A better way is to have the "highlited" line appear to "loop" around. )

I'm really not very good at explaining things, :roll: , so if you seem more confused now than before, don't feel bad.
Maybe one of the others on here can explain it better than I can.
Or if you like, I can send you a small program I have that will show/explain it to you a little better.
I do hope this helped you though.
Well, I figured it out, but thanks a lot for the help anyway. It turned out that the number in the array map$() also told the line that it would INPUT onto. I made the first map$() array 3, so that it would start printing on line 3. Then I was able to continue freely with the other arrays with no problems.