Code: Select all
Class ClassName : Actor
{
void SchismHeightClip
{
if (prevFloorclip != Floorclip)
Height = Height - (Floorclip - prevFloorclip);
prevFloorclip = Floorclip;
}
...
}
Moderator: GZDoom Developers
Code: Select all
Class ClassName : Actor
{
void SchismHeightClip
{
if (prevFloorclip != Floorclip)
Height = Height - (Floorclip - prevFloorclip);
prevFloorclip = Floorclip;
}
...
}
Code: Select all
class Blah // Inheriting from Actor isn't necessary.
{
static void LogActorHealth (Actor other)
{
if (other != null)
{
Console.Printf("%d", other.health);
}
}
}
class DemonY : Demon
{
States
{
Death:
// Logs its killer's health.
SARG A 0 { Blah.LogActorHealth(target); }
Goto Super::Death;
}
}
Code: Select all
Class SchLib : Actor
{
int prevFloorclip;
static void SchismHeightClip(Actor other)
{
if (other != null)
{
name OtherClassName = other.GetClassName();
let other2 = OtherClassName(other);
if (other2.prevFloorclip != other2.Floorclip)
other2.Height = other2.Height - (other2.Floorclip - other2.prevFloorclip);
other2.prevFloorclip = other2.Floorclip;
}
}
}
Code: Select all
Call to unknown function 'OtherClassName'
Code: Select all
Class<Actor> OtherClassName = other.GetClassName();
let other2 = OtherClassName(other);
if (other2.prevFloorclip != other2.Floorclip)
other2.Height = other2.Height - (other2.Floorclip - other2.prevFloorclip);
other2.prevFloorclip = other2.Floorclip;
Code: Select all
name OtherClassName = other.GetClassName();
let other2 = OtherClassName(other);
But how? From this topic viewtopic.php?f=122&t=68669 I got the impression that I can't. And indeed, if I try this:Cherno wrote:so you can just do away with other2 and access otehr directly.
Code: Select all
Class SchLib : Actor
{
static void SchismHeightClip(Actor other)
{
if (other)
{
if (other.prevFloorclip != other.Floorclip)
other.Height = other.Height - (other.Floorclip - other.prevFloorclip);
other.prevFloorclip = other.Floorclip;
}
}
}
Code: Select all
Unknown identifier 'prevFloorclip'
Then the whole idea loses its point. If I could inherit all the actors that need this function from one class, I would simply define this function in that class. One variable I can add to actors that inherit from different classes, but the code of the function I want to keep in one place, not in two or three different classes from which it is inherited by the actors that need it. Otherwise, if/when I decide to expand/change that function code I may change it in one class and forget about the other(s). It seems like a bad design to keep one code in more than one place._mental_ wrote:Either cast other to your base actor class (where prevFloorclip is defined), or change argument type to that class.
Code: Select all
struct HeightClip { // or "mixin class HeightClip"
double prevFloorclip;
void Tick (Actor mo) {
if(mo && mo.floorclip != prevFloorclip) {
// ...
}
}
}
class Whatever : Actor {
HeightClip height_clip; // or "mixin HeightClip"
// You can then set height_clip.prevFloorclip = floorclip and call height_clip.Tick(self) to use your function.
// If you use a mixin, you can skip writing height_clip. Rename Tick back to SchismHeightClip then haha.
}
Code: Select all
struct struct_data {int i;}
class monsta : actor
{
struct_data data_name;
//set data name somewhere
virtual void get_all_data(in out struct_data var)
{
if(data_name && var) {var.i = var.i;}
}
}
class player : playerpawn
{same as for monsta}