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.

UE3 - UT3 Checking Team Number

Discussion in 'Programming' started by inferyes, Jun 2, 2010.

  1. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    Brold9999 certainly has a point there: You need to make yourself familiar with object-oriented programming if you want to get anywhere with UnrealScript. It may be a little hard to find UnrealScript-specific OOP tutorials, but generic or Java-specific tutorials should do the job as well.

    Some UnrealWiki articles you might want to read:
    http://wiki.beyondunreal.com/Legacy:Getting_Started_In_UnrealScript
    http://wiki.beyondunreal.com/Legacy:UnrealScript_For_Non-Programmers

    Or the UnrealScript reference:
    http://udn.epicgames.com/Three/UnrealScriptReference.html

    Or articles about UnrealScript and OOP in general:
    http://www.google.com/search?q=unrealscript+oop
     
  2. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    I read through those UScript references. I understand how the language works, I just don't understand how to do certain things (and that's why I'm asking all these questions).
     
  3. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    After everything I've tried I can't solve this last problem. The only way I can switch a players team is by making a class that extends the UTTeamGame class but if I do that I can't get it to check variables in the UTPawn_Zombies class I made so I can't tell it when or who to switch the teams of.

    So how do I fix this? I just can't think of any way to do it.
     
  4. brold9999

    brold9999 New Member

    Joined:
    Apr 5, 2009
    Messages:
    142
    Likes Received:
    0
    You don't have to extend UTTeamGame to call it's functions. Except for private or protected functions (nothing you need is one of these) you can call any function from an instance of another class, as long as you have a reference to that class.

    http://wiki.beyondunreal.com/Legacy:Object_Oriented_Programming_Overview has some examples of how you can do that.

    Every instance subclassed from Actor (your Pawn is one) has a reference to the GameInfo (every UTTeamGame is one of these) with WorldInfo.Game.
     
  5. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    So your saying I can call things like this?

    WorldInfo.Game.Object.Actor.Info.GameInfo.UTGame.UTDeathmatch.UTTeamGame.SetTeam();
     
  6. brold9999

    brold9999 New Member

    Joined:
    Apr 5, 2009
    Messages:
    142
    Likes Received:
    0
    Please look at the links Wormbo and I have posted. You need to understand the basics of Unrealscript and object-oriented programming to complete your mod.
     
  7. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    I have read them. They don't explain calling functions from other classes. This is what I'm really stuck on right now.
     
  8. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    It might not be described on those pages, but with only one or two clicks you can reach other tutorial pages that have simple code examples where functions are called from somewhere else than the same instance.
     
  9. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    What's the technical term for what I'm trying to do then. I can just search that on the Wiki.
     
  10. brold9999

    brold9999 New Member

    Joined:
    Apr 5, 2009
    Messages:
    142
    Likes Received:
    0
    I linked you directly to a page with an example of calling a Pizza object's Slice and EatParts functions from another class.
     
  11. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    In that example it only calls functions that are in the script it's extended to. I know how to do that. What I'm trying to do is call functions from 2 scripts that are not extended to the same parent class.
     
  12. brold9999

    brold9999 New Member

    Joined:
    Apr 5, 2009
    Messages:
    142
    Likes Received:
    0
    I see no evidence of that. The code snippet with MyPizza.Slice(8); gives no indication of where it is being called from. You can do that from anywhere that you have a Pizza variable named MyPizza.
     
  13. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    Everything is within 2 classes.

    class Pizza extends Meal
    class BetterPizza extends Pizza

    That's my understanding of that tutorial.
     
  14. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    After looking through the source for UTPawn a bit more I stumbled upoun a usage of the call I was trying to do and I figured out how the syntax works.

    UTTeamGame(WorldInfo.Game).ChangeTeam(Controller, 1, true);

    Works fine too.

    :D
     
  15. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,702
    Likes Received:
    4
    Just so you know, that's called typecasting. Here you're taking an Object of one type and casting it to a subclass type to access the additional functions that are contained in a UTTeamGame. Typecasting will only be succesful if the class types are compatible (i.e: one is a subclass of another).

    In OOP that would be calling a function/method on an Object reference. In other words, you need to obtain a reference to an existing Object to call a function to which it belongs.
     
  16. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    I've gotten almost everything working now. All that's left to do is correct the team victory thing (which I think I know how to fix already) and fix the inventory problem.

    I wrote this out but I can't figure out what to cast the UTWeapon from.

    UTInventoryManager(InvManager).AddInventory(UTWeapon(???Something???).Weap_ImpactHammer);

    If I use InvManager in the place of the bolded text it says cast from inventory manager to UTWeapon will always fail. I'm guessing I need to cast from something else but I don't know what or how to determine what.

    edit-

    Also I modified my Mutator and changed it into it's own gametype. It's extends UTTeamGame and I set it up to over ride some of the team switching and scoring functions. So far it works perfectly.

    edit 2-
    I made a lot of progress on this tonight. Once I fix the weapon problem I listed above I will be completely done with mutator functionality and all that will be left is testing (which I have done a lot of already) and cosmetic changes.
     
    Last edited: Jun 9, 2010
  17. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    I still can't find a good way to add weapons to a players inventory. The 2 ways that SHOULD work are:

    UTInventoryManager(InvManager).AddInventory(UTWeapon(Inventory).Weap_Enforcer);

    and

    Weapon(Inventory)UTWeap_Enforcer.GiveTo(self);


    The first one returns that I have a type mistmatch in UTWeap_Enforcer. The wiki said to use :

    class<UTWeapon> WeaponClass

    But that's obviously wrong.

    The second one tells me it can't find the UTWeap_Enforcer class all together. Which is doesn't make any sense.
     
  18. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    Syntax basics: The "." means "access". Let me translate the lines you wrote, maybe the Problem becomes obvious then.

    "UTInventoryManager(InvManager).AddInventory(UTWeapon(Inventory).Weap_Enforcer);"
    Treat the content of the InvManager variable as a UTInventoryManager, access its AddInventory method and execute it. For parameter 1, treat the content of the Inventory variable as a UTWeapon and access its Weap_Enforcer variable.

    "Weapon(Inventory).UTWeap_Enforcer.GiveTo(self);" (I'm assuming you just forgot the "." there because it doesn't make sense without.)
    Treat the content of the Inventory variable as a Weapon, access its UTWeap_Enforcer variable. On that, access the GiveTo function and execute it with the parameter Self, i.e. the object executing this script.
     
  19. inferyes

    inferyes Spaced In

    Joined:
    Aug 16, 2009
    Messages:
    504
    Likes Received:
    0
    I think the problem with the first line is simply a incorrect type in AddInventory() since it does not specify how to define what you are trying to add.

    I don't know what is wrong with the second line.

    Although this part of my custom gametype is still having issues, I have made huge improvements to the scoring and post game elements. I even worked out Post-Round team balancing. I also did some online tests with my freinds and they said the gametype was pretty damn fun.
     
  20. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    Hint 1:
    AddInventory() is defined in the InventoryManager class already, so no need top typecast InvManager to UTInventoryManager.

    Hint 2:
    The UTWeapon class neither has a variable called "Weap_Enforcer" nor a variable called "UTWeap_Enforcer".
     

Share This Page