For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

[227] Class name and configs

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
User avatar
Alien3674
OldUnreal Member
Posts: 24
Joined: Thu Aug 10, 2017 11:06 pm
Location: Russia

[227] Class name and configs

Post by Alien3674 »

Hello!
Honestly, I do not know how to properly name the topic.

Got a question. The game refuses to accept the class name recorded in the configuration file. But if you write the class in the default settings everything will work.

ASMainPullGameMenu:

Code: Select all

class ASMainPullGameMenu extends ASWindowPulldownMenu
      config(ASMenuComponent);

//custom menu items
struct sPulldownMenuItem
{
      var localized string MenuItemText;         //item text (descriptor)
  var class WindowItem;       //created window
  var class SubMenuItem; //create sub menu item
  var bool bIsSeparator;                     //separating menu item
  var string ConsoleString;                  //console command
      var localized string MenuItemHelp;         //item help text
};

//custom menu items
var config sPulldownMenuItem GameMenuPulls[16];

var UWindowPulldownMenuItem GameMenuItems[16];

//fixed item
var UWindowPulldownMenuItem Quit;
var UWindowMessageBox ConfirmQuit;
var localized string QuitName;
var localized string QuitHelp;
var localized string QuitTitle;
var localized string QuitText;

function Created()
{
      local class tempPulldown;
  local int g;

      super.Created();

  for(g = 0; g < 16; g++)
  {
    Log(GameMenuPulls[g].WindowItem@default.GameMenuPulls[g].WindowItem@default.GameMenuPulls[g].MenuItemText);

//A: pass array
    if (default.GameMenuPulls[g].WindowItem != None || default.GameMenuPulls[g].SubMenuItem != None ||
          default.GameMenuPulls[g].bIsSeparator || default.GameMenuPulls[g].ConsoleString != "")
    {
//A: make sure
      if (default.GameMenuPulls[g].bIsSeparator)
        default.GameMenuPulls[g].MenuItemText = "-";
//A: change text
      if (default.GameMenuPulls[g].MenuItemText == "")
        default.GameMenuPulls[g].MenuItemText = NoDescriptor;
//A: create
      if (default.GameMenuPulls[g].bIsSeparator)
        AddMenuItem(default.GameMenuPulls[g].MenuItemText, None);
      else
      {
        GameMenuItems[g] = AddMenuItem(default.GameMenuPulls[g].MenuItemText, None);
        if (default.GameMenuPulls[g].SubMenuItem != None)
        {
//A: get and load menu class
          tempPulldown = class(DynamicLoadObject(string(default.GameMenuPulls[g].SubMenuItem), class'Class', true));
          if (tempPulldown == None)
          {
            Log("[AS Core [Menu - "$self$"]: failed to load "$default.GameMenuPulls[g].SubMenuItem$"!");
            if (default.GameMenuPulls[g].SubMenuItem != None)
              tempPulldown = default.GameMenuPulls[g].SubMenuItem;
          }
          else
          {
            GameMenuItems[g].CreateSubMenu(default.GameMenuPulls[g].SubMenuItem, self);
//A: can not be requested MenuBar
            ASWindowPulldownMenu(GameMenuItems[g].SubMenu).CreatedMenuItem(None, self);
          }
        }
      }
    }
  }

//A: fixed item
      Quit = AddMenuItem(QuitName, None);
}

function ExecuteItem(UWindowPulldownMenuItem I)
{
  local class tempWindow;
  local int g;

//A: do not
  if (I.SubMenu != None)
    return;

  for(g = 0; g < 16; g++)
  {
    if (GameMenuItems[g] == I)
    {
//A: use only console command
      if (default.GameMenuPulls[g].ConsoleString != "")
      {
        GetPlayerOwner().ConsoleCommand(default.GameMenuPulls[g].ConsoleString);
        break;
      }
      if (default.GameMenuPulls[g].WindowItem != None)
      {
//A: pre load
        tempWindow = class(DynamicLoadObject(string(default.GameMenuPulls[g].WindowItem), class'Class', true));
        if (tempWindow == None)
        {
          Log("[AS Core [Menu - "$self$"]: failed to load "$default.GameMenuPulls[g].WindowItem$"!");
          if (default.GameMenuPulls[g].WindowItem != None)
            tempWindow = default.GameMenuPulls[g].WindowItem;
          else
//A: dont create null
            continue;
        }
        Root.CreateWindow(tempWindow, 100, 100, 200, 200, Self, True);
        break;
      }
    }
  }

//A: fixed item
  if (I == Quit)
    ConfirmQuit = MessageBox(QuitTitle, QuitText, MB_YesNo, MR_No, MR_Yes);

      super.ExecuteItem(I);
}

function MessageBoxDone(UWindowMessageBox W, MessageBoxResult Result)
{
      if (W == ConfirmQuit && Result == MR_Yes)
            Root.QuitGame();
}

function Select(UWindowPulldownMenuItem I)
{
  local int g;

  for(g = 0; g < 16; g++)
  {
    if (GameMenuItems[g] == I)
      UMenuMenuBar(GetMenuBar()).SetHelp(default.GameMenuPulls[g].MenuItemHelp);
  }

//A: fixed item
  if (I == Quit)
    UMenuMenuBar(GetMenuBar()).SetHelp(QuitHelp);

      super.Select(I);
}

defaultProperties
{
//    GameMenuPulls(0)=(MenuItemText="&New",WindowItem=class'UMenu.UMenuNewGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to setup a new single player game of Unreal.")
//    GameMenuPulls(1)=(MenuItemText="&Load",WindowItem=class'UMenu.UMenuLoadGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to load a previously saved game.")
//    GameMenuPulls(2)=(MenuItemText="&Save",WindowItem=class'UMenu.UMenuSaveGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to save your current game.")
//    GameMenuPulls(3)=(MenuItemText="-",WindowItem=None,SubMenuItem=None,bIsSeparator=True,ConsoleString="",MenuItemHelp="")
//    GameMenuPulls(4)=(MenuItemText="Start &Practice Session",WindowItem=class'ASMenuComponent.ASBotMatchFramedWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to begin a practice game against bots.")
//    GameMenuPulls(5)=(MenuItemText="-",WindowItem=None,SubMenuItem=None,bIsSeparator=True,ConsoleString="",MenuItemHelp="")
    QuitName="&Quit"
    QuitHelp="Select to save preferences and exit Unreal."
    QuitTitle="Confirm Quit"
    QuitText="Are you sure you want to Quit?"
}
ASMenuComponent.ini:

Code: Select all

[ASMenuComponent.ASMainPullGameMenu]
GameMenuPulls[0]=(MenuItemText="New",WindowItem=class'UMenu.UMenuNewGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to setup a new single player game of Unreal.")
GameMenuPulls[1]=(MenuItemText="Load",WindowItem=class'UMenu.UMenuLoadGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to load a previously saved game.")
GameMenuPulls[2]=(MenuItemText="Save",WindowItem=class'UMenu.UMenuSaveGameWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to save your current game.")
GameMenuPulls[3]=(MenuItemText="-",WindowItem=None,SubMenuItem=None,bIsSeparator=True,ConsoleString="",MenuItemHelp="")
GameMenuPulls[4]=(MenuItemText="BotMatch",WindowItem=class'ASMenuComponent.ASBotMatchFramedWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="Select to begin a practice game against bots.")
GameMenuPulls[5]=(MenuItemText="OLD",WindowItem=class'UMenu.UMenuBotmatchWindow',SubMenuItem=None,bIsSeparator=False,ConsoleString="",MenuItemHelp="")
GameMenuPulls[6]=(MenuItemText="-",WindowItem=None,SubMenuItem=None,bIsSeparator=True,ConsoleString="",MenuItemHelp="")
Game log:

Code: Select all

ScriptLog: None None New
ScriptLog: UMenu.UMenuLoadGameWindow UMenu.UMenuLoadGameWindow Load
ScriptLog: None None Save
ScriptLog: None None -
ScriptLog: None None BotMatch
ScriptLog: None None OLD
ScriptLog: None None -
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
ScriptLog: None None 
Search the forum did not give results. Maybe I'm doing something wrong? Or do you really want to use a string value instead of a class?

User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: [227] Class name and configs

Post by Masterkent »

A class is an object. In order to form a reference to an object, the object must be created or loaded beforehand. Loading a package does not automatically load all its objects into memory. Initialization of config variables from strings in the corresponding config file does not create/load any objects and only tries to associate references with existing objects. If no matching object can be found for a particular string representation of a reference, the reference becomes None.

In order to store fields of a struct to a config file, the fields should also be declared with the config keyword:

Code: Select all

struct SomeStruct
{
    var config int i;
    var config string s;
};
Last edited by Masterkent on Thu Aug 30, 2018 11:40 am, edited 1 time in total.

Return to “UScript Board”