Skip to content

How do I pass an integer to a new script?

I want to pass an integer to a new script.

I converted it into a string for the purpose of using SetScriptParam, but I don't know how to set that part up before I execute the next script. It says I need to set it up via SetScriptParam(string, string) but there isn't a proper sample on nwnlexicon for setting the strings.

When I have it in a way I think it would work, I get an Unknown State in Compiler error for the SetScriptParam line.

Comments

  • ForSeriousForSerious Member Posts: 446
    edited November 2022
    Can you show us your code? The line where you have SetScriptParam and the lines before and after.

    You might not need to:
    int iInt = 5;
    SetScriptParam("variable", IntToString(iInt));
    
    And then in the next script you call:
    int iInt = StringToInt(GetScriptParam("variable"));
    
  • MelkiorMelkior Member Posts: 181
    Before calling the script, use SetScriptParam to assign a "name" to the parameter (the first string variable) and a "value" (the second string variable) to be assigned to that name. Repeat if you have more than one parameter to pass.
    Call the script using ExecuteScript or ExecuteScriptChunk.
    Inside the script you are calling, use GetScriptParam with the name you assigned to the parameter in order to access it and assign it to a variable. You can then manipulate that variable like any other.

    But the error you're getting sounds like you've forgotten to terminate the previous command with the semi-colon, not a problem with the SetScriptParam command.

    Some script fragments may help. First, the calling script:
    int iNumber=1001;
    string sNumber=IntToString(iNumber);
    SetScriptParam("INTEGERNUMBER",sNumber);
    ExecuteScript("calledscript");
    

    How to get that number back inside "calledscript":
    sNumber=GetScriptParam("INTEGERNUMBER");
    iNumber=StringToInt(sNumber);
    

    I hope this helps.
  • vxicepickxvvxicepickxv Member Posts: 6
    Melkior wrote: »
    But the error you're getting sounds like you've forgotten to terminate the previous command with the semi-colon, not a problem with the SetScriptParam command.

    I hope this helps.

    My error was much simpler than previous command termination. I didn't have my variable in quotation marks.
  • ForSeriousForSerious Member Posts: 446
    I also suspected something like that. Glad you got it figured out.
Sign In or Register to comment.