Results 1 to 8 of 8

Thread: UScript help.

  1. #1

    Default UScript help.

    Hi, people.

    Having a little trouble with some script I'm doing. I'm pretty much a newbie and have only done basic stuff - was hoping I could get some help here.

    I have a class with only 3 int variables in it, all at 0 by default. Extending from that is a class with a mesh as default (this class spawns from another class - specifically when another mesh is destroyed), and a touch function that adds 1 to one of the ints in the parent class. Now, when I touch it, a destroy function destroys it and the int goes up by 1.

    My problem is that if another one spawns, the int appears to reset. Is there a way to spawn more without resetting the int in the parent class? Essentially, in gameplay, the mesh class is a pickup. The intent is that the more of the pickup the player obtains, the more powerful their weapon gets. However, I can't increase the powerstage because everytime a new pickup spawns, the int resets. I figured I'd need to properly store the value in some way. I imagine I'm just being an idiot and not seeing the simple solution.

    I also have the problem of not fully knowing when and when not to use class specifiers like abstract here, though I've tried this script both with and without it.

    Parent class (PowerUp):

    Code:
    class PowerUp extends Actor
    	abstract;
    
    var int LaserPowerStage;
    var int RocketPowerStage;
    var int AcidPowerStage;
    
    DefaultProperties
    {
    	LaserPowerStage = 0
    	RocketPowerStage = 0
    	AcidPowerStage = 0
    }
    Extension class (PowerupLaser):

    Code:
    class PowerupLaser extends PowerUp;
    
    var EmitterSpawnable BoomEmitter;
    
    function PostBeginPlay()
    {
    	`log("POWERSTAGE IS:"$LaserPowerStage);
    }
    
    function Touch ( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
    {
    	local Pawn P;
    
    	P = Pawn(Other);
    
            if (P != none)
    	{
    		PlaySound(SoundCue'A_Pickups.Armor.Cue.A_Pickups_Armor_Respawn_Cue');
    		LaserPowerStage++;
    		Destroy();
    		spawnPickup();
    		`Log("POWERSTAGE IS:"$LaserPowerStage);
    	}
    }
    
    function spawnPickup()
    {
    	BoomEmitter = Spawn(class'EmitterSpawnable');
    	BoomEmitter.SetLocation(Location);
    	BoomEmitter.SetTemplate(ParticleSystem'CTF_Flag_IronGuard.Effects.P_CTF_Flag_IronGuard_Spawn_Blue',true);
    }
    
    DefaultProperties
    {
    	begin object class=StaticMeshComponent Name=StaticMeshComponent0
    		StaticMesh=StaticMesh'NEC_Lights.SM.Mesh.S_NEC_Lights_SM_WallLight01'
    		end object
    		CollisionComponent=StaticMeshComponent0
    		bCollideActors = true
    	DrawScale=0.6
    	Components.Add(StaticMeshComponent0)
    }
    Any help at all would be appreciated, thanks.

  2. #2
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    The problem is that PowerUp and PowerUpLaser are the same object, not separate entities. The property LaserPowerStage is within that object instance and is destroyed along with it. You need a common location to store these variables, such as your player controller class.

  3. #3
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    ...or use default.LaserPowerStage += 1;, but in this way all new spawned PowerUps after that will increase his LaserPowerStage too.
    Last edited by VendorX; 04-06-2012 at 03:58 PM.

  4. #4

    Default

    Thanks for the responses. Ah, I see. I wondered if that might be the issue. So, after storing the variables in my player controller class instead (in the default properties again, right?), I tried this:

    Code:
    class PowerupLaser extends Actor;
    
    var EmitterSpawnable BoomEmitter;
    var ShooterPlayerController SPC;
    
    function PostBeginPlay()
    {
    	`log("POWERSTAGE IS:"$SPC.LaserPowerStage);
    }
    
    function Touch ( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
    {
    	local Pawn P;
    
    	P = Pawn(Other);
    
            if (P != none)
    	{
    		PlaySound(SoundCue'A_Pickups.Armor.Cue.A_Pickups_Armor_Respawn_Cue');
    		SPC.LaserPowerStage++;
    		Destroy();
    		spawnPickup();
    		`Log("POWERSTAGE IS:"$SPC.LaserPowerStage);
    	}
    }
    
    function spawnPickup()
    {
    	BoomEmitter = Spawn(class'EmitterSpawnable');
    	BoomEmitter.SetLocation(Location);
    	BoomEmitter.SetTemplate(ParticleSystem'CTF_Flag_IronGuard.Effects.P_CTF_Flag_IronGuard_Spawn_Blue',true);
    }
    
    DefaultProperties
    {
    	begin object class=StaticMeshComponent Name=StaticMeshComponent0
    		StaticMesh=StaticMesh'NEC_Lights.SM.Mesh.S_NEC_Lights_SM_WallLight01'
    		end object
    		CollisionComponent=StaticMeshComponent0
    		bCollideActors = true
    	DrawScale=0.6
    	Components.Add(StaticMeshComponent0)
    }
    The int wouldn't increment, though. What am I still doing wrong?

  5. #5
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Quote Originally Posted by AmbulanceChaser View Post
    ...
    instead (in the default properties again, right?)
    Nope... Call like default.LaserPowerStage += 1 will store data in default properties of LaserPowerStage class not instance LaserPowerStage in the level.

    Anyway, you have declared ShooterPlayerController as SPC, but is not assigned...

  6. #6

    Default

    Could you show me what the code would look like with your fixes? I don't fully understand what you mean.

  7. #7
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Code:
    var ShooterPlayerController SPC;
    
    function PostBeginPlay()
    {
    	Super.PostBeginPlay();
    	SPC = ShooterPlayerController( GetALocalPlayerController());
    	`log("POWERSTAGE IS:"$SPC.LaserPowerStage);
    }

  8. #8

    Default

    Thanks a lot, man.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.