Player Resource Consortium

 

Author Topic: Servers, switches, and the personal_switch.2da  (Read 5663 times)

0 Members and 1 Guest are viewing this topic.

October 30, 2010, 01:13:47 PM

The documentation for the personal_switch.2da says it can't be used with servers, but looking at the code I don't see a reason as to why it can't. I am missing something here that would prevent people from using the switch 2da on their servers? The reason I ask this is setting each and every variable for 4 modules is a bit of a pain. So if I get around to converting the server I help run to the PRC this would help save me work. I know I could write up a script to set it them using SetPRCSwitch, but I was curious if the personal_switch.2da would work as well. Am I correct that you could use the 2da for servers, or am I missing something?

Code: [Select]
   //load any default switch 2da
    object oModule = GetModule();
    int i = 0;
    string sSwitchName, sSwitchType, sSwitchValue;
    // Use Get2DAString() instead of Get2DACache() to avoid caching.
    // People might want to set different switch values when playing in different modules.
    // Or just change the switch values midplay.
    while((sSwitchName = Get2DAString("personal_switch", "SwitchName", i)) != "")
    {
        // Read rest of the line
        sSwitchType  = Get2DAString("personal_switch", "SwitchType",  i);
        sSwitchValue = Get2DAString("personal_switch", "SwitchValue", i);

        // Determine switch type and set the var
        if     (sSwitchType == "float")
            SetLocalFloat(oModule, sSwitchName, StringToFloat(sSwitchValue));
        else if(sSwitchType == "int")
            SetPRCSwitch(sSwitchName, StringToInt(sSwitchValue));
        else if(sSwitchType == "string")
            SetLocalString(oModule, sSwitchName, sSwitchValue);

        // Increment loop counter
        i += 1;
    }