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.

Trigger Function

Page: 1 of 1
 TimBob12
07-20-2011, 5:18 PM
#1
So I decided that it would be handy to be able to script triggers so I decided to write another function. Currently I have code that compiles but doesn't seem to do anything.

Here is what I have:

Example.nss


#include "trigger"

void main()
{
float x = -31.06730;
float y = 111.57073;
float z = 12.75084;
float orient = 0.0;

vector test = Vector(x,y,z);

location test2 = Location(test, orient);
string script = "debug_script";

new_trigger(test2, 10.0, script);
}


Trigger.nss:


#include "k_inc_generic"
#include "k_inc_utility"

void new_trigger(location loc, float radius, string Action)
{
object trigger = GetFirstObjectInShape(SHAPE_SPHERE, radius, loc, FALSE, OBJECT_TYPE_CREATURE);
object oPC = GetFirstPC();

while (GetIsObjectValid(trigger))
{
if (trigger == oPC)
{
ExecuteScript(Action, OBJECT_SELF);
}
else
{
trigger = GetNextObjectInShape(SHAPE_SPHERE, radius, loc, FALSE, OBJECT_TYPE_CREATURE);
}
}
}


//Ignore this for now
void destroy_trigger()
{
}


Debug_script.nss


void main()
{
object oPC = GetFirstPC();
SendMessageToPC(oPC, "The trigger worked!!!!");
}


In theory this should work and it all compiles fine but no message comes through.

Any ideas people?
 newbiemodder
07-20-2011, 7:12 PM
#2
Glad you decided to give this a try...good luck..I know nothing about scripting...did you put all the .ncs scripts in override or your .mod file....how are you injecting this script into the module..on enter? or on an npc? Maybe your saved game you are using is the problem?
 Marius Fett
07-20-2011, 7:50 PM
#3
Now, I know next to nothing about scripting, so I may well be talking out of my backside here, but I'm not familiar with the 'string script' part in the first piece of code you posted. Would it make a difference if you used the ExecuteScript() command instead?

Also, in your script, you refer to the debug script as "debug_script" whereas later you call it "Debug_script" with a capital D on debug.. I think the name of the ncs has to EXACTLY match what you refer to it as In the script?

Of course, I may just be talking crap. :)

(sorry if this is poorly written, it was done on my phone)
 TimBob12
07-21-2011, 2:02 AM
#4
Now, I know next to nothing about scripting, so I may well be talking out of my backside here, but I'm not familiar with the 'string script' part in the first piece of code you posted. Would it make a difference if you used the ExecuteScript() command instead?

Also, in your script, you refer to the debug script as "debug_script" whereas later you call it "Debug_script" with a capital D on debug.. I think the name of the ncs has to EXACTLY match what you refer to it as In the script?

Of course, I may just be talking crap. :)

(sorry if this is poorly written, it was done on my phone)

The string script just defines a text variable which passes the name of your script to the ExecuteScript() command in the trigger so that people can pass any script they want to run in its parameters.

The second refferal to Debug_script.nss was me just being too gramitacally correct :P



I am running the script through an NPCs dialogue. and all the .ncs files are in my .mod
 Darth InSidious
07-21-2011, 5:06 AM
#5
It may be because you've got the script identified by two different identifiers. In example.nss, it's identified as script, but in trigger.nss it's identified as Action.

As in:

string script = "debug_script";


But:


void new_trigger(location loc, float radius, string Action)

...

ExecuteScript(Action, OBJECT_SELF);


If I've read this right, anyway.
 TimBob12
07-21-2011, 5:58 AM
#6
No the string variable is inserted into action for the function. It means the functioon can be used with cystom variables passed to it. I dont think ive explained it very well.
 Darth InSidious
07-21-2011, 6:55 AM
#7
I'm sorry, I'm not seeing any connexion between the two in the scripts you've provided. So far as I can see, string script = "debug_script"; says that the item "debug_script" is to be treated as an object of the type string, called script. It's the same as putting:


object oPC = GetObjectByTag("object_tag");

You're not actually telling the script to do anything with it, you've just defined it in the context of that script.

In your trigger include file, string Action is looking for a string called Action. You're providing a string called script. The identifier string in both cases is just the type of thing being looked for.
 TimBob12
07-21-2011, 7:27 AM
#8
I am putting the contents of string through the function as Actiton. The trigger then takes the content of action, in this case it is the same as the content of string which is "debug_script". The trigger function takes the content of action and executes a script that has the same name as what is stored in the action variable.
 Darth InSidious
07-21-2011, 8:06 AM
#9
I'm sorry, but I don't see where you've identified anything as the string called Action.
 Marius Fett
07-21-2011, 8:10 AM
#10
Why not just try it DI's way and see what happens? You've nothing to lose.
 TimBob12
07-21-2011, 8:27 AM
#11
Im on my phone so i cant at the minute. Anyway its the same as any other functin. You can pass any variable to it as long as it is the right type. Will try it later.
 Darth InSidious
07-21-2011, 8:47 AM
#12
string is not a function. It is a variable. If you want to a particular string in the places you've marked as "string Action", they need to be identified as "string Action". Same as with objects, effects, ints, floats and so on.
 TimBob12
07-21-2011, 2:33 PM
#13
I never said string was a function I am declaring string to pass it to a function with its contents. I will try it your way but this method is what I used before.

This example from cplusplus.com shows how two variables can be substituted into a custom function in place of raw bits of data


int main ()
{
int x=5, y=3, z;
z = subtraction (7,2);
cout << "The first result is " << z << '\n';
cout << "The second result is " << subtraction (7,2) << '\n';
cout << "The third result is " << subtraction (x,y) << '\n';
z= 4 + subtraction (x,y);
cout << "The fourth result is " << z << '\n';
return 0;
}


I don't quite understand what you are saying. Probably my fault though as I can be a bit stupid and ignorant to the blazing obvious. :p
 Darth InSidious
07-21-2011, 6:11 PM
#14
OK, I think we've been talking at cross-purposes a bit, but my idea was basically this: try changing "script" in example.nss to "Action".
Page: 1 of 1