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?
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?
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)
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
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.
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.
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.
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.
I'm sorry, but I don't see where you've identified anything as the string called Action.
Why not just try it DI's way and see what happens? You've nothing to lose.
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.
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.
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
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".