Jump to content

Home

Scripting Question


Fallen Guardian

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

So I have an on enter script...

 

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

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

[color=darkorange]// int iResult = GetGlobalBoolean("MERC_ASSIGN")[/color]

 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:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...