Two issues...

Started by Risk, Sun 12/12/2004 10:31:59

Previous topic - Next topic

Risk

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!

jetxl

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.

Pumaman

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.

Rui 'Trovatore' Pires

Capitalize the 1st letter? Funny you should mention that, I did it very recently for my LSL7 template. Here's what I did:

Code: ags

        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!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Radiant

Oh for crying out loud... :)

Code: ags

int ch1 = StrGetCharAt (verb, 0);
if (ch1 >= 'a' && ch1 <= 'z') StrSetCharAt (verb, 0, ch1 + 'A' - 'a');


Rui 'Trovatore' Pires

#5
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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

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 ;)

Rui 'Trovatore' Pires

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
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Scummbuddy

%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.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Rui 'Trovatore' Pires

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?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Radiant

%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 :)


Pumaman

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.

Radiant

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?

Rui 'Trovatore' Pires

Ah, I see. Thanks a lot, Radiant!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk