[solved] Syntax for assigning class<whatever>-variables

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Barbie »

I just want to add a solution for that case that you want to reference something that is not in your own class: get the package name by Outer.

Example:

Code: Select all

const InvulnerabilityClass = class'SBInvulnerabilityV0.SBInvulnerability';
...
// usual syntax: ReplaceWith(Other, "SBInvulnerabilityV0.SBInvulnerability");

// syntax using *InvulnerabilityClass*:
ReplaceWith(Other, String(InvulnerabilityClass.Outer.Name) $ "." $ String(InvulnerabilityClass.Name));
Using the constant value in the beginning of code has the advantage that you have to declare the name once and only once what is helpful for changes in the future.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: [solved] Syntax for assigning class<whatever>-variables

Post by sektor2111 »

I still don't understand this sudden affinity for constants for future modifications. What if we have configured a normal item value in ini and simply changing it without new codes ? What exactly won't work ? It's also define once in INI and it can be changed simply even between Levels even randomly server-tool if it needs. A constant won't be changed from outside it's causing a limitation. Why I'm supposed to have a limitation at one thing ?
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Barbie »

sektor2111 wrote:What if we have configured a normal item value in ini
These constant values I use are not intended to be changed by users, only by coders - a user rarely will define new sub classes but wants to change properties of certain classes.

If these definitions were moved to an INI file:
  • a sanity check has to be done additionally
  • you cannot rely on Item's properties
  • you need these wrenched syntax also to treat the cases "IsA(), Spawn(), Class(Other) == NewItem.Class, ..." if more than one of them occurs.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: [solved] Syntax for assigning class<whatever>-variables

Post by JackGriffin »

Barbie wrote: a sanity check has to be done additionally
No big deal.
Barbie wrote: you cannot rely on Item's properties
Huh?
Barbie wrote: you need these wrenched syntax also to treat the cases "IsA(), Spawn(), Class(Other) == NewItem.Class, ..." if more than one of them occurs.[/list]
I see your point but overwhelmingly you are doing this to benefit you. Very few (if any) coders will use this.
So long, and thanks for all the fish
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Wormbo »

Barbie wrote:I just want to add a solution for that case that you want to reference something that is not in your own class: get the package name by Outer.

Example:

Code: Select all

const InvulnerabilityClass = class'SBInvulnerabilityV0.SBInvulnerability';
...
// usual syntax: ReplaceWith(Other, "SBInvulnerabilityV0.SBInvulnerability");

// syntax using *InvulnerabilityClass*:
ReplaceWith(Other, String(InvulnerabilityClass.Outer.Name) $ "." $ String(InvulnerabilityClass.Name));
Using the constant value in the beginning of code has the advantage that you have to declare the name once and only once what is helpful for changes in the future.
Better:

Code: Select all

ReplaceWith(Other, String(InvulnerabilityClass));
User avatar
sektor2111
Godlike
Posts: 6410
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: [solved] Syntax for assigning class<whatever>-variables

Post by sektor2111 »

All right...
Now show me that awesome ReplaceWith and I'll tell ya what and how you are replacing items. Abusing complexity never fascinated me but... default ReplaceWith is limited like an amoeba, perhaps you have some present a la 2016 to show? Else I did not used that Outer and I'm not very interested in using it for the moment.

Aside for replacements
I prefer replacing with a defined item all the time for a simple reason: Items from mod package are returned True so this will prevent any infinite recursion replacement when you will use ISA or whatever type replacing item with a child class. The hint is: Item from mod-package won't be asked if ISA or ISA or ISA, it is accepted with no additional processing. That constant thing I'm not sure how much speeds up, a master top wrapper wisely added might be cute in exchange.
Barbie wrote:has the advantage that you have to declare the name once and only once what is helpful for changes in the future.
Yes and No. While coding using a smart Text Editor you can use FIND-REPLACE features which will change everything, in let me guess ... under a second. Else, if you do a re-edit of a mod, for sure you might want to look around it if something else needs fine tuned, not only recompiling based on a single change, for me does not worth an effort to a new compilation for changing one thing once.
Of course if you like to live complex it's up on you, I do prefer simple things making others to understand them easier rather than bugging them, several members of community will enjoy "stealing" from you and you can be proud by some contribution.
Last edited by sektor2111 on Thu Jan 28, 2016 6:33 pm, edited 2 times in total.
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Gustavo6046 »

The problem for me is that I want to know if a object instance is of the same class as the class depicted in a class variable.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Wormbo »

Gustavo6046 wrote:The problem for me is that I want to know if a object instance is of the same class as the class depicted in a class variable.

Code: Select all

if (ClassIsChildOf(YourObject.Class, ClassVariable)) {
  // there you go
}
Read the code and an API documentation of your choice. Do it again and again, every time you have a question. Most of the answers are in the Core.Object and Engine.Actor classes and they are used everywhere.
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: [solved] Syntax for assigning class<whatever>-variables

Post by Barbie »

Wormbo wrote:

Code: Select all

ReplaceWith(Other, String(InvulnerabilityClass));
Shorter and better to read - thanks. :tu:
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Post Reply