PDA

View Full Version : Auto Line break making sign NPC


grim_squeaker_x
06-24-2001, 06:20 PM
Okay basically this NPC will take a string, tokenize that string and automattically put in line breaks when one line get's too large, here it is:
// NPC made by Lady Midnight
if (created) {
this.maxlinelength=32;
this.lettersusedonline=0;
setstring test.string,This is just a test of an auto line break making system I hope I can get it to work as it would be pretty cool for editable news and stuff :) and okay at this point I'm just going to put in some filler don't be surprised if you see strange stuff ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz boring isn't it? Oh well the point of this is to make it as long as possible so I guess that's okay... Some other possible uses could be a guestbook. A place where people can write books in Graal and if you think long and hard about it a real lot of stuff. Anyway this is my biggest string manipulation yet. I think I might put in something for adding line breaks to it <br> or whatever. If you're wondering why there's nearly no puntuation that has to do with the fact that it somehow doesn't accept commas :(
}
if (playertouchsme) {
setstring player.readingpage,0;
setstring sign.readstring,;
tokenize #s(test.string);
this.lettersusedonline=0;
for (this.i=0;this.i<tokenscount;this.i++) {
this.lettersusedonline+=strlen(#t(this.i))+1;
if (this.lettersusedonline>this.maxlinelength) {
setstring sign.readstring,#s(sign.readstring)" "#t(this.i);
this.lettersusedonline=0+strlen(#t(this.i));
}
else if (this.i==0) setstring sign.readstring,"#t(this.i);
else setstring sign.readstring,#s(sign.readstring) #t(this.i);
}
tokenize #s(sign.readstring);
setstring sign.pages,#v(int((tokenscount-1)/3));
say2 #t(strtofloat(#s(player.readingpage))*3)
#b#t(strtofloat(#s(player.readingpage))*3+1)
#b#t(strtofloat(#s(player.readingpage))*3+2);
}
if (playerendsreading) {
setstring player.readingpage,#v(strtofloat(#s(player.reading page))+1);
if (strtofloat(#s(player.readingpage))<=strtofloat(#s(sign.pages))) {
say2 #t(strtofloat(#s(player.readingpage))*3)
#b#t(strtofloat(#s(player.readingpage))*3+1)
#b#t(strtofloat(#s(player.readingpage))*3+2);
}
}And believe it or not that whole long string up there get's reworked into a sign without problems.

Solareon
06-24-2001, 08:03 PM
About how long does it take to parse the information?
as in the delay between the event and the sign

grim_squeaker_x
06-24-2001, 09:10 PM
Originally posted by Solareon
About how long does it take to parse the information?
as in the delay between the event and the sign Optimally it's instantaneous (sp?), but there might be up to one second's delay between display. All depends on CPU speed.

kyle0654
06-24-2001, 10:02 PM
nice. Though it could mess up with playerendsreading on some things. Optimally you'd build a sign from the ground up...but that takes some doing, and you'd have to use ascii codes (trust me, you can do it with a letter set string-array, but it'll give all caps since strequals isn't case sensitive) but nice job anyway