Referencing classes from another package?

Discussions about Coding and Scripting
Post Reply
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Referencing classes from another package?

Post by 1337GameDev »

Is there anything special about trying to reference classes from another custom package?

I have 2 packages,

Code: Select all

Package1.Class1
and

Code: Select all

Packlage2.Class2
, and I want to call a static method in Class1 from Class2, like:

Code: Select all

class'Package1.Class1'.static.SomeMethod();
How is this done? I know I can "dynamicload," but that doesn't work for compile time references.

When building this, I get the following error:

Code: Select all

Class2.uc(8) : Error, Can't find Class 'Package1.Class1'
Critical error while compiling
Ideas?

I have Package1 BEFORE Package2 in my EditPackages section in the

Code: Select all

UnrealTournament.ini
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Referencing classes from another package?

Post by Feralidragon »

Have you tried just class'Class1' (without the package)?

I remember that specifying the package works in some specific cases (such as in extends ), but not in others (maybe something to check in 469), so the package name shouldn't really be used explicitly anywhere.
User avatar
sektor2111
Godlike
Posts: 6413
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Referencing classes from another package?

Post by sektor2111 »

I would try an "#exec obj load" directive for compiling...

Let me look at something as example and I'll be back...

EDIT: Let me show you something for previous explanation.

Code: Select all

class WarExplosion2 extends WarExplosion;

#exec OBJ LOAD FILE=textures\WLExplo.utx PACKAGE=BotPack.WarExplosionS2
In order to compile in BotPack said WarExplosion2, due to reference to a Texture, it was added an import directive in compiler. This directive loads a Texture file which was already created before, or else Texture would need to be created directly from a BMP/PCX source-file. Texture in this case was used for being as BotPack, but you can have as reference an external texture - only if it does exist or else code referencing Texture won't be generated.

Your stage is... two stages:
#1 Creating/Compiling Package1
#2 Creating Compiling Package2 with reference to Package1
#3 Attempting here to deal with "Class1" and look what fails if it fails

At least this is what I would do - my two cents.
Last edited by sektor2111 on Tue Apr 05, 2022 4:09 pm, edited 4 times in total.
Dennis
Average
Posts: 72
Joined: Tue Jan 12, 2021 9:18 pm

Re: Referencing classes from another package?

Post by Dennis »

have you tried the following?

Code: Select all

function SomeFunction()
{
local Package1 P;

ForEach AllActors(class'Package1', P )
	{
	P.static.SomeMethod(); // or simply just P.SomeMethod()
	}
}
Fraggers hangout place: http://fraggers.online/
User avatar
sektor2111
Godlike
Posts: 6413
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Referencing classes from another package?

Post by sektor2111 »

I think a package is not having functions - and I think is object not Actor, but classes have functions...
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Referencing classes from another package?

Post by 1337GameDev »

sektor2111 wrote: Tue Apr 05, 2022 3:48 pm I would try an "#exec obj load" directive for compiling...

Let me look at something as example and I'll be back...

EDIT: Let me show you something for previous explanation.

Code: Select all

class WarExplosion2 extends WarExplosion;

#exec OBJ LOAD FILE=textures\WLExplo.utx PACKAGE=BotPack.WarExplosionS2
In order to compile in BotPack said WarExplosion2, due to reference to a Texture, it was added an import directive in compiler. This directive loads a Texture file which was already created before, or else Texture would need to be created directly from a BMP/PCX source-file. Texture in this case was used for being as BotPack, but you can have as reference an external texture - only if it does exist or else code referencing Texture won't be generated.

Your stage is... two stages:
#1 Creating/Compiling Package1
#2 Creating Compiling Package2 with reference to Package1
#3 Attempting here to deal with "Class1" and look what fails if it fails

At least this is what I would do - my two cents.
I tried this, by loading a UAX I made for the mod in unrealeditor, and it doesn't seem to work.

It still just doesn't find the package at compile time....

Ideas? The mod (package1) is mainly a mutator, a sound package and a few classes.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Referencing classes from another package?

Post by Feralidragon »

If you use UMake to compile, you can simply declare all the dependencies in a make.ini file, like so:
https://github.com/Feralidragon/C21FX/b ... r/make.ini

Note that EditPackages lists all dependencies AND the package itself to be compiled.

If you use UCC directly, then you can do the same thing, but you need to do:

Code: Select all

ucc make ini=make.ini
This is the easiest way to accomplish that, and makes the code portable, in the sense that it will always use the right dependencies regardless of where and how it's compiled.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Referencing classes from another package?

Post by 1337GameDev »

Feralidragon wrote: Mon Apr 11, 2022 12:40 pm If you use UMake to compile, you can simply declare all the dependencies in a make.ini file, like so:
https://github.com/Feralidragon/C21FX/b ... r/make.ini

Note that EditPackages lists all dependencies AND the package itself to be compiled.

If you use UCC directly, then you can do the same thing, but you need to do:

Code: Select all

ucc make ini=make.ini
This is the easiest way to accomplish that, and makes the code portable, in the sense that it will always use the right dependencies regardless of where and how it's compiled.
When i specify the ucc ini, is this an absolute path, or relative to ucc.exe?

I generally run "ucc make" directly via a batch file.
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Referencing classes from another package?

Post by Feralidragon »

I almost always used UMake, so I am not quite sure.
Try both ways, one of them will likely work. :)
Deaod
Average
Posts: 37
Joined: Fri Jul 10, 2020 9:22 am

Re: Referencing classes from another package?

Post by Deaod »

I use an absolute path.

Also, make sure to use ucc make -ini=... and not ucc -ini=... make. The second doesnt work because of how UCC parses arguments.

And then theres the possibility of automatically generating the necessary make.ini, especially if youre already using a batch file. See here.
Post Reply