Simulated functions and inheritance - what's going wrong here?

  • 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.

Vig

New Member
Aug 21, 2001
6
0
0
Visit site
Ok, I've been learning UScript for a few days now, and today I ran into a problem I didn't understand. Just for fun and practice, I was making a tweeked version of the Ripper which would shoot a subclass of Razor2 (the normal projectile for the ripper) that would bounce 30 times instead of 7. I called the new projectile SuperBlade and made it a subclass of Razor2, and I made the SuperBlade Launcher a subclass of Ripper and only changed its ProjectileClass to MyMod.Superblade. What I did in SuperBlade was overload the HitWall( ) function and change the number of wall bounces it did before calling Destroy( ) to 30 instead of 6. When I tried to compile it, it gave me an error and said that the function SetRoll( ), called at the end of HitWall( ), wasn't defined (even though it should have been inherited from Razor2). So I cut and pasted the SetRoll( ) function from Razor2 into SuperBlade and tried again, and this time it compiled. I found that I could tweak the damage and speed in the default properties for SuperBlade, but for some reason it wouldn't acknowledge any changes to HitWall( ) and still vanished after bouncing 7 times. Finally I used the method from the tutorials on WoD and just copied and pasted the entire code from Razor2 into a new class, changed the code there to make it bounce 30 times, and made SuperBlade a subclass of Projectile and it worked. My question is, why didn't making SuperBlade a subclass of Razor2 work? Both HitWall( ) and SetRoll( ) I noticed are simulated functions.. can simulated functions not be overridden in a subclass of the class where they're defined? Can simulated functions not be inherited at all? Thanks in advance to anyone who replies.
 

Smoke39

whatever
Jun 2, 2001
1,793
0
0
Did you copy and modify the entire Flying auto state, or just put the functions in by themselves? You gotta keep 'em in auto state Flying.
 

Vig

New Member
Aug 21, 2001
6
0
0
Visit site
AHH! I noticed that the entire block of code was a tab over too far to the right, and it never even occured to me to check why, lol. Complete brain fart on my behalf. That explains why it wasn't working then, duh. If I were to go back and do it the original way, with the SuperBlade projectile as a subclass of Razor2, would I have to copy the entire block of code inside state Flying into SuperBlade just to modify that one integer inside that one function? Or could I just do this:

auto state Flying
{
simulated function HitWall(whatever)
{
blah blah blah etc
}
}

and leave out the rest of the state Flying functions from SuperBlade? Would they be inherited properly like this? Or would the compiler try to override everything in state Flying and tell me that the other functions weren't defined?
 

Smoke39

whatever
Jun 2, 2001
1,793
0
0
I think you have to copy all of it. That's what I always do, but I'm not sure.
 

Bytekeeper

Last of the Brunnen G
Jul 15, 2001
181
0
0
Germany
Visit site
You don't need to...
If you're inheriting a state all functions are getting inherited too. If you copy them all, you just overwrite them. The problem with your SetRoll(), vig, was that it was not called in the context of the auto state flying, but in the global state. So just overwriting Hitwall will do the job 8)
 

Smoke39

whatever
Jun 2, 2001
1,793
0
0
So he just has to overide that one function, but keep it within it's original state? Okay, I wasn't sure.