Generic Actor/Info variable to load different config classes

Discussions about Coding and Scripting

Generic Actor/Info variable to load different config classes

Postby CPan » Sun Dec 30, 2018 5:34 am

So, I'm trying to clean up some code and I want to remove multiple calls to different functions to load class files with config options. Right now I have Class0, Class1, Class2, Class3 with the same variables that depend on game type. I am loading these variables by calling a separate function that spawns the Class# file and pulls the variable settings. I am trying to make it so that I have ONE Function where I pass the GameType as a string and load the config class as a local variable of the SAME NAME. The config classes are extending the INFO class. I have tried just straight up LoadVars = SPAWN(class'Class{N}'); but I couldn't get it to work for the already spawned class0. I tried the DynamicLoadObject() function too. I'm missing something obvious but since it's been like 7-8 years since I've coded in UScript it's eluding me...

EDIT: Now that I think about this more, I should use this as a generic global VAR for the config files since I am enabling to make changes to them using mutate commands.

So I am trying to get to the below pseudocode:
Code: Select all
Function LoadSettings( String sGame )
{
     local class LoadVars;

     SWITCH ( sGame )
     {
          CASE "DM":
               LoadVars = somehow load Class1;
               break;
          CASE "TDM":
               LoadVars = somehow load Class2;
               break;
          CASE "MH":
               LoadVars = somehow load Class3;
               break;
           DEFAULT:
               LoadVars = Class0 that is already spawned earlier in the PreBeginPlay() of the mutator;
               break;
     }

     VAR1 = LoadVars.var1
     VAR2 = LoadVars.var2
     VAR3 = LoadVars.var3
//. . . . . . . . .
     VAR{N} = LoadVars.var{N}
}
CPan
CPan
Novice
 
Posts: 8
Joined: Sat Mar 10, 2012 5:28 am

Re: Generic Actor/Info variable to load different config cla

Postby sektor2111 » Sun Dec 30, 2018 5:55 pm

Using game class instead of Map prefix ?
User avatar
sektor2111
Godlike
 
Posts: 4045
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Generic Actor/Info variable to load different config cla

Postby CPan » Sat Jan 05, 2019 4:45 am

No. The Game Class only triggers the switch. I have all the VAR CONFIG items in a separate class so that they are easier to manipulate and set in the INI file. So I am loading those settings per game type instead of having them all be in the base mutator. That gives me the ability to reuse the variables instead of having 4+ bools for removing a certain weapon.

Right now I call separate functions for each class and spawn the Class file when loading the variables. My end result is to go to the single function spawning the settings class needed above from this below:
Code: Select all
function loadDM()
{ Set VARS}

Function LoadCTF()
{Set VARS}

Function LOADMH()
{Set VARS}


So my problem is the LOADVARS = Spawn(Class1), LOADVARS = Spawn(Class2), etc. I can variable it as:
var Class1 CLS1;
var Class2 CLS2;
var Class3 CLS3;

But I want to just use:
VAR (Class{1,2,3} as generic class) LOADVARS;

This way I can reuse the LOADVARS variable and basically cast it to be whatever settings class file I need it to be.



I've subscribed now so I can reply more timely. I thought it did that automatically.
CPan
CPan
Novice
 
Posts: 8
Joined: Sat Mar 10, 2012 5:28 am

Re: Generic Actor/Info variable to load different config cla

Postby Barbie » Sat Jan 05, 2019 9:22 am

You wrote you have tried DynamicLoadObject(). Doesn't it work with this?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1689
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Generic Actor/Info variable to load different config cla

Postby CPan » Sat Jan 05, 2019 3:06 pm

It loaded the class but failed on me being able to compile the class variables into the local mutator variables. I have an idea to try and am going to move around some variables between config file sections and see if that works for me. I also looked at the NW3 source and found some examples where he was doing, what I think, is similar to what I am trying.
CPan
CPan
Novice
 
Posts: 8
Joined: Sat Mar 10, 2012 5:28 am

Re: Generic Actor/Info variable to load different config cla

Postby CPan » Sun Jan 06, 2019 6:56 am

Still not working... I have the DynamicLoad loading the class correctly and I can LOG it outside of the function that is doing the loading BUT, and this is a HUGE BUT, I can't access any of the variables. When I try to access them, it's compiling with an error, 'Unrecognized member <variable> in class Class.' So, I get that it means it can't see the variables in the class. They're there, I checked. I'm at a loss as to why I can do the DynamicLoad and log the Package.Class just fine but not see inside the Package.Class.

I'm going to strip the code I'm working out into another project so I can share it. This is a larger file that I'm working with that has a lot of stuff that is not impacted by this issue.

Since this is a working package, I'm working to implement this without breaking the working file so it isn't pretty and I'm re-learning the code. So, I apologize for this mess of what I have here:
Code: Select all
Class MutTest extends Mutator config(MyConfig);
var class ACEI;

function PreBeginPlay()
{
   local Actor LogActor;
   
   foreach AllActors(class'Actor',LogActor)
        {
           if ( instr(LogActor,"ACEInfo" ) > 0 )
      LOG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Actor:"$LogActor); //This logs the ACEInfo named classes that are spawned.
   }
//There's a bunch of stuff around this...

    LoadACEInfo("DeathMatchPlus"); //To hit the DEFAULT Switch in the LoadACEInfo function
    LOG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ACEI Variable:"$ACEI.bTrans);  //With this here, it fails to compile. Without it, it compiles with no errors.
}


function LoadACEInfo( string sGame )
{
   switch (sGame)
   {
      case "MonsterHunt":
         LOG(" Loading MONSTERHUNT defaults                 ");
         ACEI = class<Actor>(DynamicLoadObject( "TestMut.ACEInfoMH", class'Class'));
         break;
      Default:
         LOG(" Loading DM/TDM Settings                      ");
         ACEI = class<Actor>(DynamicLoadObject( "TestMut.ACEInfoDM", class'Class'));
   }

   LOG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ACEI:"$ACEI); //This logs as TestMut.ACEInfoDM just fine.
}


Code: Select all
class InfoDM extends ACEInfo config(MyConfig);
//ACEInfo contains other variables for the base mutator that are not game class specific.
//InfoMH looks identical to this class

var config bool bTrans;
var config bool bChainsaw;
var config bool bShockRifle;
var config bool bBioRifle;
var config bool bPulseGun;
var config bool bRipper;
var config bool bMinigun2;
var config bool bEightball;
var config bool bFlakCannon;
var config bool bEnforcer;
var config bool bImpactHammer;
var config bool bWarhead;
var config bool bHealthpack;
var config bool bHealthVial;
var config bool bMedBox;
var config bool bArmor;
var config bool bThighpads;
var config bool bBoots;
var config bool bInvisi;
var config bool bBelt;
var config bool bUDamage;

defaultproperties
{
   bTrans=False
   bShockRifle=True
   bChainsaw=True
   bBioRifle=True
   bPulseGun=True
   bRipper=True
   bMinigun2=True
   bEightball=True
   bFlakCannon=True
   bEnforcer=True
   bImpactHammer=True
   bWarhead=True
   bHealthpack=True
   bHealthVial=True
   bMedBox=True
   bArmor=True
   bThighpads=True
   bBoots=True
   bInvisi=True
   bBelt=True
   bUDamage=True
}
CPan
CPan
Novice
 
Posts: 8
Joined: Sat Mar 10, 2012 5:28 am

Re: Generic Actor/Info variable to load different config cla

Postby Barbie » Sun Jan 06, 2019 10:52 am

CPan wrote:Still not working... I have the DynamicLoad loading the class correctly and I can LOG it outside of the function that is doing the loading BUT, and this is a HUGE BUT, I can't access any of the variables. When I try to access them, it's compiling with an error, 'Unrecognized member <variable> in class Class.' So, I get that it means it can't see the variables in the class.
Maybe it will help if you show that part of code.

A quick&dirty solution can be the function "GetPropertyText()" (it does not work for arrays).
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1689
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Generic Actor/Info variable to load different config cla

Postby CPan » Sun Jan 06, 2019 4:11 pm

LOG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ACEI Variable:"$ACEI.bTrans); //With this here, it fails to compile. Without it, it compiles with no errors.


This is where it fails to compile in the MutTest PreBeginPlay() last line. Also if I try and connect to the variables in right after the SWITCH(sGAME) block. bTrans = AECI.bTrans; fails with the same error.

I'll try the GetPropertyText()
CPan
CPan
Novice
 
Posts: 8
Joined: Sat Mar 10, 2012 5:28 am


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 3 guests