LucasForums

LucasForums (http://www.lucasforums.com/index.php)
-   Holowan Laboratories (http://www.lucasforums.com/forumdisplay.php?f=324)
-   -   Conditional Script Help (http://www.lucasforums.com/showthread.php?t=209889)

Fallen Guardian 04-01-2012 05:48 PM

Conditional Script Help
 
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:

Code:

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?

JCarter426 04-01-2012 05:55 PM

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

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

  int iResult2 = GetGlobalBoolean("DT_CHECK4");

if(

    (iResult == TRUE) &&

    (iResult2 == FALSE) ) {

  return TRUE;

}

else return FALSE;
 
}


Fallen Guardian 04-01-2012 06:42 PM

Alright, thanks JC.

Fallen Guardian 04-02-2012 11:30 PM

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:

Code:

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?

VarsityPuppet 04-03-2012 12:30 AM

Booleans in nwscript are kinda weird.

You'll have better results if you put:

Code:

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:

Code:


YOUR CODE
        if ( iResult == FALSE) {


                AddJournalQuestEntry("DT_MERC", 30);
         
                if ( iResult == TRUE) {

                        AddJournalQuestEntry("DT_MERC", 32);
 
                }
        }

       
SHOULD BE


        if ( iResult == FALSE) {


                AddJournalQuestEntry("DT_MERC", 30);
        }
         
        if ( iResult == TRUE) {

                AddJournalQuestEntry("DT_MERC", 32);
 
        }


Fallen Guardian 04-03-2012 01:33 AM

Thanks VP.

Hassat Hunter 04-03-2012 04:27 AM

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);
Code:

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);
}


Fallen Guardian 04-03-2012 04:54 AM

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:

Code:

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;
 
}

Code:

void main()
{

object oNPC = GetObjectByTag("50aa_comm");

    SetLocalBoolean(oNPC, 40, TRUE);

}


Hassat Hunter 04-03-2012 06:14 AM

Pretty sure you can do that in 1 script... (just add the SetLocalBoolean immediately after the journal entry.

Fallen Guardian 04-03-2012 12:51 PM

Yeah, but I'd already set up a similar situation like this and I'm too lazy to recompile it.

Fallen Guardian 04-05-2012 03:35 PM

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

Code:

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?


All times are GMT -4. The time now is 04:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
LFNetwork, LLC ©2002-2011 - All rights reserved.