Jump to content

Home

Conditional Script Help


Recommended Posts

Alright, so I've been using conditional scripts for a while now, but I've never actually had need for a conditional that checked for two globals to be certain values. Here's my attempt at making one:

 

int StartingConditional()
{
 int iResult = GetGlobalBoolean("DT_CHECK3");

 int iResult2 = GetGlobalBoolean("DT_CHECK4");

if(

   (iResult == TRUE) &&

   (iResult2 == FALSE) ) {

 return iResult && iResult2;  

}
}

 

Now I keep on getting an error saying that not all paths return a value. What should I change to fix this script?

Link to comment
Share on other sites

I don't think you can return more than one thing. This should manage what you require:

int StartingConditional()
{
 int iResult = GetGlobalBoolean("DT_CHECK3");

 int iResult2 = GetGlobalBoolean("DT_CHECK4");

if(

   (iResult == TRUE) &&

   (iResult2 == FALSE) ) {

 return TRUE;

}

else return FALSE; 

}

Link to comment
Share on other sites

Alright, I come here with a new conditional script woe today.

 

Basically, when doing Journal entries for a quest, a realized that if the PC were to do something in a certain order, a journal entry with a higher ID number would be added before a journal entry with a smaller ID number. Now, that means when the time came for the smaller ID'd journal entry to be given, it didn't fire. So, I created a duplicate of the smaller journal entry and gave it an ID higher than the entry that was causing problems. I then made this conditional script:

 

void main()
{

    object oPC=GetFirstPC();

object oPlaceable = GetObjectByTag("lockerlg001");

 int iResult = GetLocalBoolean(oPlaceable, 40);

if ( iResult == FALSE) {


 AddJournalQuestEntry("DT_MERC", 30);

if ( iResult == TRUE) {

 AddJournalQuestEntry("DT_MERC", 32);

}
}
}

 

Now everything works all fine and well if iResult == false. Yet, if iResult == True the higher journal entry doesn't get added. What am I doing wrong?

Link to comment
Share on other sites

Booleans in nwscript are kinda weird.

 

You'll have better results if you put:

 

void main(){

object oPC=GetFirstPC();
object oPlaceable = GetObjectByTag("lockerlg001");

if (GetLocalBoolean(oPlaceable, 40)) 
 		AddJournalQuestEntry("DT_MERC", 32);

else
 		AddJournalQuestEntry("DT_MERC", 30);
}

 

That said, if you still want to use your original script, you have to make sure that you close the brackets for the if statement. To better illustrate the issue:

 


[b][color="Lime"]YOUR CODE[/color][/b]
if ( iResult == FALSE) {


	AddJournalQuestEntry("DT_MERC", 30);

	if ( iResult == TRUE) {

		AddJournalQuestEntry("DT_MERC", 32);

	}
}


[b][color="Lime"]SHOULD BE[/color][/b]


if ( iResult == FALSE) {


	AddJournalQuestEntry("DT_MERC", 30);
}

if ( iResult == TRUE) {

	AddJournalQuestEntry("DT_MERC", 32);

}

Link to comment
Share on other sites

Also (atleast for KOTOR2 that is) putting ", TRUE" behind the journal entry number allows lower entries from overriding the higher entries. Which can be very handy in non-linear quest progressions.

 

Example (from Kotor2 though);

void main()
{
int nDxnOpen;
if(GetGlobalNumber("500OND_Civil_War") > 1) nDxnOpen = 1; else nDxnOpen = 0;
int nDanOpen;
if(GetGlobalNumber("602DAN_End") > 0) nDanOpen = 1; else nDanOpen = 0;
int nDxnEst = GetGlobalNumber("301NAR_Geeda_Dxn");
int nDanEst = GetGlobalNumber("301NAR_Geeda_Dan");

int nJournal = GetJournalEntry("NewTradeRoutes");

if (nJournal == 0) return;

if(nDxnEst == 1 && nDanEst == 1)
   {
       AddJournalQuestEntry("NewTradeRoutes", 33, TRUE);
       return;
   }
if(nDxnEst == 1)
   {
	if(nDanOpen == 0)
	{
		AddJournalQuestEntry("NewTradeRoutes", 13, TRUE);
		return;
	}
	if(nDanOpen == 1)
	{
		AddJournalQuestEntry("NewTradeRoutes", 21, TRUE);
		return;
	}
   }
if(nDanEst == 1)
   {
	if(nDxnOpen == 0)
	{
		AddJournalQuestEntry("NewTradeRoutes", 31, TRUE);
		return;
	}
	if(nDxnOpen == 1)
	{
		AddJournalQuestEntry("NewTradeRoutes", 12, TRUE);
		return;
	}
   }
if(nDanOpen == 1 && nDxnOpen ==1)
    {
       AddJournalQuestEntry("NewTradeRoutes", 22, TRUE);
       return;
    }
if(nDanOpen == 1)
    {
       AddJournalQuestEntry("NewTradeRoutes", 21, TRUE);
       return;
    }
if(nDxnOpen == 1)
    {
       AddJournalQuestEntry("NewTradeRoutes", 12, TRUE);
       return;
    }
AddJournalQuestEntry("NewTradeRoutes", 11);
}

Link to comment
Share on other sites

Oh sweet, thanks HH. It appears as though that should work in KotOR 1, judging by nwscript. I'll try it and report back.

 

 

EDIT: Alright, it works. Though, I found that since the dialogue option that assigns the entry is still available after you recieve the entry, you can advance the plot to a different journal entry and then come back, talk to the person, and then have the old entry assigned again. Here's how I set up my scripts to stop this from happening:

 

void main(){

object oPC=GetFirstPC();

       object oNPC = GetObjectByTag("50aa_comm");

 int iResult = GetLocalBoolean(oNPC, 40);

if ( iResult == FALSE) {

int bAllowOverrideHigher=TRUE;

 		AddJournalQuestEntry("DT_MERC", 30, bAllowOverrideHigher);

DelayCommand(0.1, ExecuteScript("dt_comm_flse", OBJECT_SELF));


}


return;

}

 

void main()
{

object oNPC = GetObjectByTag("50aa_comm");

   SetLocalBoolean(oNPC, 40, TRUE);

}

Link to comment
Share on other sites

Okay, so I've been trying to use this script:

 

void main()
{

    object oPC=GetFirstPC();

object oNPC = GetObjectByTag("d14ab_dcm"); 

 int iResult = GetLocalBoolean(oNPC, 21);

if ( iResult == FALSE) {

 AddJournalQuestEntry("DT_Q4", 25);


}

if ( iResult == TRUE) {

 		AddJournalQuestEntry("DT_Q4", 20);

  }
}

 

Yet for some reason when iResult is true, the journal entry isn't given. Now this is designed so that no matter what, whichever entry is going to be given it's already higher than the previous entry, thus no need for int bOverrideHigher. Now I tried using the type of script VP suggested on April 2nd, but then neither entry would be given. So, I decided to use the revised format that VP suggested, leading to my script above. Is there something I should change to make my script work?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...