logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Duplicate function errors

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Thu Jul 29, 2010 12:16    Post subject: Duplicate function errors Reply with quote

Hi everyone,

With help from a few of you here I have managed to get nwnx running and the server restarting on its own.. So thank you for the help you have given me so far.

Now, I am working at creating my own scripts to prevent the death, spell and hp logging exploits. While I have seen some scripts available on nwvault. I felt it was a good starting exercise at learning how to use the new persistent database functions with nwnx.

I am getting some strange behavior from the aps_include file and am hoping someone can give me a clue. When I add the include "aps_include" to the top of some of my scripts and compile them I get duplicate function errors. When in the nwn toolset script editor there will be two of the same functions listed at the right under the functions panel. When i take the include file back out and recompile the duplicate error goes away. What is really stumping me is that it doesn't happen with every script that I try to add the include file to. Some compile just fine and some duplicate functions. I am at a loss at this point as to what could cause this. Also, it is not always the same function getting duplicated. But, I know the duplicates are coming from the include file because they go away when I remove the include and recompile.

Ok I am starting to confuse myself so hopefully I explained what was going one well enough.

Thanks,

-Mal
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jul 29, 2010 18:13    Post subject: duplicates mean Reply with quote

If you are getting a message that says that you have duplicate functions, it is possible you do.


Go find the name of your duplicate function, and then search through your script to find anything with the same name.

Also remember to search include files.


if you have SetPersistentInt() inside your aps_include
and
if you have SetPersistentInt() inside another include file at the same time, they will both try to be read and loaded into memory, causing the error.
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Fri Jul 30, 2010 11:18    Post subject: Reply with quote

I willl look into all the includes again. I thought that may be the problem as well and checked for that but I will take another look.

It was thorowing me off because when the aps_include is part of the compile the duplicate functions show up in the function list as two of the same name. When I remove the aps_include file from the compile, both of the duplicate functions go away.
This would make me think that both of the functions are in the aps include file. However, I can add the same aps include file to a different script and i get no errors on compile.

-Mal
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Sat Jul 31, 2010 4:44    Post subject: Reply with quote

Ok, I figured it out how to stop the duplicate function errors. It seems that any scripts that I try to add the aps include file to that also have the horse system included as well give me duplicate function errors as the horse includes have the same function names. These are StringToVector, LocationToString, StringToLocation, and VectorToString.

What I have done to solve this is change the functions in the aps include file to
apsLocationToString, apsStringToLocation etc... then changed the rest of the aps_include file accordingly.

Does this seem like a good way to do this or does someone else have a better way?

Thanks,

-Mal
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Jul 31, 2010 6:13    Post subject: There is an easier way Reply with quote

You can separate your calling script, over two scripts.


eg
If aps_include and horsey_script have conflicting functions,

then have

aps_include in your main script


and then at the end of the main script, or whereever you need it done,

Put in
Code:

ExecuteScript(oPC,"streamlined_1");


Note, I cant remember if I got those arguments right way round.

Anyway, now...
Go into nwnscript, and make a new script, with that name, or whatever name u want.

and copy , cut and paste all the horse related content that you have in the main script, and put it in there.

Anything that tries to run on oPC, change it to OBJECT_SELF,
or

put this at the top, inside the void main()
Code:

object oPC = OBJECT_SELF;




So, you script would looking this


Code:

//main calling script
#include "aps_include"
void main()
{
object oPC = GetEnteringObject(); // or whatever oPC Should be.

GetPersistentLocation();
GetVector(yadayadayadad)


//Horse System here
ExecuteScript(oPC,"mylittle_ponies");
//End of Horse system

}





Now, you second script, in this case "mylittle_ponies"

Code:

//main calling script
#include "horse_include"
void main()
{
object oPC = OBJECT_SELF; // or whatever oPC Should be.

//You will find that you can now use all
//your functions in THIS script, without hassle.



}




This method, is called by some, and me, or at least, most importantly me.
Streamlining.

It is useful for a number of reasons.

If you have problems with include files -> Streamlining can get around it.
If you have used too many include files, and get Identifyer List full errors -> Streamlining can fix it.
If you wana keep scripts set up so they only contain functions necessary to their functionality, then Streamlining is good too.

Eg -
Instead of running your subrace functions, directly from onClientEnter, it likely does an ExecuteScript() call to a specific script which then takes over. There ya go, you were streamlining without realising.


eg
You could do

ExecuteScript(oPC,"subrace_onenter"); // Subrace onClient Enter functions
ExecuteScript(oPC,"check_access"); //Checks if they are dm, and if they have dm rights in the database perhaps?
ExecuteScript(oPC,"give_rewards"); // Give the player rewards if due
ExecuteScript(oPC,"anti_hack_onenter"); // Check the player to see if they look suspicous.
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Sat Jul 31, 2010 7:07    Post subject: Reply with quote

Hi thanks for that post Baaleos.

I did try to use execute scripts at first to get around the include errors. But, I got confused about how the ExecuteScript function works.

For instance,

If I wanted to set a persistent int on a player when they are a target of a spell such as Raise or Resurrection. In the raise and resurrection spell scripts the player being raised is identified as oTarget, so I would use

ExecuteScript(oTarget, "script name");

But in the script I am now executing I am having difficulty identifying the PC. It was easy when using the on rest, on respawn etc... events. But now I am having difficulty identifying my object ie.
Code:
#include "aps_include"
void main()
{
object oPC="something here";
 if (GetPersistentInt(oPC,"dead_or_alive","pwdata") == 1)
    return;
 else
    SetPersistentInt(oPC,"dead_or_alive",1,0,"pwdata");
}


Hope what I am saying makes sense. I am fairly new at scripting so I may be asking a bonehead question.

Thanks,

-Mal
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Jul 31, 2010 14:36    Post subject: Reply with quote

When you execute a script on a target, that object is running the script, and can b used as Object_self. So object_self is what otarget becomes.
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Sat Jul 31, 2010 23:42    Post subject: Reply with quote

Thanks a lot Baaleos. That explains fully why it didn't work when I tried execute script before. Hmm... I have the death system working now going another route, but I am thinking that I like the "streamlining" idea.

Are there any performance issues with calling multiple execute scripts instead of having all the code in one script. I would imagine you can end up with alot more ncs files. Is that a problem?

Thanks,

-Mal
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Jul 31, 2010 23:47    Post subject: Reply with quote

its true,
for each nss you have, an ncs file will be created.


But sometimes, streamlining with multiple files is a necessity, to get around conflicting include files.


For instance,
I had an issue, where shayans subrace engine, wouldnt work with funkyswerves Simtools, because their includes both 'included' too many functions.

The way to fix this, was to span the onClientEnter Script, over two scripts, performance wise, Executing a new script doesnt eat up any performance, since it is just the same as calling any function.

eg
SendMessageToPC() will run just as easilly as ExecuteScript

Of course, the Duration of the ExecuteScript may take longer, depending on the content of the script you are executing.

eg-
If you have a while loop inside it, which takes 25 seconds to finish, then, you will see 25 second delays potentially.
But it is up to you, to make sure your own scripts are efficient.

This streamlining method is just intended as a way to work arround limitations in the nwnscript compiler.

Eg - you can get compilers from the vault, which allow you to compile outside of nwntoolset, and these will not have the limitation on included functions.

But I never used them for the hassle.
Back to top
View user's profile Send private message
Mal



Joined: 25 Jul 2010
Posts: 13

PostPosted: Sun Aug 01, 2010 0:09    Post subject: Reply with quote

Great information. I really appreciate the help that you have given me.

Sincerely,

-Mal
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group