Author Topic: Items in Inventory Starting Conditional.  (Read 350 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« on: April 13, 2014, 03:31:29 pm »


               

Here's a stupid question. When you enter multiple tags in the conversation Start. Cond. wizard. It checks to see if the PC has all of those items. Correct ? I have made several attempts to come up with a script that will return TRUE if the PC has any of those Items. My latest copiled and worked in testing. I thought I had it. I continued on with the convo. When I went to test for something else it failed. I just don't understand the meaning of the return TRUE; return FALSE: thing. Could somebody please pound this into my thick head ?


Ed


int StartingConditional()

{

 object oPC = GetPCSpeaker();

 object oBars = GetItemPossessedBy(oPC,"RoyalGoldBars");

 object oCups = GetItemPossessedBy(oPC,"PugilistTrophies");


 if(GetIsObjectValid(oBars))

 return TRUE;



  if(GetIsObjectValid(oCups))

  return TRUE;

  return FALSE;

}



               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« Reply #1 on: April 13, 2014, 03:46:45 pm »


               

return FALSE stops the code from continuing.


 


for example


 


print Hello World


return FALSE;


print Hello World2


 


Hello World2 would never be printed. 


 


You can do double checks using the & like this. Often helps make the code look a little cleaner.


 

if (GetItemPossessedBy(oPC, "bars1")!= OBJECT_INVALID & GetItemPossessedBy(oPC, "bars2")!= OBJECT_INVALID)

   {

    //Looks like they have some bars

   }

 

Hope this helps a little. Good luck.


               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« Reply #2 on: April 13, 2014, 03:55:38 pm »


               

Ha!, I've been suckered. Looks like I don't know for sure about return TRUE, return False. 


 


return as I know it only returns a true. so it would read something closer to this. It's necessary (very handy) for embedded if statements, switches etc. 


print Hello World


return;


print Hello World2



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« Reply #3 on: April 13, 2014, 04:21:22 pm »


               

... I just don't understand the meaning of the return TRUE; return FALSE: thing. Could somebody please pound this into my thick head ?
Ed



int StartingConditional()

Above is a declaration for a function named StartingCondition that will return an integer value. The integer value that the label (StartingConditional) will be equal to, AT any given time, will be the value returned by the code that it runs.

Lets look at the rest of the code in this manner.

{
object oPC = GetPCSpeaker();

above an object labeled oPC is being defined. To it is being assigned the object that is being returned by the code block that is labeled GetPCSpeaker.

object oBars = GetItemPossessedBy(oPC,"RoyalGoldBars");

An object named oBars is being defined and given a value of the object being returned by the GetItemPossessedBy code block.
object oCups = GetItemPossessedBy(oPC,"PugilistTrophies");

An object named oCups is defined to be equal to the value returned by the GetItemPossessedBy function.


if(GetIsObjectValid(oBars))
return TRUE;

if the integer returned by the GetIsObjectValid function is true. Return TRUE as the value of StartingConditional. This will also stop the rest of the script from running.


if(GetIsObjectValid(oCups))
return TRUE;

Again we are doing the same thing as above. if the integer returned by the GetIsObjectValid is true. TRUE is returned as the value for StartingConditional and code execution is returned to the calling code.



return FALSE;

none of the code above this statment has returned given a value to StartingConditional therefore a value of FALSE will be given to it.
}

I hope that helps. FALSE is a compiler constant defined as 0
TRUE is a compiler constant defined as 1
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« Reply #4 on: April 13, 2014, 08:17:31 pm »


               

You can do double checks using the & like this. Often helps make the code look a little cleaner.

 

if (GetItemPossessedBy(oPC, "bars1")!= OBJECT_INVALID & GetItemPossessedBy(oPC, "bars2")!= OBJECT_INVALID)

   {

    //Looks like they have some bars

   }



 


You should use the logical operator && for checking two conditions. & is a bitwise operator. In this case, they will not yield different results, but you should get used to using the correct one because it can cause issues in other contexts.


Actually, to replicate the functionality of Ed's initial script, you wanna use the logical OR (||) operator, as this will allow you to return TRUE if either one is found:



int StartingConditional()
{
    object oPC   = GetPCSpeaker();
    object oBars = GetItemPossessedBy(oPC, "RoyalGoldBars");
    object oCups = GetItemPossessedBy(oPC, "PugilistTrophies");
   
    return (GetIsObjectValid(oBars) || GetIsObjectValid(oCups));
}

Lastly, since I don't see that anyone else has mentioned it... in the case of a StartingConditional(), the return value of the script determines whether the node's text displays to the PC. If it returns TRUE, the NPC will speak that node (or, if this is a PC node, the PC will be shown that line as a possible response). Otherwise, it will fall through to the next line. If no lines return TRUE, the conversation finishes.



               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Items in Inventory Starting Conditional.
« Reply #5 on: April 14, 2014, 02:51:56 am »


               Buddywarrior,
So, as I read your post says that the return FALSE, is basicly the same as the break; statement.
This confused me. I have taken script wizard checks for an item and reversed the return statements to get a convo node to appear when a PC does not have an item.
//::///////////////////////////////////////////////
//:: FileName sc_has_sols_ring
//:://////////////////////////////////////////////
//:://////////////////////////////////////////////
//:: Created By: Script Wizard
//:: Created On: 12/6/2013 9:27:33 PM
//:://////////////////////////////////////////////
#include "nw_i0_tool"

int StartingConditional()
{

// Make sure the PC speaker has these items in their inventory
if(!HasItem(GetPCSpeaker(), "SolomandsMothersRing"))
return FALSE;//Was TRUE
return TRUE;//Was FALSE
}
In testing this has always worked. Text appeared when the PC did not have the item, and did not appear when he did.


Lightfoot8,
Right through the mass of hair and age hardened bone, to the brain. Thank you ! I have gotten good at the if else statements. I always try to read a script like a sentence. If this condition is met, do this. If not, do that. Makes sense to me. The Starting Conditional just never made sense to me. I knew when I said it, the guy pointed me to the bathroom. I had no idea what I just said, but it worked. Thank you for the translation. I now have a better idea of what I am saying.


Squatting Monk,
I did not copy and paste, and I have to admit it took me awhile to find the || key on the keyboard. I know that's sad, but I grew up in a house with one rotary phone with 3 feet of cord. I sometimes pine for the days when all I needed was my pencils,paper,dice, and about 40 pounds of books and notes. Thanks. the script works like a charm, and has taught me another lesson in building.

I wish to express my gratitude to all of you. Your help is always greatly appreciated.
Ed