1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.

typecasting ;(

Discussion in 'Programming' started by Dark[NSF], Oct 5, 2003.

  1. Dark[NSF]

    Dark[NSF] Northwest Secessionalist Forces

    Joined:
    Mar 12, 2003
    Messages:
    632
    Likes Received:
    0
    How would I get my custom PlayerController class from Pawn?


    Pawn.Controller(nsfplayer).blah blah?

    Controller(nsfplayer.pawn).blah blah?

    I'm lost, I would love some help :)
     
  2. JamesKilton

    JamesKilton UA Coder

    Joined:
    Oct 6, 2002
    Messages:
    210
    Likes Received:
    0
    You've got it flipped. it's:

    nsfplayer(Pawn.Controller).foo;

    nsfplayer(Controller).foo;

    etc.
     
  3. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,915
    Likes Received:
    36
    Typecasting always works like this:

    ClassToTypecastTo(ObjectToTypecast).PropertyToAccess

    or

    ClassToTypecastTo(ThingToGetObjectFrom.ObjectToTypecast).PropertyToAccess
     
  4. clam

    clam New Member

    Joined:
    Jul 24, 2003
    Messages:
    47
    Likes Received:
    0
    Wormbo that's the best explanation of typecasting ever
     
  5. Evil-Devil

    Evil-Devil silence

    Joined:
    Jun 17, 2002
    Messages:
    74
    Likes Received:
    0
    Just need some little explanation.
    I got two classes. One is SC_Crystal and the other SC_Blue_Crystal. The blue crystal one is a subclass of crystal. and two references. one called just crystal, and the other blue_crystal.
    no i take a for loop through the navigiationpointlist and check if there is one of my crystals or blue ones

    Code:
    [...]
    // NP is the reference to NavigationPoint
    // if...found crystal -> works
    Crystal = SC_Crystall(NP);
    
    // if...found blue crystal --> works
    Blue_Crystal = SC_Blue_Crystal(NP);
    
    // if found blue crystal (another bsp) -> wont works
    Blue_Crystal = SC_Crystal(NP);
    [...]
    
    Can i only cast objects which belongs to their reference? cause the third cast doesn´t work as shown in the comment.

    Just want to know why.

    Evil
     
  6. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,915
    Likes Received:
    36
    The cast itself works well, the compiler moans about a different problem: You can only assign objects of the same class or a sbuclass to a variable.
    Your Crystal variable can hold any SC_Crystal and any subclass of it, like SC_Blue_Crystal, but you can't assign an SC_Crystal to the Blue_Crystal variable because it's not a subclass of SC_Blue_Crystal.
     
  7. Evil-Devil

    Evil-Devil silence

    Joined:
    Jun 17, 2002
    Messages:
    74
    Likes Received:
    0
    ok, thats clear to me. but in the first tries i also tried to set Crystal = SC_Blue_Crystal(NP) and it even gives me an access none. weird, isn´t it?
     
  8. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,915
    Likes Received:
    36
    That statement can't give any Accessed Nones directly, only if NP isn't an SC_Blue_Crystal. If NP is an SC_Crystal (i.e. not an SC_Blue_Crystal) the typecasting result is None, which gets assigned to Crystal.
     
  9. Evil-Devil

    Evil-Devil silence

    Joined:
    Jun 17, 2002
    Messages:
    74
    Likes Received:
    0
    Hmm, k. And thx for explenation.
     

Share This Page