Author Topic: Inserting variables into dialogue  (Read 265 times)

Legacy_dndfreak

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inserting variables into dialogue
« on: July 09, 2012, 11:08:57 am »


                I've been searching for an answer for hours now and can't think of any way to do this.

Essentially, I have a map for a tower defense style survival game in which orcs spawn from the map corners and follow pathing to an immobile dragon with no AC or STR in the center (it also has a level of undead to block heals and the orcs have true seeing).

Upon death, the orcs add 1 to a variable called iKillCount, which I want to then convert into a string and have either a sign or the dragon itself display constantly overhead as popup text. While I know how to convert it (I think), I have no idea how to insert the variable into text. I know there's got to be a way but can't for the life of me figure it out. Help would be much appreciated.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #1 on: July 09, 2012, 12:02:27 pm »


               Variables are added to Dialog, and Journal entries via Custom Tokens.


void SetCustomToken(
int nCustomTokenNumber,
string sTokenValue
);

Eg



void SetCustomToken(10005, "James");


Then, in a conversation, if I were to say

I want you to kill <CUSTOM10005> for me, he can be found at the docks!


It would produce

I wan you to kill James for me, he can be found at the docks!


You can get some advanced dialog systems working, with a little practice.
Make use of the Copy and Paste Link feature of the dialog editor, as well as having the Custom Tokens getting updated on the 'Happens When' event/side of the conversation of the node that you are pasting a link to.

eg- You can make an infinite loop in the conversation system, where the Custom Tokens get updated each time you refresh.
Gives the illusion of scrolling to a next page of data.



If this is just a matter of you want popup text, then you might not need to deal with custom tokens at all.


int iNumber = GetLocalInt(GetModule(),"my_Storednum");
string sConvertedNumber = IntToString(iNumber);
FloatingTextStringOnCreature(sConvertedNumber,oCreatureToFloatAbove,TRUE);
or
SpeakString(sConvertedText);
               
               

               


                     Modifié par Baaleos, 09 juillet 2012 - 11:05 .
                     
                  


            

Legacy_dndfreak

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #2 on: July 09, 2012, 12:48:20 pm »


               Thanks a ton! Honestly didn't expect that fast a reply, this forum seems to be pretty dead even for a decade old game.

So... if I were to add this to the heartbeat trigger

int iKillDisplay = GetLocalInt(oKillCountSign,iKillCount);
string sKillCount = IntToString (iKillDisplay);
SpeakString(sKillCount);

it would work?

Also having an issue right now trying to get my code on the creeps to work correctly.

I have

43    int iKillOrc = GetLocalInt (oKillCountSign,iKillCount);
44    iKillOrc = (iKillOrc+1);
45    SetLocalInt (oKillCountSign,iKillCount,iKillOrc);

But the compiler returns Error. 'killcountplus' did not compile.
killcountplus.nss(43): ERROR: VARIABLE DEFINED WITHOUT TYPE
               
               

               


                     Modifié par dndfreak, 09 juillet 2012 - 11:52 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #3 on: July 09, 2012, 01:05:11 pm »


               There are a few issues here.

1. You need to determine what object you are using to store your variable on.

      if you want to store this on the orc, then you would need to get an object variable that points to the orc.
If this is a heartbeat script, for the orc, and not the module, then you can use


object oOrc = OBJECT_SELF;
then to get the last stored variable
int iKillDisplay = GetLocalInt(oOrc,"KillCount"); // Note - the variable name must be in quotes to identify it as a string, unless it is a string variable you are passing in. eg a consts.
string sVal = IntToString(iKillDisplay);// Converts the int to a string for being verbally spoken.
SpeakString(sVal); // Speak the number


For storing the variable, / or incrementing it.
int iKillDisplay = GetLocalInt(oOrc,"KillCount");
//to increment it, we just need to call
iKillDisplay++;  (this tells it to add one)
SetLocalInt(oOrc,"KillCount",iKillDisplay);

The reason it was throwing compiler issues for you, was likely because something on line 43 wasnt defined or declared.

eg
You have declared and defined iKillOrc
But... Have you defined oKillCountSign, or iKillCount?

eg
object oKillCountSign = SOMETHING?
int iKillCount =   Something?
               
               

               
            

Legacy_dndfreak

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #4 on: July 09, 2012, 05:17:52 pm »


               oKillCountSign is the object that will shout the kill count. iKillCount is the variable, stored on oKillCountSign.

You are correct, the other variables were not being defined. Didn't think you needed to given the context, but now I know. Was unaware that NWNScript is so narrow-minded that you have to declare objects as themselves before a given segment of code will see them.

What I need to do is use the death of one object to add to the variable of a completely different object. I have the code fully compiled but right now the integer isn't being added to correctly and I'm not quite sure where the problem is.

The way I have it set up is that
oKillCountSign is the object which displays the total number of orcs slain.
iKillCount is the integer stored as a local variable on oKillCountSign
iKillCountTwo is a temporary integer created during each individual orc's death script which loads the old value of iKillCount, increases it by one, then replaces the original value of iKillCount.
sKillCount is the string to be shouted, a conversion of iKillCount.

The script added to the normal orc death trigger:

   object oKillCountSign = oKillCountSign;
   int iKillCountTwo = GetLocalInt(oKillCountSign,"iKillCount");
   iKillCountTwo++;
   SetLocalInt (oKillCountSign,"iKillCount",iKillCountTwo);

And this is the script for the heartbeat trigger of oKillCountSign:

void main()
{
    string sKillCount = IntToString(GetLocalInt(OBJECT_SELF,"iKillCount"));
    SpeakString(sKillCount);
}

What is currently happening is that the sign shouts '0' every six seconds, meaning that somewhere along the line the local integer iKillCount is not being manipulated properly. Is it not possible for one object to permanently manipulate the variable of another object?
               
               

               


                     Modifié par dndfreak, 09 juillet 2012 - 04:49 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #5 on: July 09, 2012, 06:00:26 pm »


               

object oKillCountSign = oKillCountSign;

lokely needs to be:
object oKillCountSign = GetObjectByTag ("SIGN_TAG_HERE");
               
               

               
            

Legacy_dndfreak

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Inserting variables into dialogue
« Reply #6 on: July 09, 2012, 06:36:57 pm »


               And that's the last missing piece. Script works like a charm. With this I'll be able to keep track not just for the sake of informing the players but also when I get around to it, I'll be able to increase the difficulty of new mobs as more and more waves go by. Huge thanks to both of you.