
-----------------------------------
chaos
Tue Aug 09, 2011 6:58 pm

2D Mapping
-----------------------------------
I understand the basics of file I/O. I have attached a map and its corresponding program. The problem is that when I run the program, I get an error message saying "Invalid Integer Input". What exactly does this mean and what exactly can I do to fix this problem?

-----------------------------------
DemonWasp
Tue Aug 09, 2011 8:17 pm

RE:2D Mapping
-----------------------------------
It's telling you that the first line in your data file, which is "1111111111111111111111111111111" isn't a valid integer. What it's hinting at is that that's way, way behond the maximum integer size.

What you actually wanted to do was get the first character, not line. Look up the get command (here: http://compsci.ca/holtsoft/doc/get.html or in the Turing help). It shows several different forms your get command can take. You need to limit the width that you get at a time, so you should use syntax: (d) variableReference : widthExpn.

Try that yourself, and if you can't figure it out, report back to this thread.

-----------------------------------
chaos
Tue Aug 09, 2011 9:40 pm

Re: 2D Mapping
-----------------------------------
The only thing that I can think of and that I have tried is modifying my array and text file to make it smaller. 
Also, I tried using this code:

        get:num,map:1
        put map..



Is this code correct?

-----------------------------------
DemonWasp
Wed Aug 10, 2011 7:45 am

RE:2D Mapping
-----------------------------------
No. You are close, and the ': 1' is correct, but you probably meant 'draw(x,y)' instead of 'map'. It should be: get : num, draw(x,y) : 1

You should also be careful, because getting one character at a time may mean you get newline characters -- be sure to consume those without trying to convert to integer.

-----------------------------------
chaos
Wed Aug 10, 2011 10:42 am

Re: 2D Mapping
-----------------------------------
I tried what you said and I got an error message saying "    'get' width ony applies to strings and char(n)". Does this mean that I have to convert change my array type from int to char?

-----------------------------------
DemonWasp
Wed Aug 10, 2011 11:50 am

RE:2D Mapping
-----------------------------------
Good guess! As a bonus, that means you can use something a little clearer than 0 = floor, 1 = wall. For example, you could use '.' = floor, 'X' = wall, which makes the map file a lot easier to look at.

-----------------------------------
chaos
Wed Aug 10, 2011 3:18 pm

Re: 2D Mapping
-----------------------------------
I did what you said, but when I ran the program, I still get the same error message. I  am not sure what to do at this point.

-----------------------------------
DemonWasp
Wed Aug 10, 2011 4:01 pm

RE:2D Mapping
-----------------------------------
Hmm. Could you post the source code? Don't post it in image format -- copy and paste your code between two "tags" that look like:

[ syntax = "Turing" ]

your code goes here

[ / syntax ]

except don't put the spaces in the tag lines.

-----------------------------------
chaos
Wed Aug 10, 2011 9:16 pm

Re: 2D Mapping
-----------------------------------
Here is my code. I have attached the new map as well. Also, you will need to change the file location. 



View.Set("graphics:150;150")
var draw:array 0..14,0..14 of char

var map:string:="G:/map.txt"
var num:int

open:num,map,get
for x:0..14
    for y:0..14
        get:num,draw(x,y):1
    end for
end for
close(num)

for x:0..14
    for y:0..14
        if draw(x,y)='O' then
            Draw.FillBox(x*10,y*10,x*10+10,y*10+10,red)
        else
            Draw.FillBox(x*10,y*10,x*10+10,y*10+10,black)
        end if
        delay(150)
    end for
end for



-----------------------------------
crossley7
Wed Aug 10, 2011 10:15 pm

RE:2D Mapping
-----------------------------------
Try 


open:num,map,get 
var temp: string
for x:0..14 
    get:num,temp
    for y:0..14 
        draw(x,y):=temp(y) 
    end for 
end for 
close(num) 
 

If you have no spaces in the text file this is a good and easy solution.  My guess is you are getting the newline characters and getting as a string then converting to char removes the issue.

-----------------------------------
DemonWasp
Thu Aug 11, 2011 10:59 am

RE:2D Mapping
-----------------------------------
crossley7 is correct: you are not handling newline characters (see: http://en.wikipedia.org/wiki/Newline ). His solution will handle that.

Once you get it working, you can add new features. For example, you may also want to put the size of the map at the top of the file -- then you can determine how big to make the array, without needing to rewrite anything in your source code.

-----------------------------------
chaos
Fri Aug 12, 2011 5:16 pm

Re: 2D Mapping
-----------------------------------
Thanks a lot! I finally got it work. But, the result is a flipped image. How exactly do I fix this?

-----------------------------------
DemonWasp
Fri Aug 12, 2011 10:00 pm

RE:2D Mapping
-----------------------------------
You need to start at the bottom of the array instead of the top -- but only in the Y direction. In the X direction, it should stay the same. You want:

for y : 14 .. 1 decreasing
