View Full Version : call function from other classes
hi all,
i have a problem i get errors if i try to call function from other classes,
I'll give you a quick overview about my aim. Is very simple i created a trigger
as a checkpoint and if i touch it a variable from another class should be set.
now my code:
class Trigger_CP1 extends Trigger;
event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
{
local MyGameInfo GameInstance;
GameInstance = MyGameInfo(Other);
GameInstance.SetCeckPoint1(true);
}
defaultproperties
{
}
class MyGameInfo extends UTDeathmatch;
var bool bCeckPoint1;
simulated function SetCeckPoint1(bool bState)
{
bCeckPoint1 = bState;
}
defaultproperties
{
bCeckPoint1 = false
Acronym="My"
PlayerControllerClass=class'UTGame.MyPlayerControl ler'
HUDType=class'UTGame.MyHUD'
bUseClassicHUD = true
name="Default__MyGameInfo"
}
and the error message is: ...\Trigger_CP1.uc<5> : Error, Unrecognized type 'MyGameInfo'
so how can i fix this ?
Blade[UG]
07-25-2011, 08:09 AM
Don't ever set "Name" in DefaultProperties, don't ever add classes to one of the existing packages (unless you really know what you're doing and why you're doing it), and the Actor called by "Other" that is passed into the Touch event is a reference to the Actor that caused the Touch - there's no possible way that a GameInfo could ever touch anything.
Your actual error is apparently caused because Trigger_CP1 is in a package that is compiled before MyGameInfo, but logically, there is no way that your code can work.
indygoof
07-25-2011, 08:14 AM
Uhm,
Your GameInfo will never touch the trigger. Actors can Touch.
So, in your Trigger-Class, you will actually want to check if "Other" is a GamePawn, or better, your PlayerPawn (whatever class this would be).
I dont know from my mind how you get the GameInfo, but that should be easy enough to find out.
Regarding the compile Problem, try to fix the code first, and see if the Error still occurs.
EDIT: Ok, Blade was faster and with a more complete posting, so ignore mine :)
Wizzard~Of~Ozz
07-25-2011, 09:47 AM
I dont know from my mind how you get the GameInfo, but that should be easy enough to find out.
WorldInfo.Game for any Actor based class, class'WorldInfo'.static.GetWorldInfo().Game for others. However this is only available to the Server as Game does not exist on Clients.
ok thanks at first I try to bring it to work now;)
Edit:
did i understand it right that i should extend the pawn and add my funktions in there ?
Bob_Gneu
07-25-2011, 10:47 AM
You look at what Pawn, UDKPawn and the other Pawns offer and extend them as you see fit. You should always be building off where you can.
I've not proof read it, but this tutorial is on a site run by friends of mine.
http://udkc.info/index.php?title=Getting_Started
hi again,
i changed my scripts now. I put my funktion in an extention of pawn and tried
to bring it to work but i still get some errors ,may someone can help
My current scripts
class MyPawn extends Pawn;
var bool bCeckPoint1;
simulated function SetCeckPoint1(bool bState)
{
bCeckPoint1 = bState;
`log("Touched CP1");
}
defaultproperties
{
bCeckPoint1 = false
}
class Trigger_CP1 extends Trigger;
event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
{
local MyPawn P;
P = MyPawn(WorldInfo.Game);
P.SetCeckPoint1(true);
}
defaultproperties
{
}
and the error : ...\Trigger_CP1.uc<6> : Error, Cast from 'GameInfo' to 'MyPawn' will always fail
Bob_Gneu
07-25-2011, 02:46 PM
You cannot cast a class to a class that it does not derive from. You should probably read some object oriented programming primers and the unreal script reference.
In fact, this guide may be of use: http://udn.epicgames.com/Three/MasteringUnrealScriptBaptismByFire.html
Wizzard~Of~Ozz
07-25-2011, 03:53 PM
class Trigger_CP1 extends Trigger;
event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
{
// P = MyPawn(WorldInfo.Game); // Of course this will fail, GameInfo is not a Parent of Pawn.
// You took two methods of correcting it and applied both at the same time ( flipping your result )
if( MyPawn( Other ) != None )
MyPawn( Other ).SetCeckPoint1(true);
// Alternatively, using your original approach
if( MyGameInfo( WorldInfo.Game ) != None )
MyGameInfo( WorldInfo.Game ).SetCeckPoint1( True );
}
defaultproperties
{
}
ok thanks all think i understand most of it now
hi it's me again,
i have only one question more how can i call a funktion in a class extends fromUTHUDBase from my pawn ?
Wizzard~Of~Ozz
07-26-2011, 06:42 PM
UTHUDBase( PlayerController( Controller ).MyHud );
mmmmh thanks but i dont bring it to work
Error:
...\MyPawn.uc<18> Error, Unrecognized type 'UTHUDBase'
Blade[UG]
07-27-2011, 09:46 PM
you need to have your package -under- the UTGame package in the EditPackages list
unrealscript is the most confusing programminglanguage ive learned so far:rolleyes:
Bob_Gneu
07-28-2011, 10:57 AM
That is unfortunate. Most of this has not been because of difficulties in the language, instead it comes from the initial setup which has been explained in pretty gross detail in the tutorials I've linked you. This setup stuff is not nearly as confusing as accomplishing any of the real goals for your game within the UDK. It gets much easier once you get moving. You just need to keep your head screwed on and life gets easier.
Wormbo
07-28-2011, 11:39 AM
unrealscript is the most confusing programminglanguage ive learned so far:rolleyes:
What other languages have you learned so far? Maybe we can give you a more specific jump start based on your previous knowledge.
c++ ,AutoIt and the basics of Assembler
Bob_Gneu
07-28-2011, 12:20 PM
UnrealScript doesn't hold a candle to the complication of doing anything novel in Assembler. It has common features to the OO concepts used in C++ and Java though.
Wormbo
07-28-2011, 12:28 PM
You didn't actually use C++ the way it was intended to, otherwise you'd be used to the way you access stuff for mother classes in general. I suspect you used more of the C aspect that was left in C++.
AutoIt looks like it's very BASIC-like and quite non-OOP. Assembler languages are strictly non-OOP and generally very low-level. They are good for understanding underlying workings in other languages, but unfortunately that knowledge doesn't help you at all in UnrealScript because it's too high-level, being compiled into an interpreted bytecode representation.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.