Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

[887] Cannot assign strings in ZScript

6 replies · 1,766 views · Started 18 November 2008

void test() {
int mystr[100] = "This is a string";
mystr = "This is another string?";
}

This causes the compiler to barf on the second statement:

ZQuest wrote:Pass 1: Parsing
Pass 2: Preprocessing
line 3: syntax error, unexpected QUOTEDSTRING, on token "This is another string?"
tmp, line 1: Error P01 : Failure to parse imported file quest2.z.

Yeah, I never did finish the implementation of strings, did I...

You can initialize strings just fine though. Will work on this some time or another.

User posted image

I think this may have been discussed prior to the forum meltdown, but:

While it's still not possible to assign strings, it IS possible to pass strings as arguments. So:

void strcpy(int src, int dest) {
int i;
for(i = 0; src[i] != 0; i++) {
dest[i] = src[i];
}
dest[i] = 0;
}

Other implementations of standard C functions are NOT forthcoming.

Gleeok wrote:Does this mean no strcmp()? 😞


Okay, fine...

int strcmp(int a, int b) {
int j;
for(j = 0; a[j] != 0 && b[j] !=0; j++) {
if(a[j] < b[j]) return -1;
if(a[j] > b[j]) return 1;
}
if(a[j] == b[j]) return 0;
if(a[j] == 0) return 1; else return -1;
}

First person to ask for sprintf gets a flogging!

I'm going to say that this is not a bug. It's possible to use strcpy as I showed above to copy strings around. Though, we don't have true string literals to make this easy. However, that's a separate issue.