Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Trouble With Strlen() (https://forums.graalonline.com/forums/showthread.php?t=45706)

wonderboysp2p 06-24-2003 04:14 AM

Trouble With Strlen()
 
im sorry i havent posted code in a while..
plz help meh X_x



if (created) {
timeout=0.05;
}
if (timeout) {
timeout=0.05;
setstring message2,This is NOT a Test;
showimg 2,@@b@#s(client.message2),screenwidth-strlen(message2)*8,screenheight-21;
changeimgvis 2,4;
}

I need it to be kinda like the little thing on GK that says you know "you avatar of govannon atmoizes Glok Lord"

Kaimetsu 06-24-2003 04:20 AM

1) Strlen takes a string, not the name of a string. Currently it's returning the length of 'message2'.
2) Use a this.string for temp stuff.

wonderboysp2p 06-24-2003 04:24 AM

what would i use to get the length of "this is NOT a test" then?

protagonist 06-24-2003 04:48 AM

Use a for loop. What you need to do is get the strlen of the string's value (this is NOT a test), not just the length of the string name.

wonderboysp2p 06-24-2003 04:54 AM

a for loop?

how would the script look then?

Kaimetsu 06-24-2003 05:01 AM

I don't know why protagonist is talking about loops. Anyway:

#s() converts string names into strings.

protagonist 06-24-2003 05:04 AM

Everybody always tells me to do for loops :(.


I would do something like for(i=0;i<strlen(#s(message2));i++) type thing.

Kaimetsu 06-24-2003 05:09 AM

Quote:

Originally posted by protagonist
I would do something like for(i=0;i<strlen(#s(message2));i++) type thing.
...for what purpose?

wonderboysp2p 06-24-2003 05:11 AM

X_x

strlen(#s(client.message2))

would be the length of "this is NOT a test" then?

Admins 06-24-2003 05:21 AM

strlen(#s(message2))

wonderboysp2p 06-24-2003 05:24 AM

woo! alright i got it working now... i feel good now that stefan posted in my thread thanks for the help guys

protagonist 06-24-2003 05:25 AM

Quote:

Originally posted by Kaimetsu


...for what purpose?


Ugh, sorry, that would just give i the the value of the length of message2.

Quote:

Originally posted by Stefan
strlen(#s(message2))
Whoa, you are awake late.:megaeek:

wonderboysp2p 06-24-2003 05:32 AM

Quote:

Originally posted by protagonist

Whoa, you are awake late.:megaeek:

yea stefan's crazy like that...



now i gotta figure out the right number to multiply it by.. X_x

and i think capital letters will screw that up
Edit : Yep... having lower case letters numbers and capital letters changes everything... now im gonna have to check the string for caps, numbers, and lowercase letters X_x

Tseng 06-29-2003 08:02 AM

Quote:

Originally posted by protagonist
Everybody always tells me to do for loops :(.


I would do something like for(i=0;i<strlen(#s(message2));i++) type thing.

Uh. Do you even know what you're talking about?

Do you even know what the guy's trying to do?

He's trying to use strlen to return a value.

Using a for loop does not help him learn to use strlen.

And the fact that everyone else tells you to do for loops has absolutely nothing to do with this situation. Sorry, just had to complain about that.

Anyway, as for your problem wonderboy, align your showimg text to the right instead of the left perhaps? Then you need not worry about strlen at all, really.

wonderboysp2p 06-29-2003 09:38 AM

omg i can just Align it?????

protagonist 06-29-2003 03:18 PM

Quote:

Originally posted by Tseng


Uh. Do you even know what you're talking about?

Do you even know what the guy's trying to do?

He's trying to use strlen to return a value.

Using a for loop does not help him learn to use strlen.

And the fact that everyone else tells you to do for loops has absolutely nothing to do with this situation. Sorry, just had to complain about that.


Well, that was mean, I already admitted my mistake.
I was thinking about sarraylen, not strlen.

Tseng 06-29-2003 05:36 PM

Quote:

Originally posted by wonderboysp2p
omg i can just Align it?????
To the very best of my knowledge, yes. It requires putting a letter in between the @ signs of the showimg, and I believe is explained in one of the newfeatures.txts (though I may be wrong about it being in there- it's been a while since I looked for image-showing clarifications). As it happens, I haven't had an occasion to align something to the right, so I do not know the letter off the top of my head (although, the logical guess is r). If you can't find it, I'll have access to my other computer in a couple of hours, and can find it then.

Quote:

Originally posted by protagonist



Well, that was mean, I already admitted my mistake.
I was thinking about sarraylen, not strlen.

Perhaps it was mean, but he was trying to learn, and you were giving him incorrect information. Naturally, I will be very critical of cases like that, because when people are trying to learn, receive incorrect information, and it is not corrected, they not only learn wrong, but in some cases their own ignorance will prevent them from ever learning their way is wrong. I dealt with a case like this recently, in which a scripter not only refused to acknowledge something stefan had explained about triggeractions, but deleted a script of several hours work, as well as a few weeks' worth of that script's running and logging. :\

protagonist 06-29-2003 07:09 PM

Yes, I didn't have the right command. But Kaimetsu pointed it out already, and I made it clear I was mistaken.

KainM0rbid 06-29-2003 09:22 PM

If you look in newfeatures2003.txt you will notice there is a nice new handy variable added called textwidth :)
so instead of using strlen() I would suggest using textwidth
NPC Code:

textwidth(size,font,style,text)


Makes things easier and more accurate than guessing a formula to get the width of your text

---Kain Morbid

wonderboysp2p 06-30-2003 12:54 AM

:confused: umm... i dont think anyone has really helped solved my problem...

osrs 06-30-2003 01:10 AM

Quote:

Originally posted by wonderboysp2p
:confused: umm... i dont think anyone has really helped solved my problem...
Ask Tseng,he is the best scripter of the world. ^_^

KainM0rbid 06-30-2003 03:12 AM

NPC Code:

if (created) {
timeout=.05;
}
if (timeout) {
timeout=.05;
setstring message2,This is NOT a Test;
showimg 2,@@b@#s(client.message2),screenwidth-strlen(#s(message2))*8,screenheight-21;
changeimgvis 2,4;
}


I have bolded what you forgot in your script.
though I do suggest using text width instead of strlen()*8 seeing as how textwidth is MUCH more accurate.

---Kain Morbid

wonderboysp2p 06-30-2003 05:43 AM

yea kain i had gotten that part figured out but it turns out that *8 only works when each letter in message2 is lower case... numbers and CAPS screw up the placement.. which is why i want to know what tseng was talking about when he said i can probably align things to the right

Kaimetsu 06-30-2003 06:32 AM

It doesn't work at all when the font is not monospaced. Anyway:

Firstly, use showtext instead of showimg. Secondly, use an 'r' in the style argument. If you don't understand, read newfeatures.txt.

wonderboysp2p 06-30-2003 07:15 AM

alright thanks kai
i used showimg because im just more used to showimg @@@ but yea ok show text and r in style arguement all so simple ^_^

Projectshifter 07-06-2003 09:13 PM

lol, showtext, I can't stand that!
sarraylen() needs a for loop why? Sarraylen you don't need #s for, and it checks the amount of arrays in it rather than it's length x-x
---Shifter

Kaimetsu 07-07-2003 03:37 AM

Quote:

Originally posted by Projectshifter
lol, showtext, I can't stand that!
¬_¬

wonderboysp2p 07-07-2003 09:14 AM

cmon kai you cant deny that after using showimg @@@ for a while, it's hard to switch over to a new command

Kaimetsu 07-07-2003 09:27 AM

Quote:

Originally posted by wonderboysp2p
cmon kai you cant deny that after using showimg @@@ for a while, it's hard to switch over to a new command
Uh, no it isn't. I never used showimg to display text after showtext was released.


All times are GMT +2. The time now is 11:09 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.