Are you basing this code off something else? You're repeating some earlier mistakes we've already pointed out, which leads me to think you don't fully understand what you're posting here.
Notably: You're still doing stuff where you declare & define a variable at the start (assumption: assigned to same value), and seem surprised that the position is the same throughout.
I'll be guessing a bit here, based on your description of what happens.
1. You're calling this function every update, with the same input every time (full text string you want to be printed sequentially, positionX and positionY). I'm assuming this because you say the behavior/output changes. Keep doing this. Note that I'm assuming this despite you not mentioning whether or not the sound plays correctly. I am guessing the sound plays repeatedly, far too frequently.
2. When you're testing this, you are starting the text drawing at startup. I'm assuming this based on guessing that al_get_time() returns seconds since the application was started, and because you say the text prints each individual letter from start to finish. This will hide a future problem, but I'll get to that.
3. px is supposed to be the current character's x position, while the int x parameter is the start x position.
Things that go wrong with your approach:
1. You only every print one character.
2. You play a sound every time you call the function.
3. You never advance the text cursor -- you always print in the same location. This is linked to only printing one character every time you call the function.
4. The timer you're using will only work immediately upon starting the game.
5. If left running, text[timeElapsed] will try to access garbage data (timeElapsed will surpass the number of characters in the text string).
Things you need to do:
1. Figure out how many characters to print. This involves being able to tell how much time has passed from when the text printing began. This also involves never trying to print more characters than are in the given text string.
2. Print the correct amount of characters, using the information above.
3. Figure out a way to tell if you should play a sound (this could be based on time, or based on more characters printed now than previous function call, or something else).
I'm slightly hesitant in terms of just posting a suggested solution (and honestly, somewhat tired again!). I'd suggest trying to solve the issues above on your own, and posting again if you run into problems, or if you've just got questions.
Hopefully that helps, both in accomplishing your goals and possibly increasing your programming abilities
Also, as a minor note to Satharis: int i is actually not redeclared/ghosted in the for loop. The for loop just uses the already declared i. As I mentioned in my first post, though, there is no reason to declare the variable before the loop in this case.
EDIT: I typed all of this up before your edit. Most of the issues I listed are still relevant.
Edited by Lactose!, 20 April 2014 - 06:06 PM.