Computer Science Canada

Huge project, few questions

Author:  Nathan4102 [ Fri Jul 26, 2013 8:54 pm ]
Post subject:  Huge project, few questions

Hey guys! I've been planning a huge project lately, it's a huge strategy game that will probably take me a couple months to make. I've got a question though. So in my game you'll be able to walk around a 2d town. How do you guys suggest I do this? I was thinking I could photoshop a huge map image, load it at the beginning, and then scroll it around when the character walks, with programmed obstructions and stuff, but is there a better way?

Thanks!
Nathn

Author:  Insectoid [ Fri Jul 26, 2013 8:58 pm ]
Post subject:  RE:Huge project, few questions

You could use an ASCII map, which is basically a text file representing, well, the map. Each character corresponds to a different object type- grass, roads, bushes, walls, doors, etc. All your movement, collisions, etc. take place on this map. You can then draw the world either with a photoshopped image, or by assigning a sprite to each character in the ASCII map and drawing the map based on that. Many old (and some new) games use this method.

Author:  Raknarg [ Fri Jul 26, 2013 8:59 pm ]
Post subject:  RE:Huge project, few questions

Personally I would make tile images for the whole game. That way you could have customizable maps and you could just draw a few small pictures instead of one huge one, which is a lot slower. Not only that, but it would be much easier to program obstructed areas, by far.

If you do go the way you're planning, split the map into a bunch of smaller maps so you can just draw whats visible rather the always the whole thing.

edit: Instectoid got there first. Mix text files with tiles, and it becomes a lot easier.

Author:  Nathan4102 [ Fri Jul 26, 2013 9:23 pm ]
Post subject:  RE:Huge project, few questions

Wow, I never thought about using tiles... That would make everything A LOT easier. I like your idea about an ASCII map Insectoid, I'll probably use that!

I've got a decent idea on how to draw this, so we'll see how it goes! Very Happy

Thanks!

Author:  Raknarg [ Fri Jul 26, 2013 10:06 pm ]
Post subject:  RE:Huge project, few questions

I started an RPG a while ago, and it had a cool tile system... basically it was a text file, and each tile had two parts. The first part in lowercase would indicate what tile it was by name of the jpg, and the second part would indicate what directions it was inaccessible from. Thats how I could easily include objects with obstruction.

For instance, lets say you had a tile with a cliff that was high on top and low on bottom. The text for that could be clftB

That means cliff tile, top high, inaccessible from the bottom.

Just an idea

Author:  Nathan4102 [ Sat Jul 27, 2013 7:29 pm ]
Post subject:  RE:Huge project, few questions

I'll use that too! xD Thanks!

I got another questions now. So I'm making my map in a txt file, but I don't want it to be easily editable. In turing, I don't think you can add files to your .exe without including it in the .t file, so I came up with another way.

I'd like to make the map in plain text, and then convert every character to binary. The binary would look like gibberish to anyone who isn't really tech savy. Now is there a way in turing to quickly convert a character to its binary form, and back? Sure, I could do a huge case statement, but I have a feeling theres a better way! :p

Thanks!

Author:  Raknarg [ Sat Jul 27, 2013 8:15 pm ]
Post subject:  RE:Huge project, few questions

Turing:

fcn toBinary (x : int) : string
    var total := ""
    var newX := x
    var n := 0
    loop
        if newX - 2 ** n < 0 then
            n -= 1
            exit
        else
            n += 1
        end if
    end loop
    for decreasing i : n .. 0
        if newX - 2 ** i < 0 then
            total += "0"
        else
            total += "1"
            newX -= 2 ** i
        end if
    end for
    result total
end toBinary

fcn toDec (x : string) : int
    var total := 0
    var len := length (x)
    for decreasing i : length (x) .. 1
        total += strint (x (i)) * 2 ** (len - i)
    end for
    result total
end toDec

put chr (toDec (toBinary (ord ("H"))))


make functions to convert from decimal to binary and from binary to decimal. I would encourage you to try it yourself.

Author:  Nathan4102 [ Sat Jul 27, 2013 10:36 pm ]
Post subject:  RE:Huge project, few questions

O.o I'd need to read up on how to convert decimal to binary, I've never really looked into that stuff. For now, I'll use your function, but I'll make my own soon! Thanks!

I think I'm done for tonight, I can already tell this is going to be a lot of fun! Very Happy

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  Raknarg [ Sat Jul 27, 2013 10:42 pm ]
Post subject:  RE:Huge project, few questions

It always is. Just make sure you set your priorities right, plan out how you're going to build this project before you throw yourself into it.

Author:  Nathan4102 [ Sat Jul 27, 2013 10:51 pm ]
Post subject:  RE:Huge project, few questions

I've got a 4 page layout of what the game is gonna contain and stuff, but as for how I'm building it, I'm just build it, no plans, just keep adding to it and watch it grow. It seemed to work for my other projects, So.... Wink

Author:  Raknarg [ Sat Jul 27, 2013 11:03 pm ]
Post subject:  RE:Huge project, few questions

Haha well you might run into issues. I did the same thing a while ago, I started working on a big game in grade 10. Ended at well past 2000 lines, and it was hard to make any changes because there was just so much to change. For smaller projects its easy to change things on the fly, but for larger ones it's not always quite as easy

Author:  Nathan4102 [ Sat Jul 27, 2013 11:20 pm ]
Post subject:  RE:Huge project, few questions

Jesus, a 2000 line project in grade 10? What on earth were you making? xD My summative was 400 lines, and I got 105%. This game will be around 3-5k lines when I'm done, I'm assuming, so HOPEFULLY I don't run into too many problems. If I do, at least its just a project for fun, and not a final!

Author:  Raknarg [ Sat Jul 27, 2013 11:35 pm ]
Post subject:  Re: Huge project, few questions

I was busy making this space shooting game, but if I remember correctly 1200 lines are dedicating to all the enemy drawings... I hard coded them so I could manipulate them.

It's also written like garbage haha I've rewritten it a couple times in the past

You wont be able to run it without removing all the picture stuff in the program though.

Author:  Dreadnought [ Sun Jul 28, 2013 12:52 am ]
Post subject:  Re: Huge project, few questions

If you're going to do any work at all in binary it would be good to learn bitwise operators. In Turing these are |, &. shl, shr, xor, and ~.
You can also look into storing the characters in hexadecimal, your text file will be about 8 times smaller and should be just as incomprehensible as the binary version.

Also Turing already has functions to convert to and from binary representation:
Turing:
intstr(10, 0, 2) >> "1010" % indentical to Raknarg's toBinary function

strint("1010", 2) >> 10 % identical to Raknarg's toDec function

Author:  Raknarg [ Sun Jul 28, 2013 12:58 am ]
Post subject:  RE:Huge project, few questions

haha wow I had no idea

Author:  Nathan4102 [ Sun Jul 28, 2013 11:02 am ]
Post subject:  Re: Huge project, few questions

Raknarg @ Sun Jul 28, 2013 12:35 am wrote:
I was busy making this space shooting game, but if I remember correctly 1200 lines are dedicating to all the enemy drawings... I hard coded them so I could manipulate them.

It's also written like garbage haha I've rewritten it a couple times in the past

You wont be able to run it without removing all the picture stuff in the program though.


Wow... xD

And thanks for the suggestions Dread! That's probably actually a good idea, since I'll have 4 or 5 characters per 20x20 tile, the text file could get pretty big if I used binary.

Edit: Now I gotta figure out how to do decimal to hex... :/

Author:  Raknarg [ Sun Jul 28, 2013 12:06 pm ]
Post subject:  RE:Huge project, few questions

If you want to use dreadnaughts solution, you just replace the 2's with 16's and it then works in hex

Author:  jr5000pwp [ Mon Jul 29, 2013 9:54 am ]
Post subject:  Re: RE:Huge project, few questions

Nathan4102 @ Sat Jul 27, 2013 11:20 pm wrote:
Jesus, a 2000 line project in grade 10? What on earth were you making? xD My summative was 400 lines, and I got 105%. This game will be around 3-5k lines when I'm done, I'm assuming, so HOPEFULLY I don't run into too many problems. If I do, at least its just a project for fun, and not a final!
My grade 10 project was 5726 lines. My case really highlighted the necessity of well thought out code. I had the idea to make a minecraft 2D clone early in the semester, maybe a month or two in. I started it one way, refactored it to work another way, added features, and refactored some times. My issue was that I would refactor one file down from 800 lines to 150 but became too lazy to do the second file. Another issue was that I was too lazy to refactor my main segments of code to a better design, take for example, a segment of my collision code:
Turing:
% If the character is moving right
if chars (rightkey) then
        % If the block at the players feet after moving is air, torch, or open door then continue
        if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 0
                or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 15
                or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 18
                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).dooropen = 0) = true
                or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 19
                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).dooropen = 0) = true)
        then
                % If the block at the players torso after moving is air, torch, or open door then continue
                if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 0
                        or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 15
                        or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 18
                        and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).dooropen = 0) = true
                        or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 19
                        and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).dooropen = 0) = true)
                then
                        % If the block at the players head after moving is air, torch, or open door then continue
                        if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 0
                                or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 15
                                or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 18
                                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).dooropen = 0) = true
                                or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 19
                                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).dooropen = 0) = true)
                        then
That's obviously not very friendly to change, if I wanted to add additional functionality, change current functionality, or track down a bug I'd be in for a word of pain.
My recommendation would be to think before you program. It's very easy to just hardcode stuff or use tons of if statements etc. but it will bite you in the end. Take a few minutes, think about what you need to do, think about how you can do it, and find the best solution for it. Had I done that when making my game I would have thought of a 1 minute solution to improve the code
Turing:
function CheckCollision(x, y : int) : boolean
        if getblockfloor (x, y).blockid = 0
                or getblockfloor (x, y).blockid = 15
                or ((getblockfloor (x, y).blockid = 18
                and getblockfloor (x, y).dooropen = 0) = true
                or (getblockfloor (x, y).blockid = 19
                and getblockfloor (x, y).dooropen = 0) = true)
        then
                result false
        else
                result true
        end
end CheckCollision

if chars(rightkey)
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)) = false
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15) = false
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29) = false
then
This code is no where near perfect either, but it's better.

Author:  Raknarg [ Mon Jul 29, 2013 6:25 pm ]
Post subject:  RE:Huge project, few questions

My friend made a program well over 10000 lines because noone had introduced him to arrays.

Author:  Nathan4102 [ Mon Jul 29, 2013 8:39 pm ]
Post subject:  RE:Huge project, few questions

10 thousand lines... I imagine that was fun to write... and fun to read for the teacher xD

I might end up plannign out all the programming for this thing after all. When I go to work on it, I end up only getting 20-30 lines down, because I spend the whole time trying to figure out the best way to do what I want to do. We'll see how it goes

Author:  Raknarg [ Mon Jul 29, 2013 10:00 pm ]
Post subject:  RE:Huge project, few questions

Thinking is half the process.

Maybe getting you ideas down here might help.

Author:  Nathan4102 [ Tue Jul 30, 2013 2:47 pm ]
Post subject:  RE:Huge project, few questions

I would put my ideas here, but I kind of wanted to try to do this with as little help as possible. I could do some sort of development progress thread or something, you think I should?

Author:  Raknarg [ Tue Jul 30, 2013 5:45 pm ]
Post subject:  RE:Huge project, few questions

Whatever you want, it's your progress. Either you want to tell people what you've accomplished or you want help from outside sources, if you don't care about either, then dont. Otherwise, go crazy.

I don't know if it's against posting rules or whatever, but you can probably post it under submissions, or at least off topic.

Author:  Nathan4102 [ Thu Aug 08, 2013 9:49 pm ]
Post subject:  RE:Huge project, few questions

Man...

Ignoring your guy's' suggestions to think out my code before I go was a bad idea. Now I'm getting into this, and my code is A MESS. Look at this crap!

Turing:
for i : 1 .. llength
        for ii : 1 .. height
            case text (ii) (i) of
                label "R" :
                    Pic.Draw (pic (1), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "G" :
                    Pic.Draw (pic (2), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "B" :
                    Pic.Draw (pic (3), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "V" :
                    Pic.Draw (pic (4), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "H" :
                    Pic.Draw (pic (5), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "1" :
                    Pic.Draw (pic (6), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "2" :
                    Pic.Draw (pic (7), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "3" :
                    Pic.Draw (pic (8), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "4" :
                    Pic.Draw (pic (9), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "q" :
                    Pic.Draw (pic (14), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "w" :
                    Pic.Draw (pic (15), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "e" :
                    Pic.Draw (pic (16), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "r" :
                    Pic.Draw (pic (17), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "a" :
                    Pic.Draw (pic (18), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "s" :
                    Pic.Draw (pic (19), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "d" :
                    Pic.Draw (pic (20), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "f" :
                    Pic.Draw (pic (21), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

            end case
        end for
    end for


I think I'm going to end up having to redo some of this, there's no way I'm going to be able to troubleshoot or modify my game with this kind of code.

Next time I'll listen to you guys :p

Author:  Raknarg [ Thu Aug 08, 2013 9:59 pm ]
Post subject:  RE:Huge project, few questions

Here, lets fix that for you.

Turing:

const Char : array 1 .. 21 of string := init ("R", "G", "B", "V", "H", "1", "2", "3", "4", " ", " ", " ", " ", "q", "w", "e", "r", "a", "s", "d", "f")

fcn indexArray (s : string) : int
    for i : 1 .. 21
        if Char (i) = s then
            result i
        end if
    end for
    result 0
end indexArray

for i : 1 .. llength
    for ii : 1 .. height
        Pic.Draw (pic (indexArray (text (ii)(i)), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)
    end for
end for


always look for ways to condense.

Also, everyones got to learn at some point. At least now you know fairly early on and you can change it.

Author:  chrisbrown [ Thu Aug 08, 2013 10:29 pm ]
Post subject:  Re: Huge project, few questions

One step further?

Turing:
const pic : array char of int := init ( 0 );
pic('R') := Pic.New(...)
pic('G') := Pic.New(...)
...

for i : 1 .. llength
    for ii : 1 .. height
        Pic.Draw (pic (text (ii) (i)), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)
    end for
end for

Author:  Raknarg [ Thu Aug 08, 2013 10:33 pm ]
Post subject:  RE:Huge project, few questions

Good call, I forgot you could have an array of chars.

Author:  Nathan4102 [ Fri Aug 09, 2013 11:44 am ]
Post subject:  Re: RE:Huge project, few questions

Nathan4102 @ Tue Jul 30, 2013 3:47 pm wrote:
I would put my ideas here, but I kind of wanted to try to do this with as little help as possible. I could do some sort of development progress thread or something, you think I should?


This is why I didn't want to put my code on here xD

Thanks for the help, I'll use your code just this one time, but the rest of it I want to do myself. :p

Author:  Raknarg [ Fri Aug 09, 2013 8:52 pm ]
Post subject:  RE:Huge project, few questions

then dont post specifics :p

And you shouldn't get the notion that using others' code = bad programming. A lot of times, programming is just taking stuff that other people have made and figuring out how it goes together. There's lots to be learned on your own, but theres lots you can be taught as well.

In any case, carry on.

Author:  Nathan4102 [ Fri Aug 09, 2013 9:44 pm ]
Post subject:  Re: RE:Huge project, few questions

Raknarg @ Fri Aug 09, 2013 9:52 pm wrote:
then dont post specifics :p

And you shouldn't get the notion that using others' code = bad programming. A lot of times, programming is just taking stuff that other people have made and figuring out how it goes together. There's lots to be learned on your own, but theres lots you can be taught as well.

In any case, carry on.


The reason I wanted to try to do this all on my own was to see if I could finish a large project like this by myself, but I understand what you mean. Just reading those few code snippets in the last couple posts gave me some ideas on how to improve quite a few parts of my program. And now in the future, I'll be able to solve similar problems using methods I've learned from you guys.

I think I am going to create a project progress thread for this, because of what you said. I enjoy learning by myself, but there's only so much I can learn this way, and I might grow some bad habits along the way.

Author:  Raknarg [ Fri Aug 09, 2013 10:23 pm ]
Post subject:  RE:Huge project, few questions

You're already on a better start than most people ever will, imho.

Author:  Nathan4102 [ Fri Aug 09, 2013 10:30 pm ]
Post subject:  RE:Huge project, few questions

Better start at what?

Author:  Raknarg [ Fri Aug 09, 2013 10:36 pm ]
Post subject:  RE:Huge project, few questions

just the learning process in general, and your extent of knowledge. As far as I know.

Author:  Nathan4102 [ Fri Aug 09, 2013 10:41 pm ]
Post subject:  RE:Huge project, few questions

Oh, well thanks, I guess. I don't think I'm doing any better than normal though. In fact, I feel I'm at a huge disadvantage to most since the only languages I know are dead/useless. Logic/knowledge is no good without a way to express it.

Just got an android phone though, so I'm hopefully gonna get into app development in Java, assuming this plan doesn't get put aside like all my other plans to learn Java :p

Author:  Raknarg [ Fri Aug 09, 2013 10:46 pm ]
Post subject:  RE:Huge project, few questions

everything I've learned from Turing has passed into Java as well. It may be annoying not beingable to express it, but it carries over quite easily.

You're grade 10 right? No one expects you to be amazing right now. I'm just saying you seem to be at a strong starting point

Author:  Raknarg [ Fri Aug 09, 2013 10:49 pm ]
Post subject:  RE:Huge project, few questions

btw @chris, you just blew my mind, the Input.KeyDown stuff makes sense now.

Author:  Nathan4102 [ Fri Aug 09, 2013 10:56 pm ]
Post subject:  RE:Huge project, few questions

Oh well thats good to know. I was expecting the transition from Turing to the OOP world of Java to be quite challenging.

Yeah, grade 10 last year, grade 11 this September. Thanks for the compliments, you don't seem too bad either. Wink

Author:  Raknarg [ Fri Aug 09, 2013 10:59 pm ]
Post subject:  RE:Huge project, few questions

Turing can be pretty OOP, if you let it become that way. You just need to learn how classes work is all.

Well I am going to university for it, so I'd hope i'm at least somewhat competent Razz and I just like to see students with real potential, who wants to learn, I don't get to see it all the time. I thinks its a good thing to see in any discipline, really.

Author:  Nathan4102 [ Fri Aug 09, 2013 11:14 pm ]
Post subject:  RE:Huge project, few questions

Turing can be OOP? It might be a good idea to learn the concept of OOP here then... Hmm.....

And I agree with you. Even if you're naturally good, you're only going to be able to go so far without a willingness to learn.

Author:  Raknarg [ Fri Aug 09, 2013 11:18 pm ]
Post subject:  RE:Huge project, few questions

mhm. Do you know how classes work in java at all? Because if you do, it's more or less the same concept inn turing with some syntax differences.

Author:  Nathan4102 [ Fri Aug 09, 2013 11:25 pm ]
Post subject:  RE:Huge project, few questions

Nope, I know next to nothing about classes. I read a bit about them a while back, but I just couldn't wrap my head around it.

Author:  Raknarg [ Fri Aug 09, 2013 11:27 pm ]
Post subject:  RE:Huge project, few questions

You could look at the Turing Walkthrough. Alternatively I could try my hand.. tomorrow

Author:  Nathan4102 [ Fri Aug 09, 2013 11:33 pm ]
Post subject:  RE:Huge project, few questions

I'll give it a read in the morning, getting pretty late now. Ill let ya know how it goes.

Author:  chrisbrown [ Sat Aug 10, 2013 1:35 pm ]
Post subject:  Re: Huge project, few questions

@Raknarg: The fun doesn't have to stop there. Look up indexType in the Turing documentation if you're interested. I was playing around for a bit and came up with a quick demo of the usefulness of Turing's range capabilities.
Turing:
setscreen("text")

for i : char
    %put i
end for
put "-----"

for i : boolean
    put i
end for
put "-----"

type CustomIntRange : 2 .. 10
for i : CustomIntRange by 2
    put i
end for
put "-----"

type CustomCharRange : 'a' .. 'e'
for i : CustomCharRange
    put i
end for
put "-----"

var a : array CustomCharRange of int := init(5, 4, 3, 2, 1)
for i : CustomCharRange
    put i, " ", a(i)
end for
put "-----"

Author:  Raknarg [ Sat Aug 10, 2013 3:46 pm ]
Post subject:  RE:Huge project, few questions

do other languages do this at all?

Author:  chrisbrown [ Sat Aug 10, 2013 4:55 pm ]
Post subject:  Re: Huge project, few questions

Most languages have some type of construct for dealing with this sort of problem, but it's rarely based on ranges like this. <a href="http://en.wikipedia.org/wiki/Foreach_loop">Foreach loops</a> are the standard way in most high-level languages. Turing is based on Pascal though so I wouldn't be surprised if it has something similar. I'm sure you can find others if you look hard enough. VHDL and Verilog have excellent range support but those are languages for hardware, not software.


: