Help, int vs bool vs vs

Discussions about Coding and Scripting
Post Reply
Red_Fist
Godlike
Posts: 2166
Joined: Sun Oct 05, 2008 3:31 am

Help, int vs bool vs vs

Post by Red_Fist »

This is for Unreal2, however code is code.

I am just posting the code so you can read it rather than have me try and explain.
But I do know int is integer, bool is boolean or the other two here.

But how does that work with the mechanics of programing with reference to the actual things that happen considering Unreal actors, why a"float" "byte" "bool" "int", why are they different and how it applies to know what I need to do.

not sure how to apply the programing thinking, I do know that int would be for a solid set number and shoved it in, the others, why would I need it or how to think of why I would use them
I do know a $ string can be a word of text, or made a variable,

here is the code just so you can read it
This part
var() enum TPropType
{
TYPE_Bool,
TYPE_Float,
TYPE_Int,
TYPE_Byte,

I just need a scenario real game example , not necessarily the exact meaning but a scenario for an actor results.
like
"If a skaar, or light or mover" will make this or that happen.

Code: Select all

//=============================================================================
// PropertyFlipper.uc
// $Author: Mfox $
// $Date: 10/02/02 2:25p $
// $Revision: 12 $
//=============================================================================

//------------------------------------------------------------------------------
// Description:	Use this to modify any variable of any Actor at runtime via
//              a trigger.
//------------------------------------------------------------------------------
// Basic Instructions:
// 
// Set the Event to the object's Tag you wish to modify.
// 
// Note: Only the first object you link to will be affected.  If you need to 
// affect multiple objects, use multiple PropertyFlippers.
// Update: You can now link up to 16 objects safely.
// 
// There are three InitialStates that you can set:
// 
// + TriggerToggle
// + TriggerControl
// + TriggerTimed (note associated TriggerDuration)
// 
// These are self explanatory.
// 
// Under the PropertyFlipper section in the default properties, you will see 
// a bunch of variables.
// 
// + PropertyName - set this to the name of the variable you wish to modify 
//   (i.e. DrawScale).  Just type it in -- spelling counts.
// + PropertyType - set this to the type of property you are modifying 
//   (i.e. float, Texture, Sound, etc.)
// + XXXValue (FloatValue, TextureValue, SoundValue, etc) - set this to the 
//   value you wish your variable to be modified too.  These are basically for 
//   easy of use.  Rather than making you type in 
//   "Texture'Angreal.Effects.GreenExplosion'" you can simply select the texture 
//   in the texture browser, and then click USE in the variable box.
// 
// Notes:
// 
// If I didn't include the type of variable you want to modify (i.e. an enumeration 
// like Style), you can use StringValue to hack it into submission.  
// 
// Example:
// + Set PropertyName to Style.
// + Set PropertyType to TYPE_String.
// + Set StringValue to STY_Translucent.  
// 
// This will not work for constant variables like Physics and Location, however, 
// I have added a PropertyType for Physics, and I can add more for other constant 
// variables if you find you need to modify them.
// 
// This will not work for Static actors.  If you can't figure out why your 
// PropertyFlipper isn't working, make sure to check that the Actor you are trying 
// to modify isn't static.  Also make sure you didn't spell the PropertyName wrong.
//------------------------------------------------------------------------------

class PropertyFlipper extends KeyPoint;

#exec Texture Import File=Textures\PrpFlipper.pcx Name=S_PrpFlipper Mips=Off MASKED=1

var() enum TPropType
{
	TYPE_Bool,
	TYPE_Float,
	TYPE_Int,
	TYPE_Byte,
	TYPE_Vector,
	TYPE_Rotator,
	TYPE_String,
	TYPE_Texture,
	TYPE_Sound,
	TYPE_Physics,
	TYPE_Collision,	// No property name needed.
	TYPE_Color,
	TYPE_bCollideActors,
	TYPE_DrawType,
} PropertyType;

var() string PropertyName;

var() bool			BoolValue;
var() float			FloatValue;
var() int			IntValue;
var() byte			ByteValue;
var() vector		VectorValue;
var() rotator		RotatorValue;
var() string		StringValue;
var() Texture		TextureValue;
var() Sound			SoundValue;
var() EPhysics		PhysicsValue;
var() float			CollisionRadiusValue;	// No property name needed.
var() float			CollisionHeightValue;	// No property name needed.
var() color			ColorValue;
var() EDrawType		DrawTypeValue;

var string		OldPropertyText;
var EPhysics	OldPhysics;
var float		OldCollisionRadius;
var float		OldCollisionHeight;

var() float TriggerDuration;

var bool bOn;

var PropertyFlipper Flippers[16];


//------------------------------------------------------------------------------
simulated state() TriggerToggle
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		if( !bOn )	Set();
		else		Reset();

		bOn = !bOn;
	}
}

//------------------------------------------------------------------------------
simulated state() TriggerControl
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		Set();
	}

	simulated function UnTrigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		Reset();
	}
}

//------------------------------------------------------------------------------
simulated state() TriggerTimed
{
	simulated function Trigger( Actor Other, Pawn EventInstigator, optional name EventName )
	{
		Set();
		SetTimer( TriggerDuration, false );
	}

	simulated event Timer()
	{
		Reset();
	}
}

//------------------------------------------------------------------------------
simulated function Set()
{
	local Actor IterA;
	local int i;
	i = -1;

	if( Event != '' )
		foreach AllActors( class'Actor', IterA, Event )
			StaticSet( GetInstance(i++), IterA );
}

//------------------------------------------------------------------------------
simulated function Reset()
{
	local Actor IterA;
	local int i;
	i = -1;
	
	if( Event != '' )
		foreach AllActors( class'Actor', IterA, Event )
			StaticReset( GetInstance(i++), IterA );
}

//------------------------------------------------------------------------------

simulated static function StaticSet( PropertyFlipper P, Actor A )
{
	if( P == None || A == None )
		return;

	if( P.PropertyType != TYPE_Physics && 
		P.PropertyType != TYPE_Collision &&
		P.PropertyType != TYPE_bCollideActors &&
		P.PropertyType != TYPE_DrawType &&
		!A.CanSetProperty( P.PropertyName ) )
	{
		A.DMT( "Warning -- can't set property '" $ P.PropertyName $ "' (Type=" $ EnumStr( enum'TPropType', P.PropertyType ) $ ") for Actor " $ A $ " using property flipper " $ P );
		return;
	}
	
	P.OldPropertyText = A.GetPropertyText( P.PropertyName );

	switch( P.PropertyType )
	{
	case TYPE_Bool:
		A.SetPropertyText( P.PropertyName, string(P.BoolValue) );
		if( P.PropertyName == "bHidden" ){ A.StaticFilterState = FS_Maybe; }
		break;

	case TYPE_Float:
		A.SetPropertyText( P.PropertyName, string(P.FloatValue) );
		break;

	case TYPE_Int:
		A.SetPropertyText( P.PropertyName, string(P.IntValue) );
		break;

	case TYPE_Byte:
		A.SetPropertyText( P.PropertyName, string(P.ByteValue) );
		break;

	case TYPE_Vector:
		A.SetPropertyText( P.PropertyName, string(P.VectorValue) );
		break;

	case TYPE_Rotator:
		A.SetPropertyText( P.PropertyName, string(P.RotatorValue) );
		break;

	case TYPE_String:
		A.SetPropertyText( P.PropertyName, P.StringValue );
		break;

	case TYPE_Texture:
		A.SetPropertyText( P.PropertyName, string(P.TextureValue) );
		break;

	case TYPE_Sound:
		A.SetPropertyText( P.PropertyName, string(P.SoundValue) );
		break;

	case TYPE_Physics:
		P.OldPhysics = A.Physics;
		A.SetPhysics( P.PhysicsValue );
		break;

	case TYPE_Collision:
		P.OldCollisionRadius = A.CollisionRadius;
		P.OldCollisionHeight = A.CollisionHeight;
		A.SetCollisionSize( P.CollisionRadiusValue, P.CollisionHeightValue );
		break;

	case TYPE_Color:
		A.SetPropertyText( P.PropertyName, "(R="$P.ColorValue.R$",G="$P.ColorValue.G$",B="$P.ColorValue.B$")" );
		break;

	case TYPE_bCollideActors:
		A.SetCollision( P.BoolValue );
		break;

	case TYPE_DrawType:
		A.SetDrawType( P.DrawTypeValue );
		break;
		
	default:
		A.DMT( "Warning -- unhandled PropertyType" );
		break;
	}
}

//------------------------------------------------------------------------------
simulated static function StaticReset( PropertyFlipper P, Actor A )
{
	if( P == None || A == None )
		return;

	if( P.PropertyType == TYPE_Physics )
	{
		A.SetPhysics( P.OldPhysics );
	}
	else if( P.PropertyType == TYPE_Collision )
	{
		A.SetCollisionSize( P.OldCollisionRadius, P.OldCollisionHeight );
	}
	else
	{
		if( !A.CanSetProperty( P.PropertyName ) )
			A.DMT( "Warning -- can't reset property '" $ P.PropertyName $ "' (Type=" $ EnumStr( enum'TPropType', P.PropertyType ) $ ") for Actor " $ A $ " using property flipper " $ P );
			
		A.SetPropertyText( P.PropertyName, P.OldPropertyText );
		if( P.PropertyName == "bHidden" ){ A.StaticFilterState = FS_Maybe; }
	}
}

//------------------------------------------------------------------------------
simulated function PropertyFlipper GetInstance( int i )
{
	if( i == -1 )
		return Self;

	if( i < 0 || i >= ArrayCount(Flippers) )
	{
		warn(i$") PropertyFlipper linked to too many Actors!!");
		return None;
	}

	if( Flippers[i] == None )
	{
		Flippers[i] = Spawn( Class,,, Location, Rotation, Self );
		Flippers[i].Tag = '';	// make sure the trigger doesn't affect us.
	}

	return Flippers[i];
}


Binary Space Partitioning
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Help, int vs bool vs vs

Post by Higor »

viewtopic.php?f=15&t=6189
You're programming on high level scripting language, of course there's gonna be a lot of extra stuff done in the background.
User avatar
Barbie
Godlike
Posts: 2808
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Help, int vs bool vs vs

Post by Barbie »

I tried to understand what you want to know, but I failed. Do you want to know what data types are and how to use them? Or do you look for an example for this PropertyFlipper?
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Red_Fist
Godlike
Posts: 2166
Joined: Sun Oct 05, 2008 3:31 am

Re: Help, int vs bool vs vs

Post by Red_Fist »

Hmm well, lets just use a skaarj.

What things would they affect

what things or reason for bool, or byte or float, and so on.

Say youI want to modify the skaarj, (on the fly using a trigger and property flipper), I can understand changing , say health, or team, but I don't know why I would need to use the others.

What other things could you change for a skaarj, I only understand int. and the property name.
Binary Space Partitioning
User avatar
Barbie
Godlike
Posts: 2808
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Help, int vs bool vs vs

Post by Barbie »

You can use that PropertyFlipper to modify settings during runtime that cannot be done by stock utilities below Triggers (Trigger, SpecialEvent, ...). For example you can change a Skaarj DrawSize (while having his collision cylinder in mind) or his visibility, fatness, skill, ... (IDK if these examples really work during gameplay). Therefore you must know the data type and technical and game valid range of that property: DrawSize (float) may not be negative, visibility (byte) and fatness (byte) is limited to 0...255, Skill (float) is ranged between 0.0 and 3.0 and so on.

You can also have a look into your map "MH-Spillway_XXL72em", where a similar property changer is used:
PropertyChanger50.jpg
PropertyChanger50.jpg (15.49 KiB) Viewed 3879 times

Code: Select all

class PropertyChanger50 expands Triggers;

var() private string property, value;

function Trigger(actor Other, pawn EI)
{
local actor ac;
	foreach allactors(class'actor',ac,event)
	{
		ac.setpropertytext(property,value);
	}
}
BTW: Have you finished the port to MH already? ^^
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Red_Fist
Godlike
Posts: 2166
Joined: Sun Oct 05, 2008 3:31 am

Re: Help, int vs bool vs vs

Post by Red_Fist »

MH, I added that ship from Frigate to make a longer play, and had to shuffle things around, now I need to add more spawn points triggers and other things. I also do want to add one other pawn but I cannot think of it, it's the big pupea I think it shoots pupea , hatchling ? I don't know where to get the dang thing. Otherwise it was done, but played through to fast, still working on it.

OK so, let me ask it this way, what property would have to have a bool or float, unlike just using a larger int number for health. I understand, 100 is larger than 2, that's easy, so just switch that to change health on the fly.
But I don't get why or what the others are needed for.
Binary Space Partitioning
User avatar
sektor2111
Godlike
Posts: 6412
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Help, int vs bool vs vs

Post by sektor2111 »

You can change more things with that in the same way as with PropertyChanger.
Examples:
- in a random moment of week a boss suddenly goes to skill 3 ignoring default server setup;
- In a random moment a weapon won't be "bWeaponStay" in Level any more - a sort of big boom as a present supposed to not respawn any more;
- turning Lights ON Off at once with their presumed lamp-source;
- Monster annoyed badly - suddenly goes to 700 GroundSpeed;
- Monster receiving new orders around Level According to player success of NOT;
- Changing rotation of some Creature depending on some time factor - player wonder how much chances are to be seen;
- Changing some property for Navigation Network;
- On Fly changing prototype from a factory in some instance.

Many of these things are doesn't change using ONLY INT (like that 100), they can be Bool, Float, etc. that's why this tool has so many things.
Last edited by sektor2111 on Thu Apr 21, 2016 3:31 pm, edited 1 time in total.
User avatar
Barbie
Godlike
Posts: 2808
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Help, int vs bool vs vs

Post by Barbie »

Red_Fist wrote:it's the big pupea I think it shoots pupea , hatchling ? I don't know where to get the dang thing.
Do a search for "asgard2.u" and look for "Swarm" in it.
Red_Fist wrote:what property would have to have a bool or float
Have a look in the source code of Actor: there you'll find all properties and their type. An example of bool could be (Acor.uc, line 290):

Code: Select all

var(Collision) bool       bProjTarget;      // Projectiles should potentially target this actor.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6412
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Help, int vs bool vs vs

Post by sektor2111 »

And you cannot count speed in True or False, you need some Numerical Values after all... not all values are the same.
Red_Fist
Godlike
Posts: 2166
Joined: Sun Oct 05, 2008 3:31 am

Re: Help, int vs bool vs vs

Post by Red_Fist »

I sort of understand, but it would be nice to see it work in realtime, in Unreal2 (or UT) applied to an example actor.

I can easily see and know why that int is to change a number for some property.

But not how the others are.

Like "True" or "False" it's definitely not an int number. Unreal2 seems very powerful to make things and still have premade pawns and things, unlike with UDK.

I assume float means an non permanent number.?

This is not critical to make this map but they put those in the property flipper and just wonder why one would pick those types.
Binary Space Partitioning
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Help, int vs bool vs vs

Post by Higor »

1 and 0, that's all you need to know.

Unreal Types:
- INT > 4 byte signed integer.
- FLOAT > 4 byte floating point number.
- BOOL > individual bit packed in a 4 byte generic variable.
- STRING > Dynamic array of TCHAR's (12 bytes: data pointer(4), arraynum(4), arraymax(4))
- NAME > index of a name stored in the name table (4 byte INT)
- BYTE > 1 byte unsigned integer
- ENUM = BYTE
- ARRAY<> > Dynamic array (string is a special case of this)
- OBJECT/CLASS > 4 byte Pointer to a memory address.

Alignment:
Aligns data in memory for increased memory I/O performance, when a data type is smaller than the alignment bytes, then extra padding bytes are added before the next variable's memory space.
Example (0 is padding bytes): INT, FLOAT, BYTE, BYTE, INT, BYTE >>> IIIIFFFFBB00IIIIB000
UT has default alignment of 4 bytes, UE3 games have 8 bytes.

Bool:
Bool properties are single bits in a 4 byte space, you can pack as many as 32 bool properties in the same block.
Example: bCollideActors, bCollideWorld, bBlockActors > 00000000000000000000000000000xxx
Where: True=1, False=0
Trivia: Doing SetPropertyText("bBoolean","1"); works just as well.
When coding, put your booleans together if you can.

Interpretation:
Nothing signals how to handle a memory space, except for the compiled code being executed by the CPU.
UnrealScript doesn't provide neither reinterpretation functions nor generic memory access reading.

Bit fiddling:
A common optimization technique where storage size is critical (replication, net play) is bit fiddling.
Basically, you construct your own variable type and pack it yourself.
Basic example: Array of 32 bools >>> can be packed in a single INT using own code.
Advanced example: Yes/No (1 bit), 16 choices (4 bits) >>> can be packed in a single BYTE using own code.

UProperty:
It's an unreal object (did you see my charts post?) type, it's most commonly used derivates are UIntProperty, UBoolProperty, UFloatProperty, UStringProperty.
These objects are generated upon compile time and chained together to it's owner (generally a class/struct).
These objects contain offset, array size, category, variable flags information on them.
These objects implement 'ImportText', 'ExportText', 'IsIdentical', methods that allow the scripting engine to properly display/handle them.

Interesting hacks:
Imagine you have this struct:

Code: Select all

struct TestHack
{
    var float Data_1;
    var .... Data_...;
    var byte Data_N;
}
Let's say we hack in a new property on it:
var int Raw[n]; with offset 0 and array size just enough to read the entire struct.
Raw[0] is the INT version of the data in Data_1 and so on, basically we're reinterpreting.
In c++ this can be done very easily.

Code: Select all

BYTE* Data; //Pointer to a memory address
*(INT*)&Data[0] = FileSignature; //Write signature to first 4 bytes of Data
*(FLOAT)&Data[4] = TimeStamp; //Write timestamp to second 4 bytes of Data
... etc
When you start thinking in 'generic' it all becomes clear.
User avatar
Barbie
Godlike
Posts: 2808
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Help, int vs bool vs vs

Post by Barbie »

Red_Fist wrote:Like "True" or "False" it's definitely not an int number.
But, it is! ^^ Depending on language one special value (e.g. zero) is interpreted as FALSE, all other values as TRUE. Remember, the CPU processes only numbers, the content of RAM or ROM or mass storage contains only numbers - and even that is not fully correct, they store one of several states (often only 2 states ("dual") are possible) that can be interpreted as a number.
Take for example the (decimal) number 90: it can be representable as 101 1010 in a dual system (e.g. switches:on/off or capacitors: loaded/not loaded) or as the character "Z" using a coding table or as an instruction for the 8088 CPU family (NOP = No Operation) or as TRUE or as part of a float number. It's just a matter of interpretation.
Higor wrote:BOOL > individual bit packed in a 4 byte generic variable.
Really? Not char or byte? What a waste...^^
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
sektor2111
Godlike
Posts: 6412
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Help, int vs bool vs vs

Post by sektor2111 »

If you think simple you might be more lucky. Forget advanced tech and think in Sand-Box. Monster run... Which speed ? Well we speak about a number. Does monster fly ? Let's see if can do that, bCanFly=True/False. Yes, these are Bits 0 1 after all, just stay simple and understand them as they are, and then you can get over them stepping into Natives yard. Mapping doesn't really need so much Rocket Science. Some understanding of UScript can do amazing things. With some imagination a Level can be an extreme great story representation.
What we have:
- Triggers;
- Pathing stuff;
- PropertyChanger;
- CamViewers;
- custom goodies... matching that Level on purpose;
We only need some creativity and tiny UScript knowledge not cube-drawers-only, seriously. It is art in matching colors and lights but THIS is not enough - proved already.
Post Reply