New Keyword And Objects

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

New Keyword And Objects

Post by 1337GameDev »

I am making some data structures and other classes to use in code i write. I extend object, with a basic class.

How use the 'new' keyword used?

I have the below example code:

Code: Select all

class Class1 extends Object;

var Object Value;

function Funct1() {
      
}
I tried using this to instantiate it:

Code: Select all

local Class1 c1;
c1 = new Class1();
and UCC seems to complain and not like this.

How is this done?

And, if i want to have a GENERIC parameter to a function / field of this class, how is that done? I have done generics extensively in a dozen or so languages, but don't see how to do that in UnrealScript.
ShaiHulud
Adept
Posts: 459
Joined: Sat Dec 22, 2012 6:37 am

Re: New Keyword And Objects

Post by ShaiHulud »

I use this syntax:

Code: Select all

local Class1 c1;

c1 = new class'Class1';
Though the relevant wiki page suggests potential alternative formats. One issue I rubbed up against in choosing to inherit from Object rather than, say, Actor, is that you won't have access to other useful objects like Level - though you can pass these in as parameters to functions.
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: New Keyword And Objects

Post by sektor2111 »

By any matter if Wiki goes down-hill (as it often does) you might look at TestInfo class from Engine - probably there are conclusive samples about some of their testing goals.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: New Keyword And Objects

Post by 1337GameDev »

ShaiHulud wrote: Tue Nov 03, 2020 7:49 am I use this syntax:

Code: Select all

local Class1 c1;

c1 = new class'Class1';
Though the relevant wiki page suggests potential alternative formats. One issue I rubbed up against in choosing to inherit from Object rather than, say, Actor, is that you won't have access to other useful objects like Level - though you can pass these in as parameters to functions.
Doh!

I'm so used to other languages that class references like this trip me up.

Makes perfect sense.

How do I specify a constructor? Our do I basically don't and just populate after?

Also, I see no mention of generics in the Wiki, so I'm assuming I'll have to do the naive approach and make basic wrappers for primitive types.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: New Keyword And Objects

Post by 1337GameDev »

sektor2111 wrote: Tue Nov 03, 2020 4:39 pm By any matter if Wiki goes down-hill (as it often does) you might look at TestInfo class from Engine - probably there are conclusive samples about some of their testing goals.
I'll give that class a look. I didn't see that when I was grepping the source code and uc classes.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: New Keyword And Objects

Post by 1337GameDev »

Any way to hand generics in an object? Or does unrealscript not support that?
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: New Keyword And Objects

Post by Feralidragon »

No, it doesn't.
UnrealScript is very old and quite primitive in many ways, even in relation to the existing languages at the time.

While it improved over time with each engine generation (up until UE3, since it was dropped completely starting with UE4), and while it's meant to be an OOP language, the UE1 version lacks many fundamental features such as protected properties (it has private though, albeit rarely used in practice), protected and private methods, interfaces, constructors and destructors (as you've seen), and so on.

Even something like dynamic arrays are broken in v436 at least, and only fixed-length arrays work properly.

Furthermore you have to be careful when handling objects, since the GC of this version of the engine is not that great.
It was severely improved in the latest patches (v469+), but you still have to be careful, especially if you have references between normal objects and Actor objects, otherwise you may end up getting GC crashes (mostly on map change, when GC runs).

That is to say that, if you use v469, then you're somewhat safe, but there are still some considerations to have, although in this part is best to ask the patch developers themselves, they know a lot better what situations you still have to be careful about.
Post Reply