Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Scripting Question

Page: 1 of 1
 Fallen Guardian
01-15-2011, 3:27 PM
#1
So I have an on enter script and I want NPCs to spawn only after you have been assigned a certain quest. It works well as to the NPCs don't spawn. But when I get the quest and the global boolean is set to true they still do not spawn. Here is the script

int StartingConditional()
{
int iResult;

iResult = ((GetGlobalBoolean("MERC_ASSIGN") == TRUE) );

return iResult;

CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64,50.61,7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85,51.61,7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04,53.33,7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50,52.10,7.72), 0.0));
ExecuteScript("old_k_pdan_14b_area", OBJECT_SELF);

}



Can anyone help?
 TimBob12
01-15-2011, 4:52 PM
#2
That's because that begining bit is for a conditional script and has no actual link to the second bit.

This would be what you're after


void main()
{
int check = GetGlobalBoolean("MERC_ASSIGN");

if (check == TRUE)
{
CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64,50.61,7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85,51.61,7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04,53.33,7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50,52.10,7.72), 0.0));
ExecuteScript("old_k_pdan_14b_area", OBJECT_SELF);
}
}


That should work straight out the box
 Qui-Gon Glenn
01-15-2011, 5:40 PM
#3
So I have an on enter script...

int StartingConditional() // The problem TB12 refers to
{
int iResult; // This is fine, but could be done by merging

iResult = ((GetGlobalBoolean("MERC_ASSIGN") == TRUE) );// with this line, like so:

// int iResult = GetGlobalBoolean("MERC_ASSIGN")

return iResult;

CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64,50.61,7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85,51.61,7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04,53.33,7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50,52.10,7.72), 0.0));
ExecuteScript("old_k_pdan_14b_area", OBJECT_SELF);

}
The other issue is that you want to make sure that you do not assume a value to the boolean before checking it.... you had done so by specifying == TRUE in that integer declaration. A boolean is either true or false by def, so you only need check against the true value, as TimBob12's script does.

So, using TB's script with your var names, would be this:

void main()
{
int iResult = GetGlobalBoolean("MERC_ASSIGN");

if (iResult == TRUE)
{
CreateObject(OBJECT_TYPE_CREATURE, "n_merc02", Location(Vector(559.64,50.61,7.70), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_doha", Location(Vector(566.85,51.61,7.57), 180.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_merc01", Location(Vector(560.04,53.33,7.76), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "n_aramil", Location(Vector(561.50,52.10,7.72), 0.0));
ExecuteScript("old_k_pdan_14b_area", OBJECT_SELF);
}
}
One more tip to the would be scripters out there:

This is not a universal law, and many coder's far more experienced and professional than I scoff at this. At the same time, the vast majority of coders will agree with what I am saying, so take it FWIW: Indentation in your coding can make it far easier to read, follow, and troubleshoot. When used properly, you can see at a glance the relationship of conditionals by how they are nested. When things do not follow a uniform structure, it is easy to confuse what part of code belongs to what.

So, indent at every level of code abstraction. What does this mean?
void main() - gets no indentation, as it is the root of the code
{ - first bracket, same deal as above, this is the beginning of the code map.
int iInteger; - should be indented; this is the base indentation for the main actions of the function. If there is nothing conditional happening for the particular event, it should be on this level of indent.
if (iInteger == 1) - this is on the same indent as the declared int... it is the base conditional, of which there can be more than one. Not generally though...
{ - this is the opening bracket for the if, directly under the if, so when the conditional is done, there should be a corresponding bracket on the same abstraction indent
GetEnteringObject(oNPC.... - this is how we nest the conditionals, by indenting under the conditional declaration. A new layer of abstraction is created by indentation, so we know that unless we are looking to check against that specific conditional, the indented portion can be ignored.
if oNPC == "Atton" - new conditional, inside a conditional. it starts at the abstraction indent of the GetEntering line, as this is still included in the same if conditional
{ - inside if bracket
SendMessageToPC("It's Atton");
} - closes the inside if
} - this closes the main if
} - closes the main
... and so on. I have just noticed that some of us, while already more knowledgeable at KotOR scripting than I am, do not have the software writing education that I do. This is 101 stuff, but many people find it helps make your code more readable, and to me I want my code to be easy to read.... because it is often TOTALLY WRONG :lol:
 Fallen Guardian
01-15-2011, 6:58 PM
#4
Thanks both of you.
Page: 1 of 1