I recently came upon two issues that I thought were simple but ended up being (oh hey larry vales smiley... lol... sorry... get distracted easily)...Ã, anyway, it ended up being a wee bit harder than I expected. So, to make a long story short, here's the problem I found out in the end:
How do I convert strings to characters?... in AGS, that is, because I know how to anywhere else, lol
AND
How do make the speech text ALWAYS appear in front? It doesn't appear in front when there is a GUI blocking it.
BTW, the reason I wanted to convert characters to strings is so I could capitalize the first letter of any string. Why? Well, because I feel is important knowledge (plus it'll clean up my game a bit)...
Any input would be really cool.... thanks!
Quote from: Risk on Sun 12/12/2004 10:31:59
How do I convert strings to characters?... in AGS, that is, because I know how to anywhere else, lol
StrGetCharAt, StrSetCharAt.
Don't know about the text and GUI.
Speech can't appear in front of GUIs, but this is on my to-do list. However, it should be automatically moved around the screen such that it's not hidden behind a GUI.
Capitalize the 1st letter? Funny you should mention that, I did it very recently for my LSL7 template. Here's what I did:
StrToLowerCase(verb);
int getcharacter=StrGetCharAt(verb, 0);
string capital;
StrFormat(capital, "%c", getcharacter);
StrToUpperCase(capital);
if (StrComp(capital, "A")==0) StrSetCharAt(verb, 0, 'A');
if (StrComp(capital, "B")==0) StrSetCharAt(verb, 0, 'B');
if (StrComp(capital, "C")==0) StrSetCharAt(verb, 0, 'C');
if (StrComp(capital, "D")==0) StrSetCharAt(verb, 0, 'D');
if (StrComp(capital, "E")==0) StrSetCharAt(verb, 0, 'E');
if (StrComp(capital, "F")==0) StrSetCharAt(verb, 0, 'F');
if (StrComp(capital, "G")==0) StrSetCharAt(verb, 0, 'G');
if (StrComp(capital, "H")==0) StrSetCharAt(verb, 0, 'H');
if (StrComp(capital, "I")==0) StrSetCharAt(verb, 0, 'I');
if (StrComp(capital, "J")==0) StrSetCharAt(verb, 0, 'J');
if (StrComp(capital, "K")==0) StrSetCharAt(verb, 0, 'K');
if (StrComp(capital, "L")==0) StrSetCharAt(verb, 0, 'L');
if (StrComp(capital, "M")==0) StrSetCharAt(verb, 0, 'M');
if (StrComp(capital, "N")==0) StrSetCharAt(verb, 0, 'N');
if (StrComp(capital, "O")==0) StrSetCharAt(verb, 0, 'O');
if (StrComp(capital, "P")==0) StrSetCharAt(verb, 0, 'P');
if (StrComp(capital, "Q")==0) StrSetCharAt(verb, 0, 'Q');
if (StrComp(capital, "R")==0) StrSetCharAt(verb, 0, 'R');
if (StrComp(capital, "S")==0) StrSetCharAt(verb, 0, 'S');
if (StrComp(capital, "T")==0) StrSetCharAt(verb, 0, 'T');
if (StrComp(capital, "U")==0) StrSetCharAt(verb, 0, 'U');
if (StrComp(capital, "V")==0) StrSetCharAt(verb, 0, 'V');
if (StrComp(capital, "W")==0) StrSetCharAt(verb, 0, 'W');
if (StrComp(capital, "X")==0) StrSetCharAt(verb, 0, 'X');
if (StrComp(capital, "Y")==0) StrSetCharAt(verb, 0, 'Y');
if (StrComp(capital, "Z")==0) StrSetCharAt(verb, 0, 'Z');
StrCopy(actionaction,verb);
This is probably too complicated, I'm sure there's a better and simpler way, but it worked for me and I'm sticking to it!
Oh for crying out loud... :)
int ch1 = StrGetCharAt (verb, 0);
if (ch1 >= 'a' && ch1 <= 'z') StrSetCharAt (verb, 0, ch1 + 'A' - 'a');
ARGH! Why don't I start using my head!
...I think I just found out why my templates will never be popular, though they work well. :P
EDIT - BTW, these two things should be doccumented somewhere. 'a', 'A' and %c? They aren't documented at all - at all. Maybe if I'd known more about them, I wouldn't have made this mistake...
...
...nah, I'd have made it anyway. But i'd be nice to know exactly what these are all about.
It's the way chars work in C. It's one of those things that I feel that if it's documented it'll end up confusing more people than it helps, but maybe it should be.
Anyway, basically you can use an ascii character inside single quotes, which represents the ASCII value of that character.
So, doing this in the script:
'A'
actually evaluates to 65.
Because the letters all go sequentially though, you can use the difference between 'a' and 'A' (in this case the line
'A' - 'a'
which compiles down to:
65 - 97
which is -32)
to modify the case of a character. The result of which is basically adding 32 to an upper case character will make it lower case, and subtracting 32 from a lower case character will make it upper case.
However, perhaps some script functions like CharToUpper would be more friendly ;)
Heh, yes it would!
Anyway, what IS %c? I don't even know if it's a string or an int. I just blundered with it (because I'd seen it in the SQ3 template) in hopes of getting things to work, which it did.
And BTW - then I can do (if keycode == 'A'), right? Not that it serves any practical purpose... :P
%c is the code for this formatted I/O for 'single char'
or did you mean something else.
and I suppose 'A' would work, and it could make the code more readable, so just checking over the code, one wouldn't have to go back to a ascii chart, but I use their corresponding numbers; thats what im used to.
I mean, what does it return? How does it work? String is a variable of alphanumeric symbols, char/short/int are variables of numbers with different lengths... what about %c?
%c returns the character whose ASCII code is given by the argument, e.g. Display ("%c", 65) would yield a capital A. Values less than 32 or greater than 127 are likely to cause your game to crash.
Keypress does work with those codes. Note that you should use capitals (pressing the A key yields 'A', regardless of whether you hold shift).
Oh and btw in C I would have typed "ch1 - 'a' + 'A'" only that doesn't work in AGS :)
Yes -- in fact, in your on_key_press I would recommend using things like
if (keycode == 'A') { }
rather than
if (keycode == 65) { }
because it makes the script a lot easier to read. As Radiant says though, make sure you use capital letters in those checks.
Hm, if you're doing a bunch of defined constants anyway - maybe you could add something like KEY_F1 (=359 I believe) for use with the key_press functions?
Ah, I see. Thanks a lot, Radiant!