getSpeakString function


Questions, Explanations, Howtos

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 24th June 2013, 00:28

getSpeakString function

I'm trying to use the getSpeakString function, but I'm not sure what include statements are required. I tried #include "database.h" and while it does compile, all I get is blank space where the message should be. Please help.
EDIT:
Just realized posting my code would be helpfull. Here's the code that calls the function:
Spoiler: show
  Code:
      switch(you.experience_level) {
          case 3:
                mpr(getSpeakString("lev3"), MSGCH_INTRINSIC_GAIN);
               mummyskills();
                break;
            case 6:
                mpr(getSpeakString("lev6"), MSGCH_INTRINSIC_GAIN);
                mummyskills();
                break;
            case 9:
                mpr(getSpeakString("lev9"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 12:
                mpr(getSpeakString("lev12"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 15:
                mpr(getSpeakString("lev15"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 18:
                mpr(getSpeakString("lev18"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 21:
                mpr(getSpeakString("lev21"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 24:
                mpr(getSpeakString("lev24"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            case 27:
                mpr(getSpeakString("lev27"), MSGCH_INTRINSIC_GAIN);
            mummyskills();
                break;
            default:
                break;
}

And here's the text itself:
Spoiler: show
  Code:
#########################
#The text for when a mummy regains memories.
#########################
%%%%
lev3

This @_dungeon_@ is no longer all you know.

You begin to remember a time before this @_dungeon_@.

Although much has been lost to the [sands|mists|river] of [time|the past] you still see glimpses of a [fleeting|distant|long gone|long forgotten] past.
%%%%
lev6

You [begin to remember|recall] more of your [hidden past|history|life|unlife], regaining skills once [forgotten|thought lost|gone from this earth].

Allthough long gone from the world of [the living|men|elves|the surface|mortals], [unholy|forbidden|dark] [powers|secrets] live on in your mind.
%%%%
lev9

Through flashes and short glimpses, you now know secrets lost to the [ages|surface|world of men].
%%%%
lev12

You are utterly [shocked|horrified|amazed] by how much you [forgot|lost] over the years. Who were you? What did you know?

Who were you? A [king|lord|emperor]? You remember [little|few details|almost nothing], but occasionally [glimpse|see] a [crown|castle|throne].
%%%%
lev15

A raw stream of [memories|history] [floods over|washes over|engulphs] you. You would cry, if you still had functioning tear ducts.
%%%%
lev18

Much that once was is [found|regained|again], for one now [lives|unlives] to [remember|recall] it.

You once [ruled|lead] a [country|empire|kingdom|relm|continent|religion]. [Foes|Enemies|Trators|Rebels|Mortals|Rivals|Kings|The jeweled thrones of the world] were [crushed|squashed] beneath your feet. Just what happened to you between then and now?
%%%%
lev21

Your memories have largely [returned|been restored|been regained], allthough there are still [gaps|missing pages]. Once more, you [ask the question|wonder]: 'Who [am|was] I?'

How could you have forgotten? The [knife|sword|blade|dagger] from your [daughter|advisor|vizier|husband|wife|son|consort]. You trusted [others|people|humans|the world] once. [Never again|No more].
%%%%
lev24

The [gaps|holes|blanks] are starting to [close|shrink]. You wish you [appreciated|understood] all you had in your [past|mortal|previous] life, before you were cast down into this @_dungeon_@.
%%%%
lev27

The ghosts of [amnesia|the past] are no match for your [vast|immense] [intellect|power]. You know who you are. More importantly, you know who you were.

The Orb. You know what it [is|was|could become]. With its [power|might|magic], you could become [all powerful|almighty|omniscient|omnipotent|like unto a god]. Once again, the [world|relm] shall [shake|quake|tremble] at the mention of your name.
%%%%
_dungeon_

dungeon

pit

prison

complex

madhouse

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Monday, 24th June 2013, 00:44

Re: getSpeakString function

Use:

  Code:
        mprf(MSGCH_INTRINSIC_GAIN, "%s", getSpeakString("foo").c_str());

For this message the author mumra has received thanks:
khalil

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Monday, 24th June 2013, 00:50

Re: getSpeakString function

Actually, there's maybe a problem with what I just posted. That method is used only once in the code, everywhere else you'll see:
  Code:
string foo = getSpeakString("bar");
mprf(MSGCH_INTRINSIC_GAIN, "%s", foo.c_str());


Someone with slightly more C++ knowledge than me would have to comment on which forms are correct and why.

For this message the author mumra has received thanks:
khalil

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Monday, 24th June 2013, 00:58

Re: getSpeakString function

After some consultation, the first version I posted is actually fine, although the second version is sometimes better for cleaner code.

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 24th June 2013, 01:02

Re: getSpeakString function

Not sure why, but they both seem to result in the message showing up as black. There's a space where the text should be, but it's empty.

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Monday, 24th June 2013, 01:18

Re: getSpeakString function

So the next thing to consider is that your text lines aren't getting loaded into the string database.

Did you add these to a new file? Text file names are hard-coded. Put it in an existing one or add your text file name in database.cc.

For this message the author mumra has received thanks:
khalil

Tomb Titivator

Posts: 799

Joined: Saturday, 23rd February 2013, 22:25

Post Monday, 24th June 2013, 10:50

Re: getSpeakString function

Yeah, I put them in a new file. didn't think they fit in any of the others. I'll try that.
EDIT:
Thanks, it works!

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Monday, 24th June 2013, 13:04

Re: getSpeakString function

I've added a misctext.txt database file in something I'm working on for exactly this kind of purpose where text doesn't really fit anywhere, but I haven't merged that to trunk yet.

Return to Coding

Who is online

Users browsing this forum: No registered users and 3 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.