Okay. This is a thread started by and directed towards those who are familiar with the concept of C++, and can potentially read it without too many problems, but when it comes to actually writing a script, hope flies out the window. It's like being able to read English but not being able to write it due to the myriad of minutia-related questions which seem to constantly pop up. As ridiculous as that situation seems, (Can READ English but not WRITE it? WTF!? .. etc.) it's a real issue. Some people can understand the basic premise/s of C++, but no amount of example following and personal try-outs seem to solve this delicate issue.


One particular issue at hand is, what is the difference between Pseudocode and actual code in the way it's written? For example, what is the difference in syntax and layout to go from the following: (This example is not necessarily in ZC Terms.)

Code:
if { the_number_of_goblins in treewood_forest_screen001 == 0 
then
execute script 4052 and tell wooden_signpost_052 to change variable 05 to state "1" }
Or,

Code:
get object PC
If object PC has less than 10% Health
then {
play SFX_beep once every three seconds }
Note my fairly obvious misuse of Brackets. ( { } I hope these are brackets; I'm not sure if I've named them incorrectly. You don't need to know their names to type them, apparently. :p ) I wouldn't know where to place them relative to the script. Do they group commands? Do they group subsets of code? Do they separate one process from another? Again, if I saw it in an example, I'd know what it does, but clearly, I'm not 100% sure in the examples above if I'd even need them at all, and when to use them if I do. (But I wouldn't be sure if I needed them, so...)





@}---------------------------------------------{@




Here's a sample of the closest script I have available to me. It's from Neverwinter Nights.

Code:
void main( )
{
  object oPC = GetEnteringObject( );
  if(GetIsPC(oPC) &&
    GetMaxHitPoints(oPC) == GetCurrentHitPoints(oPC))
  {
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(1),oPC);
  }
}
Here's the bit of text they described it with:

By now, you should be able to recognize the basic structure of the script (the void main and the curly braces). However, the code inside introduces a few concepts not discussed, yet. So don't feel stupid if you couldn't figure it out.
Here's what's going on. FIrst, the script gets the object currently entering the area (using GetEnteringObject( )). The object is then checked to see if it is the PC (using GetIsPC(oPC)) and if the current HP of the object (still undermined but possibly the PC) are equal to the maximum HP of the object. If the object is a PC object, and the maximum HP is equal to the current HP, then the object is given a free point of damage (using ApplyEffectToObject( ) and EffectDamage( ))! Sounds like a nice little area to stay away from, doesn't it?
The StartingConditional type is commonly used in NPC conversations to setup conditions for the start of a conversation (as the name implies) with a PC. The return value can indicate if the NPC has spoken with the PC before or at what point in a complicated conversation they are currently at. For example, a conversation script can be written that only exposes a certain part of the NPC's conversation the first time a PC and an NPC meet.
The following script is taken from the initial conversation of an NPC you meet in the first part of the single-player campaign.
Code:
int StartingConditional( )
{
  int bCondition = GetLocalInt(OBJECT_SELF, "NW_L_TALKTIMES") == 0;
return bCondition;
}
... Okay. You can read that and sort of understand what's going on. A few questions arise though:

1) bCondition is a variable that we define ourselves, rather than a game constant, right? We set it ourselves to an int with "int bCondition =" so that must mean that we're setting it up ourselves to be a custom variable that's referring immediately, right off the bat, to the local integer which refers to the number of times the "L" (Whatever) has been spoken with. This isn't so much a question as it is something to say "... ... ... Yes ShadowTiger. " to. :p
2) The first line of that script was "int StartingConditional" rather than void main( ). I know that void main means that the script isn't "returning anything," (Though I still don't know where it would or wouldn't be returning it to, as when I look at scripts, it's always on an individual script snippet by script snippet basis; never at the whole.) So considering that it says "return bCondition" it must be sending that value somewhere. Where does it say where it's returning it to? Does it automatically assume that it's returning it to the nuclear script (Nuclear, as in nuclear family.) outside of the brackets the script snippet is contained within? Or would it be returned to the variable with the same name anywhere within the local script as the new value of that variable?
3)Referring to the first script under the centered dividor; (The one that gives you a point of damage for entering the area.) why is the syntax object oPC = GetEnteringObject( ); rather than GetEnteringObject( ) = object oPC;?
4) Would that object oPC be a variable? Would either of the two words be a variable? Why would they write oPC instead of just PC? Why would they write object oPC instead of just object PC, etc.
5) On the line "if(GetIsPC(oPC)" why would they say "GetIsPC" but mark the actual PC as being oPC? What would the "o" be doing there? I know this isn't related to ZC, but it's an interesting question in case there are these odd visually mismatching examples within ZScript that one might encounter in one's travels, such as the instance of "this->" etc.
6) On the line with the double ampersand, (&&) I think I can understand what that implies, though two brief questions arise:
  • Why are there two ampersands? Would one suffice? Or is that just general syntax, similar to != and ==?
  • There is nothing after the double ampersand on the same line. If the line underneath it is the second part to an "And" statement, could it be on the same line? Is it really perfectly alright to have it on the line underneath it? (and with any number of return carriages after the double ampersand?



Thank you very much for your patience. :) I'll be sure to get you some ointment for your forehead after slamming it on the head so very many times.