Identifying char numbers in strings. [SOLVED]

Started by mode7, Thu 11/11/2010 15:29:04

Previous topic - Next topic

mode7

I want to play a different sound when a certain type-character is at a certain position in a string

First I tried this:

if (text.Chars[trunc] == I) {
   aI.PlayQueued();}

- which does not work

Then I tried this

if (text.Chars[trunc] == 78) {
   aI.PlayQueued();}

- which works BUT now I have to manually find out which char number corresponds to which letter. Is there an easier way to do this or at least a table somewhere, where I can identify char numbers?

Thanks in advance!

monkey0506

The simplest way for displayable characters is to use what is referred to as a character-literal. You had basically the right idea, but for AGS to understand that it's a character-literal and not, for example, a script variable or something, you have to enclose it in single quotes, i.e.:

Code: ags
if (text.Chars[trunc] == 'I') {
  aI.PlayQueued();
}


If the character is non-displayable (for example, the escape key) you can use the proper enumerated value:

Code: ags
if (text.Chars[trunc] == eKeyEscape) {
  aEscape.PlayQueued();
}

mode7

I knew I was very close to the solution ;) thanks man

monkey0506

Glad you got it sorted out. So are you turning the keyboard into some sort of keyboard? :=

mode7

No, wanted to play certain sounds depending on what text the player entered, of course your idea would be very possible - I wonder why there isn't such a thing yet.

SMF spam blocked by CleanTalk