• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Coding a button to do something..

otester

Grizzled Veteran
Mar 7, 2006
366
5
Currently trying to code a laser range finder but the player will need to press a button to trigger the code to find the range, set elevation (if needed) etc.

Code:
For example I want the button to trigger code like this:

if( LRFRange != RangeValue )
    HandleFCS();

Any ideas?

Thanks,

otester.
 
Last edited:

Ok I had a look and put some of the code together to test (although not finished):

Code:
function Initialize()
{
    Log("Interaction Initialized");
}

function bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
{
    if (Action == IST_Press)
        ViewportOwner.Actor.ClientMessage("Key PRESSED:" @ Key);
    if (Action == IST_Release)
        ViewportOwner.Actor.ClientMessage("Key RELEASED:" @ Key);
    if (Action == IST_Hold)
        ViewportOwner.Actor.ClientMessage("Key HELD:" @ Key);
    if (Action == IST_Axis)
        ViewportOwner.Actor.ClientMessage("Key AXIS:" @ Key);

    return false;
}
And got this error:

C:\Program Files\Steam\steamapps\common\red orchestra\PantherII\Classes\PantherI
ICannon.uc(15) : Error, Unrecognized type 'EInputKey'
Compile aborted due to errors.
Failure - 1 error(s), 0 warning(s)

C:\Program Files\Steam\steamapps\common\red orchestra\System>PAUSE
Press any key to continue . . .

I know this wiki is really aimed at UT2003/4 so would it be something else for RO or ?
 
Upvote 0

I got a problem which is something to do with Begin, here:

Code:

Code:
class PantherIIButton extends Interaction;
 
var bool bHasInteraction
 
Begin:
    If ((Viewport(Player) != None) && (!bHasInteraction))
        {
        Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player);
        bHasInteraction = True;
        }
 
simulated function PostBeginPlay()
{
      Super.PostBeginPlay();
      PlayerOwner.Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", PlayerOwner.Player);
}
 
function Initialize()
{
    Log("Interaction Initialized");
}
 
function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{
    if ((Action == IST_Press) && (Key == IK_F)) // if F is pressed
        Log("you pressed F");
    if ((Action == IST_Release) && (Key == IK_F))
        Log("you let go");
    return false;
}
 
DefaultProperties
{
     bActive=True
}


Error on build:

Code:
C:\Documents and Settings\Oliver Tester\Desktop>cd C:\Program Files\Steam\SteamA
pps\common\red orchestra\System
C:\Program Files\Steam\steamapps\common\red orchestra\System>ucc.exe make
----------------------------Core - Release----------------------------
---------------------------Engine - Release---------------------------
----------------------------Fire - Release----------------------------
---------------------------Editor - Release---------------------------
--------------------------UnrealEd - Release--------------------------
---------------------------IpDrv - Release----------------------------
----------------------------UWeb - Release----------------------------
--------------------------GamePlay - Release--------------------------
-------------------------UnrealGame - Release-------------------------
---------------------------XGame - Release----------------------------
-------------------------XInterface - Release-------------------------
---------------------------XAdmin - Release---------------------------
-------------------------XWebAdmin - Release--------------------------
---------------------------GUI2K4 - Release---------------------------
--------------------------xVoting - Release---------------------------
--------------------------UTV2004c - Release--------------------------
--------------------------UTV2004s - Release--------------------------
-------------------------ROEffects - Release--------------------------
--------------------------ROEngine - Release--------------------------
---------------------------ROGame - Release---------------------------
---------------------------ROAmmo - Release---------------------------
------------------------ROInventory - Release-------------------------
------------------------ROInterface - Release-------------------------
--------------------------RORoles - Release---------------------------
-------------------------ROVehicles - Release-------------------------
-------------------------PantherII - Release--------------------------
Analyzing...
Parsing PantherIIButton
C:\Program Files\Steam\steamapps\common\red orchestra\PantherII\Classes\PantherI
IButton.uc(5) : Error, Missing ';' before 'Begin'
Compile aborted due to errors.
Failure - 1 error(s), 0 warning(s)
C:\Program Files\Steam\steamapps\common\red orchestra\System>PAUSE
Press any key to continue . . .
 
Last edited:
Upvote 0
Played around with it a bit more and got this, I have no idea how the expression is wrong?

Code:
class PantherIIButton extends Interaction;

var bool bHasInteraction;

function Interaction()
{
Begin:
    if ((Viewport(Player) != None) && (!bHasInteraction))
        {
        Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player);
        bHasInteraction = True;
        }
}

[COLOR=Silver]/*
function EnterStartState()
{
    Super.EnterStartState();
    if ((Viewport(Player) != None) && (!bHasInteraction))
    {
        Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player);
        bHasInteraction = True;
    }
}
*/

/*
Begin:
    If ((Viewport(Player) != None) && (!bHasInteraction))
        {
        Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", Player);
        bHasInteraction = True;
        }

simulated function PostBeginPlay()
{
      Super.PostBeginPlay();
      PlayerOwner.Player.InteractionMaster.AddInteraction("MyMod.MyInteraction", PlayerOwner.Player);
}
*/
[/COLOR]

function Initialize()
{
    Log("Interaction Initialized");
}


function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{
    if ((Action == IST_Press) && (Key == IK_F)) // if F is pressed
        Log("you pressed F");
    if ((Action == IST_Release) && (Key == IK_F))
        Log("you let go");

    return false;
}

DefaultProperties
{
     bActive=True
}

But the error (line highlighted above where error was found):

Code:
C:\Documents and Settings\Oliver Tester\Desktop>cd C:\Program Files\Steam\SteamA
pps\common\red orchestra\System

C:\Program Files\Steam\steamapps\common\red orchestra\System>ucc.exe make
----------------------------Core - Release----------------------------
---------------------------Engine - Release---------------------------
----------------------------Fire - Release----------------------------
---------------------------Editor - Release---------------------------
--------------------------UnrealEd - Release--------------------------
---------------------------IpDrv - Release----------------------------
----------------------------UWeb - Release----------------------------
--------------------------GamePlay - Release--------------------------
-------------------------UnrealGame - Release-------------------------
---------------------------XGame - Release----------------------------
-------------------------XInterface - Release-------------------------
---------------------------XAdmin - Release---------------------------
-------------------------XWebAdmin - Release--------------------------
---------------------------GUI2K4 - Release---------------------------
--------------------------xVoting - Release---------------------------
--------------------------UTV2004c - Release--------------------------
--------------------------UTV2004s - Release--------------------------
-------------------------ROEffects - Release--------------------------
--------------------------ROEngine - Release--------------------------
---------------------------ROGame - Release---------------------------
---------------------------ROAmmo - Release---------------------------
------------------------ROInventory - Release-------------------------
------------------------ROInterface - Release-------------------------
--------------------------RORoles - Release---------------------------
-------------------------ROVehicles - Release-------------------------
-------------------------PantherII - Release--------------------------
Analyzing...
Parsing PantherIIButton
Parsing PantherIITank
Parsing PantherIITank_Snow
Parsing PantherIITank_Striped
Parsing PantherIICannonPawn
Parsing PantherIICannonPawn_Snow
Parsing PantherIICannonPawn_Striped
Parsing PantherIIMountedMGPawn
Parsing PantherIIMountedMGPawn_Snow
Parsing PantherIIMountedMGPawn_Striped
Parsing PantherIITankFactory_Snow
Parsing PantherIITankFactory_Striped
Parsing PantherIICannonShellHE
Parsing PantherIICannonShell
Parsing PantherIICannon
Parsing PantherIICannon_Snow
Parsing PantherIICannon_Striped
Parsing PantherIIMountedMG
Parsing PantherIIMountedMG_Snow
Parsing PantherIIMountedMG_Striped
Parsing PantherIIDriverOverlay
Compiling PantherIIButton
C:\Program Files\Steam\steamapps\common\red orchestra\PantherII\Classes\PantherI
IButton.uc(8) : Error, Bad or missing expression in parenthesis
Compile aborted due to errors.
Failure - 1 error(s), 0 warning(s)

C:\Program Files\Steam\steamapps\common\red orchestra\System>PAUSE
Press any key to continue . . .
 
Upvote 0
I hope you resolve this to the state of ready and working mod (but what are you doing ?? laser rangefinder in a Panther ??) and then you let to take me a look, because I would like some new keys too in AB (like start/stop engine, maybe change gears, some new gunsight options ect, some new secret funtion ;) ...) but lately never had enough time/patience to learn from the begining how key interactions work in Unreal... ;)


P.S. Anyway, I see few problems in it. First you tried to make AddInteraction within PostBeginPlay (although it was said to not do it) and in your button class instead of playercontroller class (so hmm an ROPlayer ?). Maybe it has to be added by mutator...
Third problem with Begin was that it should be put into correct place inside "state PlayerWaiting" (not sure if state can be extended in subclasses ?) in PlayerController class (or it's subclasss?) and not just written without context (and not in your button class anyway).

As I'm not sure how to modify RoPlayer class (I thought for a moment that ROTankCannonPawn is subclass of it, but not) then the only way to put this interaxction into the game would be by mutator - I think (I can be wrong of course). So totally different way.

Maybe remove AddInteraction part from your button (this one for sure) and put it into your mutator (if you have one).

Are my comments making any sense ?? Worluk ?

edit: I see that states can be extended... but not from subclasses ? So better get rid of this and make AddInteraction by mutator I believe ? We don't have acces to ROPlayer or PlayerController anyway from tank/CannonPawn classes. But I'm not too happy that I need the mutator to get the additional key interactions working, I would prefer to get this from inside the vehicle/base vehicle code to be mutator - independent... Well you can't have everything I guess...
 
Last edited:
Upvote 0
imo interactions should only be used if you know what you do and if you really need them. For example to add extra functionality you dont need an extra button. There are several functions in tanks which are not used and which can be overwritten.

I had to create an additional interaction for mortar stuff, but thats another story. The problem with the posted code is, sorry to say, that the basic syntax is not correct. You are trying to either overwrite functions that are not there or creating new Interaction functions.

Also, more than only a few of the posted links show exactly how it is done. Just copying stuff from there without knowing what it does wont lead anywhere. The initialize function should be in a controller subclass which you can modify. Unless this is for DH it' unlikely, and you should go the mutator way.

PS: dont bother with engine switch ;)
 
Upvote 0
So it's an "academic" discussion (about interactions) I guess ;).
The problem with buttons is that they are available (unused) but in wrong places ;). But if you advice not use interactions, I will probably drop this idea and use what is available. And I do not like the code to be dependant on the mutator to enable interactions...
As for engine on/off, well I can wait with that and see what happens, if you say so ;). It was far away in my "to do" pipeline anyway :)

Cheers
 
Upvote 0