Posted: Mon Jun 04, 2012 8:01 pm Post subject: Re: Text-Based Adventure I was working on last year, figured I'd look over it and ask for some opinions on it
haha there's too many users too remember XD hello again though.
So basically I like to consider them as arrays with multiple directions. They can work in different ways. For instance, you could just imagine a chain, where one link is touch the next link and the one before it, or a tree where each link is holding two links below it, and you have one original link at the top. In this case, you could do something like the tree one. I'll tell you a bit about the first one.
You would start with this:
Turing:
var link :collectionof record
previous, next : ^link
contents :string endrecord
var current :^ link
new link, current
current -> previous :=nil
current -> next :=nil
So look at what we have here. There's a collection with three things: a pointer to the next link, a pointer to the previous link and a contents variable that'll hold some info. So far there is only one link, so we say that the current and next links have nothing, i.e. nil. There are different ways to go about doing this, but this is what I do. Now lets say we wanted to move to the next link in the chain. We would do this:
Turing:
new link, current -> next
current -> next -> previous := current
current := current -> next
This might look a bit confusing, so we'll break it down. First we initialize the pointer next so we can use it. (Idk if that's necessary, I'm just used to classes. Kindof similar in turing). Then we have this statement:
current -> next -> previous := current
In other words, we want what the previous of whatever next is to be whatever you're at now. If you just tried to move on to next without this statement, previous would have nothing in it, and so you would lose current. The idea of a linked list is to have everything linked, remember?
current := current -> next
We want current to now be on the next link. Pretty straightforward.
So it might be a bit confusing, but it can come in handy sometimes. I'll show you a game I made with this idea.