UE1 - UT Importing packages

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
Hi,

Is there an equivalent to Java's import directive (import java.util.* for example) that allows you to import packages and use the code in them ?

I'm asking this because I'd like to create some packages containing functions that can be reused.

Also, it seems that unrealscript doesn't handle packages well. What are the risks of referring to outside code and is there a way to avoid a missing package creating errors ?
 

Raven

Member
Jan 17, 2004
147
0
16
41
turniej.unreal.pl
I think you need to add package to EditPackages and then refer:

Code:
class'Package.Class'.static.function_name(parameters)

if you want to use static function.

You can create new object using directive new if class extends Object, or spawn actor and refer to it. I didn't try it but maybe there's a way to use #exec obj load to load package and use it.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
For code there's zero margin for error. Missing package? Your code won't load in the first place. Package exists but does not contain the expected code? Your code either just won't load or even crashes.

It's something you usually don't have to worry about, though. Package dependencies are implicitly taken account for in ServerPackages, so clients will download dependent packages automtically if only your package is in the ServerPackages list.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
It's something you usually don't have to worry about, though. Package dependencies are implicitly taken account for in ServerPackages, so clients will download dependent packages automtically if only your package is in the ServerPackages list.

The code in question is only needed by the server. That's why I'm asking the question.

@Raven: static calls should work (the static keyword might not be needed. I also seem to remember using #exec obj load for a mod that had trouble finding a package. This directive is probably only applied at compilation time though. As for creating new instances of an object, this suffers from the same problem if the object is defined in another package.

On the subject of objects, this might be of interest. It just needs a FILO stack added to contain unused instances.
http://forums.beyondunreal.com/showthread.php?t=182657
 
Last edited:

War_Master

Member
May 27, 2005
702
0
16
I just add an EditPackages of the mod I'm basing mine off. This way I skip the use of the #obj load if the package I'm subclassing of has a different name than mine. I only use #obj load when I have a texture package with the same package name that contains Fire/IceTextures so that they get saved inside the .u file instead.

An example of the one I'm working now which I do need to load first so my package finds its classes:

EditPackages=EnhancedItems
EditPackages=Q3aWeapons
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
*Bump*

I did some searching on directives (C/C++ uses this to include code) and came accross this :

http://wiki.beyondunreal.com/Legacy:Exec_Directive_(UT)#Import
Code:
#exec OBJ LOAD FILE="..\Textures\MyTextures.utx"
 
var Texture SomeTexture;
 
defaultproperties
{
    SomeTexture=Texture'MyTextures.SomeCoolTexture_A'
}

Which is what Raven suggested. I tested it and it works with U files too.

El_Muerte also hints that there's an #include directive too :
http://wiki.beyondunreal.com/Legacy:UCPP
Code:
#include files not processed 
    Files included via the UnrealEngine built-in #include macro are not processed for macros. Use #ucpp include filename to include preprocessor directives. It is possible to enable support for include directives, in this case the #include line is replaced with the actual file during rewriting. So the actual unrealscript compiler won't have to include it.
 
Last edited:

Raven

Member
Jan 17, 2004
147
0
16
41
turniej.unreal.pl
Yes, but it'll work only if you'll use UCPP as preprocessor.

Personally I see no sense in using #exec to load .u file - it's better to use EditPackages instead (for compilation only). Besides it won't give the same effect as #include in C++. To have this functionality you'd have to use custom preprocessor - UCPP or integrated with ucc UEngine Preprocessor Commandlet.
 
Last edited:

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
.U files should really be loaded via EditPackages as that will happen before importing the source files into the package that's currently being compiled. Directives are only processed in the parsing stage, i.e. after your new classes have already been created. Super classes must already exist before this point.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
Using #exec would do for utility functions, no ?

The objects aren't important and I'm just wondering if there's a way to import code at compile time instead of doing a copy-paste and adding to visible code. Just like #include does on MS Visual C++ 6.0.

Yes, but it'll work only if you'll use UCPP as preprocessor.

It would seem so. Which makes me ask why #include keeps getting mentionned :D (gah!) :

http://wiki.beyondunreal.com/Legacy:New_UnrealScript_In_UT3
No More #-Directives

There's no replacement for #exec directives, you have to use UnrealEd to import resources now.

The (admittedly, very infrequently used) #include directive has been replaced by the `include() preprocessor macro.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
#include is a compiler directive in UE1/2. However, it will mess up your line numbers, so using it will cause more confusion than it'll help. If you wan to avoid code duplication, you could just create utility class with static functions.