-
Re: Regarding arrays
Oh, I get what you're doing now. I don't know that's even neccessary though. since ASCII chars already have a number value why do you need to assign them another?
I just tested this out and it works friggin great. Check it out, this was about as user freindly as I could make:
EDIT: Got it. :D
Code:
int string1[98] = "this is a test |this is only a test |if this had been an actual emergency, |you would be dead.";
int string2[25] = "abcdefghijklmnopqrstuvwxyz";
int string3[9] = {1,2,3,4,5,6,7,8,9};
int string4[9] = {1,2,3,4,5,6,7,8,9};
int string5[9] = {1,2,3,4,5,6,7,8,9};
int string6[9] = {1,2,3,4,5,6,7,8,9};
int string7[9] = {1,2,3,4,5,6,7,8,9};
int string8[9] = {1,2,3,4,5,6,7,8,9};
int string9[9] = {1,2,3,4,5,6,7,8,9};
global script test{
void run(){
while(true){
Waitframes(30);
Draw_String(1,98,0,0,6);
}
}
}
int temp[255];
void Draw_String(int string, int max_depth, int Xindent, int Yindent, int cset){
int x = Xindent; int y = Yindent;
int i; int t; int j; int k;
int tile = 520;
if(string==1){ for(i=0;i<=max_depth;i++) temp[i] = string1[i]; }
else if(string==2){ for(i=0;i<=max_depth;i++) temp[i] = string2[i]; }
else if(string==3){ for(i=0;i<=max_depth;i++) temp[i] = string3[i]; }
else if(string==4){ for(i=0;i<=max_depth;i++) temp[i] = string4[i]; }
else if(string==5){ for(i=0;i<=max_depth;i++) temp[i] = string5[i]; }
else if(string==6){ for(i=0;i<=max_depth;i++) temp[i] = string6[i]; }
else if(string==7){ for(i=0;i<=max_depth;i++) temp[i] = string7[i]; }
else if(string==8){ for(i=0;i<=max_depth;i++) temp[i] = string8[i]; }
else if(string==9){ for(i=0;i<=max_depth;i++) temp[i] = string9[i]; }
Waitframe();
for(i=0;i<=max_depth;i++){
for(k=0;k<4;k++){
for(j=0;j<=i;j++){
if(temp[j]==124){
t = tile + 32;
Screen->DrawTile(6,x,y,t,1,1,cset,1,0,0,0,0,true,128);
y+=8;x=Xindent;
}
else{
t = tile + temp[j];
Screen->DrawTile(6,x,y,t,1,1,cset,1,0,0,0,0,true,128);
x+=6;
}
}
x=Xindent;y=Yindent;
Waitframe();
}
}
}
http://i235.photobucket.com/albums/e...D/zelda007.jpg
-
Re: Regarding arrays
http://zctut.com/strings.zip
This is how I done it.
The original strings are in strings.tbl. It's a plain text file, comments start with @. Certain comments are special, such as the @bufname at the top. That tells strings.exe what to call the variable.
A string is said to be everything from the start of a line to the end. If a string ends in "\", it's "escaping" the new line at the end, and allows a string to span more than one line (with an embedded new-line). Also, you can explicitly embed control codes (or, rather, you will be able to), such as "\n" for new line, or "\c" for change cset.
anyway, drag strings.tbl onto strings.exe to create strings.zh. This is a very ugly file to inspect manually. Your strings are those ugly blocks of numbers and brackets that look like something out of the IOCCC competition. Don't worry about that.
Anyway, strings.zh defines 5 important things for your script:
* a string buffer (although, you shouldn't have to interact with this directly)
* a constant with the size of the buffer (again, it's primarily for internal use)
* a loadString(int) function, which allows you to load a string into the buffer.
* a loadString(int, int) function, which allows you to load part of a string into the buffer. The second parameter is how much to load. You can only load from the beginning to an arbitrary point.
* a stringLen(int) function, which returns the size of a string.
Combining the two last functions allows you to have, say, a block of text that slowly appears on screen.
The last file to look at is quest.z, which is the main script file. It has all the non-directly-related-to-strings stuff, such as the font-width definitions, a couple unrelated arrays, and the drawString() function.
drawString accepts 5 parameters: s_tile (the first tile in the font set, which should be ASCII 32), cset (the cset), lay (the layer), x and y (yeah).
Above this, in the onStart() script, I demonstrate how one could create a marquee (scrolling text). My intro is comprised of three strings, which slow scroll from bottom to top, one after another. As a speed optimization, it won't load and draw the string unless part of it is on screen.
Start a new game on the included quest to check it out in action.
-
Re: Regarding arrays
Wowsers. :odd: You made a seperate program to do that for you. That's pretty impressive. No wonder I couldn't make heads or tails out of what you were posting. ..Well then, carry on. :P
What's the max number of strings you can generate like that? ..And good god, how long did that take?
Looks awesome.
-
Re: Regarding arrays
Altogether, about three hours.
How many strings? Well, the program can do about 2 billion before it chokes, though I don't know how much ZC can handle.
I do know that obscenely long strings (500 chars+, maybe) cause ZC to barf a little in its mouth, and not do anything at all, but if you break them up like I did, it should be fine.
The main advantage of my method over yours is that I'm not relying on arrays being saved and loaded. You are. I bet your code would break if you saved, since right now arrays are borked. And, if that was fixed, then you couldn't ever change your arrays, since they're only set on a new game (in ~Init).
My way is more likely to chew up valuable room in the script buffer, but it won't break on new versions of the quest.
-
Re: Regarding arrays
...I should've finished implementing strings a long time ago. Ah well, Zscripters are resourceful as always XD
-
Re: Regarding arrays
Your mistake was to give me an inch. Strictly speaking, none of this requires strings proper, only arrays ;)
-
Re: Regarding arrays
I'm sure this program will have some useful applications. Nice brainstorming, guys. :thumbsup: