Skip to content

ERROR: BAD VARIABLE NAME?

NeverwinterWightsNeverwinterWights Member Posts: 339
edited August 2022 in Builders - Scripting
Perhaps someone can help me out and figure out why the following script keeps giving me an "ERROR: BAD VARIABLE NAME". It's originally part of a separate library but to test it out I put it in a separate script on it's own and it's still giving me the error. There is literally nothing else in this script:
void AddLanguageToLanguageArray(object oDBItem, string sLanguage)
{
    int iLanguage = 1;
    string sCheck = GetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguage));
    while (sCheck != "")
    {
        iLanguage++;
        sCheck = GetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguage));
    }
    if (sCheck == "")
    SetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguage), sLanguage);
}
void main()
{

}

It's specifically the perameter "string sLanguage". If I change it to "string sLanguag" (no e) it compiles fine.

Comments

  • TerrorbleTerrorble Member Posts: 169
    I pasted this and got the same thing using the default compiler. It will work if you don't capitalize the L, or make any change to the var name. It seems sLanguage specifically cannot be used.

    What's also wierd is I typed sLanguage as slanguage in the function header but didn't change the reference to the var in the last line of the function to match it, and it compiles fine.
    void AddLanguageToLanguageArray(object oDBItem, string slanguage)//<----- changed the var
    {
        int iLanguag = 1;
        string sCheck = GetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguag));
        while (sCheck != "")
        {
            iLanguag++;
            sCheck = GetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguag));
        }
        if (sCheck == "")
        SetLocalString(oDBItem, "LANGUAGE" + IntToString(iLanguag), sLanguage);//<----- forgot to change the var to match
    }
    void main()
    {
    
    }
    

    Wierd!
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Terrorble wrote: »
    Wierd!

    Indeed. I guess in the meantime I'll just change that parameter to something else but it certainly is curious.
  • KamirynKamiryn Member Posts: 74
    edited August 2022
    Reason is that sLanguage is already defined in nwscript.nss as
    string sLanguage = "nwscript"
    

    You can see that if you double-click the sLanguage in your script. Apparently it's not allowed to re-define variables defined in nwscript.nss.

    That also explains why it compiles if you change the header. But of course in your function then the sLanguage from nwscript.nss would be used and not your parameter slanguage.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Kamiryn wrote: »
    Reason is that sLanguage is already defined as
    string sLanguage = "nwscript"
    

    You can see that if you double-click the sLanguage in your script.

    Ah gotcha. I was thinking it might be something already defined but it was the first time I'd seen that particular error. Also...why did I never know that you can double click things like that in the script until literally just now? Learn something new every day!

    Thank you.
Sign In or Register to comment.