Re: Don't look now, but build 1000 is nearing...
Well, because in C, the language ZScript is based off of, we do this:
Code:
mystruct foo; //doesn't really matter what this is, exactly
foo.x = 1; //set the x member of foo to 1
mystruct* fooptr = &foo; //take a pointer to foo. Remember: fooptr == foo
printf("foo.x: %d", fooptr->x); //prints "foo.x: 1"
With a normal struct (UDT, class, whatever), you get to use the dot operator, like in BASIC and other languages. However, when you add a pointer into the mix, then you need to tell the computer "I want to deal with the object being pointed at, not the pointer itself". So, you get to use the dereferencing operator instead.
Re: Don't look now, but build 1000 is nearing...
I once thought that a period would be nicer to use, but the dereferencing operator is much less ambiguous, more accurate to the parent language, and easier on the compiler.
The only advantage to the somewhat ambiguous period is that it takes fewer keystrokes. It would make perfect sense if ZC used, say, Python for scripting.
On the other hand, I can't really site an instance when one would use the dot operator. As far as I know, ZScript doesn't have structs.
Re: Don't look now, but build 1000 is nearing...
Quote:
Originally Posted by
pkmnfrk
Well, because in C, the language ZScript is based off of, we do this:
Code:
mystruct foo; //doesn't really matter what this is, exactly
foo.x = 1; //set the x member of foo to 1
mystruct* fooptr = &foo; //take a pointer to foo. Remember: fooptr == foo
printf("foo.x: %d", fooptr->x); //prints "foo.x: 1"
With a normal struct (UDT, class, whatever), you get to use the dot operator, like in BASIC and other languages. However, when you add a pointer into the mix, then you need to tell the computer "I want to deal with the object being pointed at, not the pointer itself". So, you get to use the dereferencing operator instead.
ZScript has structs? When did this happen? I've never seen pointers anywhere in any ZScript I've ever looked over either, at least not as I've grown to know them.
Maybe I don't know what I'm talking about, as I'm no expert on C, but nothing should ever be followed off of a cliff. When mimicking C precisely becomes more important than making a usable language, you have a problem.
Re: Don't look now, but build 1000 is nearing...
No, ZC doesn't have structs (although, that would be made of awesome. But, finish strings first!).
However, it does have pointers, if not the same was as in C. All those "ffc"s and "npc"s and "item"s and stuff we like throwing around are "pointers" to the underlying objects. The fact that we can reassign what a given variable points at is a clue. ("Link" and "Screen" and stuff are pointers too, but since there's only one of those, you can't reassign them.)