Unable to Run My Scripts


#1

I recently started playing this game again after about five years. Previously I had made about 20 scripts and some I wanted to run. I also had recently made over 50 scripts for NWN 1. These were mostly to add and equip or unequip armor and weapons. These scripts all worked well in NWN, so I imported them into the NWN2Toolset and re-compiled them. After I finished, I placed them in the My Documents\Neverwinter Nights 2\override folder along with weapon and armor blueprints I created with the tool kit. I did this before even starting the game.

As soon as I started the game, I tried to run a script to add and equip my armor. I used DebugMode 1 and then “rs aces_add12armor” to call the script. (name carried over from NWN) I received a script error “Virtual Machine reports unsuccessful execution of script aces_add12armor for object Ace sHigh.” I rechecked my spelling and tried it again. I then tried running several scripts to install weapons. I received errors every time. I had to use giveitem itemID to add everything I wanted and equip them manually. Since the console was working I knew that wasn’t the problem. I went back into the toolset and rechecked my scripts and they looked ok. I checked online for similar problems and did not see anything close.

I tried running some simple scripts to see if they would work and still received errors. I tried running several cheat scripts built into the game like rs ga_party_limit(6) and rs ga_influence (#,##) and those worked perfectly. I decided to add the Advanced Script Compiler to see if there was a problem with my scripts and did not find any. Finally, I wrote a very simple test script which is below:

void main()
{
object oPC=GetPrimaryPlayer();
string sMsg;

sMsg=“This is a test!”;
FloatingTextStringOnCreature(sMsg, oPC);
}

I ran this script and also received the unsuccessful execution error. This has been very frustrating for me and I finally decided to ask for help. If anybody knows why this might be happening, I would appreciate your help!


#2

The problem seems to be coming from the bad left/right quotation marks in the sMsg=“This is a test!”; line.
Replace them with " (shift+comma) and recompile.


#3

This script compiles OK. (Shift+comma) is a “<” on my keyboard and there is only one set of quotes on my keyboard. I have used those quotation marks in all of my scripts for NWN without any problems. Why would they be a problem for NWN 2. Why would they compile if they were a problem? When I try your recommendation, I get a compiler error “test.nss(7): Error: NSC1040: Syntax error at “<” (see verify window for full context)”. I even deleted that whole line and recompiled it and it still would not run in the game.

I’m not having trouble compiling my scripts, only running them in the game. I appreciate you replying, but that is not what is preventing my scripts from running.


#4

Sorry, I made a mistake. It’s shift + ’ (single quote) which gives you the double quote ".
In my toolset, your script would not compile until I changed your quotes to ".
Then the script worked fine. I tested it in game through the console, too - worked fine.


#5

That is the one I have been using. I don’t know why it would have changed on this page. It has always compiled for me. I think all of my scripts should run. That is the problem!

Try this one:

/******************************

Created by dwharper34 aka AcesHigh

   November 13, 2018

Determines Henchman Tags

    aces_henchmen

******************************/

void main()
{
object oPC=GetPrimaryPlayer();
object oHench;
string sMsg;
string sTag;

int nIndex;
int nMaxHench = GetMaxHenchmen();
for (nIndex = 1; nIndex <= nMaxHench; nIndex++)
{
oHench = GetHenchman(oPC,nIndex);
if (oHench != OBJECT_INVALID)
{
sTag = GetTag(GetHenchman(oPC,nIndex));
if (sTag != “”)
{
PrintString(sTag);
sMsg=GetName(oHench) + " is the Name and " +sTag + " is the tag for Henchman #" + IntToString(nIndex) + “!”;
FloatingTextStringOnCreature(sMsg, oPC);
PrintObject(oHench);
PrintString(sMsg);
}
}
}
}

Thanks for your help!


#6

Just a little thing. There is a pinned thread that tells you how to get formatted code (amongst loads of other things) on here. So the above code can look like this -

/******************************

Created by dwharper34 aka AcesHigh

   November 13, 2018

Determines Henchman Tags

    aces_henchmen
******************************/

void main()
{
    object oPC=GetPrimaryPlayer();
    object oHench;
    string sMsg;
    string sTag;

    int nIndex;
    int nMaxHench = GetMaxHenchmen();
    for (nIndex = 1; nIndex <= nMaxHench; nIndex++)
    {
        oHench = GetHenchman(oPC,nIndex);

        if (oHench != OBJECT_INVALID)
        {
            sTag = GetTag(GetHenchman(oPC,nIndex));
            if (sTag != "")
            {
                PrintString(sTag);
                sMsg=GetName(oHench) + " is the Name and " +sTag + " is the tag for Henchman #" + IntToString(nIndex) + "!";
                FloatingTextStringOnCreature(sMsg, oPC);
                PrintObject(oHench);
                PrintString(sMsg);
            }
        }
    }
}

TR


#7

This script also would not compile due to the erroneous quotes in the following two lines:

if (sTag != “”)

and

sMsg=GetName(oHench) + " is the Name and " +sTag + " is the tag for Henchman #" + IntToString(nIndex) + “!”;

In the second line, it’s the quotes around the bang (!) at the end of the line.

Note the difference between those quotes in both lines. I changed the erroneous quotes to " and now I’m able to compile it. I also tested it in game through the console - runs fine.

Note the deference of the quotes here:

if (sTag != “”)
if (sTag != "")

#8

@travus That is down to discourse being “helpful”. If @AcesHigh had actually done it with code formatting the wrong sort of quotes would not be there.

TR


#9

Guys, all I’m saying is if you copy/paste AcesHigh’s original script into your toolset, it will not compile because he is using a different style of quotes.
The script in Tarrot_Redhand’s post WILL compile because he edited the erroneous quotes to make it correct.

For example - Someone copy/paste this exact script into your toolset and let me know if it compiles. I’m willing to bet it will not:

void main()
{
	string sTag = GetName(GetFirstPC());
	if (sTag != “”) return;
}

Also, try copy/pasting it in this format:

void main()
{
string sTag = GetName(GetFirstPC());
if (sTag != “”) return;
}

If you look at these quotes in the toolset, you can clearly see that they are not the normal quotes used in scripting.


#10

Travus is correct, it is an issue with the quote marks. You can delete the quote marks of the original, then put in new quotes with the keyboard, and it will compile. The toolset also highlights the “this is a text” code in red when it’s properly quoted (though that’s possibly some plugin I have).


#11

You are not getting what I meant. If you paste your code into here without making it a pre-formatted code block, Discourse will prettify what you paste so that it has the wrong quotation marks. As an example of this here is an unedited code snippet without it being marked as code -

void TimerPseudoHB(object oTicker)
{
if(!(GetLocalInt(OBJECT_SELF, “bTimerRunning”))) // Recursion guard -
return; // terminate timer prematurely

and with being marked as code -

void TimerPseudoHB(object oTicker)
{
    if(!(GetLocalInt(OBJECT_SELF, "bTimerRunning"))) // Recursion guard -
        return;                                      // terminate timer prematurely

I repeat, both are unedited. Note the code block has the right sort of quotes while the plain text version has the wrong.

If you don’t believe me try it yourself.

TR


#12

I copy/pasted your code with ``` at beginning and end of the code block.

void TimerPseudoHB(object oTicker)
{
if(!(GetLocalInt(OBJECT_SELF, “bTimerRunning”))) // Recursion guard -
return; // terminate timer prematurely

Still has the left/right leaning quotes. I also did not edit the code itself.

Back to my point - The left/right leaning quotes will not compile in the toolset. So if AcesHigh copy/pasted his code directly from the toolset onto his original post above, then the quotes are bad.


#13

If the forum software is prettyfying things by changing the actual content (from valid quote marks to not valid things that look like quote marks), then that’s a serious issue with the forum software.

void main()
{
object oPC=GetPrimaryPlayer();
string sMsg;

sMsg=“This is a test! Kamal”;
FloatingTextStringOnCreature(sMsg, oPC);
}


#14

So, if I use the methods for posting code here, by making it a pre-formatted code block, the quotes would remain correct?

The issue remains. I uninstalled and reinstalled NWN 2 twice this morning, once on the C: drive and back to the F: drive, and I still cannot run any of my scripts. I wrote about 20 scripts 5 years ago when I last played the game and they worked then. Now I can’t get any to run. I don’t remember where I got that game from, possibly from GameStop, but the one I’m using now is from GOG. No one else seems to be having the same issue.

Most of the scripts I’ve written lately, I wrote originally for NWN and they all worked. All I’ve done is recompiled them for NWN 2.They all compile with no errors. Like I said earlier, the scripts that are included in the game, like ga_influence and ga_party_limit(6), work alright. And giveitem works, so I know that the console is working. What is the problem?

Thanks for your help!


#15

@kamal I just copy/pasted your test script to my toolset and it would NOT compile due to bad quotes. Once I changed the faux quotes to normal quotes, everything compiled and worked fine. I have to agree with you that if code in our posts is being changed behind the scenes, then that’s a no go.

@AcesHigh Your scripts worked fine as long as the quotes are fixed - At least in my toolset they did. Have you tried completely retyping them in the NWN2 toolset and then recompile?


#16

@kamal grabbed your code, pasted into npp, corrected the quotes then copy/pasted into a code block. Using code blocks is easy enough to do just look here.

@travus Instead of copying from one code block to another, did you try copying the code from the code block to a plain text file or a script editor? While copying from one code block to another is not unheard of it is nowhere near as common as copying the code from the code block to a plain text file or a script editor. So I tried to replicate what you are seeing using @kamal’s code.

void main()
{
    object oPC = GetPrimaryPlayer();
    string sMsg;

    sMsg = "This is a test! Kamal"; 
    FloatingTextStringOnCreature(sMsg, oPC);
}

I then copied and pasted into a second code block -

void main()
{
    object oPC = GetPrimaryPlayer();
    string sMsg;

    sMsg = "This is a test! Kamal"; 
    FloatingTextStringOnCreature(sMsg, oPC);
}

and still the quotes are the right ones. Sorry, I can’t replicate what you are seeing.

TR


#17

I guess you don’t understand. The page is changing the quotes, not me. They compile fine on my computer. If the quotes were bad it would not even compile!

Tarot_Redhand explained it above, but you are not getting it. You said after fixing the quotes, that the script ran fine on your computer. It will not run on my computer and it should. That is the problem! Not my script.


#18

It’s just a thought but are you on windows? If so have you tried right clicking on the toolset’s exe and selecting properties. Then select the compatibility tab and check the run as administrator checkbox.

It’s just I figured that as windows has got more security concious it won’t allow an older program to write to disk without that being checked.

TR


#19

Yes. I have already set it into compatibilty mode for Windows 7 and set to run as Administrator. I copy the *.ncs files into My Documents\Neverwinter Nights 2\override. I would have uploaded the actual script here, but it does not allow ncs files. I doubt that the problem is in the script file itself though.


#20

@AcesHigh
sometimes (once or twice in blue moon) the console doesn’t accept “rs” for RunScript on my system. Instead i have to type out the full “RunScript” (+ scriptname, ofc)

you could try that, although i don’t know why it happens nor why a stock script would run w/ “rs” but a custom script’d require “RunScript” …