Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Scripting.Action


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
// Action
//
// All Action paramters should be of type "string". These parameters must be resolved before use.
// On execution of the action, locals of type Variable should be defined (they are 'new'ed in the resolve function)
// "resolve" should then be called, passing each local Variable and its string representation.
// The string is first parsed to attempt to resolve it to an existing script variable by name.
// If a variable is found, then the value from that object is used to create a new variable object. 
// If no variable by the given name exists, then the resolve function attempts to parse the value to a built-in data type.
class Action extends Core.Object
	editinlinenew
	collapsecategories
	hidecategories(object)
	native
	abstract;

import class Engine.Actor;
import class Engine.Pawn;
import class Engine.LevelInfo;

cpptext
{
	virtual void CleanupDestroyed();
	virtual UAction* FixOwnership(AScript* ownerScript);
	virtual void CheckForErrors(FString& prefix, int index, AScript* ownerScript);
	virtual bool IsMember(UAction* action) { return false; }
}

var string actionDisplayName;
var string actionHelp;
var class<Variable> returnType;
var string category;

var Script parentScript;

// True if this actions properties can accept any return type from a nested action
// used by the assignment actions
var bool acceptAllTypes;

// parameter resolve data
struct native ParameterResolveInfo
{
	var deepcopy Action action;
	var Name variable; 
	var Name propertyName;
};

var private Array<ParameterResolveInfo> resolveInfoList;

// construct
overloaded function construct()
{
	parentScript = Script(Outer);
	assert(parentScript != None);
}

function setParentScript(Script s)
{
	parentScript = s;
}

native final function SetActionPropertyText(string PropName, string PropValue);

// resolveParameters
// Uses the parameterResolveInfo array (previously filled by native UnrealEd code during script creation) to
// set the value of Action or Variable parameters to the run-time return value of an action/variable, if required.
// Call this at the start of your execute function to resolve script variables to Action return values.
private latent function resolveParameters()
{
	local int i;
	local Name propName;
	local Variable v;
	local Array<int> resolveActions;

	ForEach AllProperties(self.Class, class'Action', propName)
	{
		// See if this action property should be set to the value of an action
		for (i = 0; i < resolveInfoList.Length; i++)
		{
			if (resolveInfoList[i].propertyName == propName)
			{
                if (resolveInfoList[i].action != None) // add resolve index to resolve action list
				{
					resolveActions.Length = resolveActions.Length + 1;
					resolveActions[resolveActions.Length - 1] = i;
				}
				else if (resolveInfoList[i].variable != '') // resolve as a variable
				{
					v = tryFindVariable(resolveInfoList[i].variable);

					if (v != None)
					{
						SetActionPropertyText(string(propName), v.GetPropertyText("value"));
					}
				}
				else // empty resolve info
				{
					logError("Parameter "$propName$" has an entry in the resolveinfo map, but has no action or variable resolve target");
				}
			}
		}
	}

	// Execute resolved actions
	for (i = 0; i < resolveActions.Length; ++i)
	{
		v = resolveInfoList[resolveActions[i]].action.execute();

		if (v != None)
		{
			SetActionPropertyText(string(resolveInfoList[resolveActions[i]].propertyName), v.GetPropertyText("value"));
		}
		else
		{
			SetPropertyText(string(resolveInfoList[resolveActions[i]].propertyName), "");
		}
	}
}

// logError
function logError(string reason)
{
	local string s;

	editorDisplayString(s);

	s = "ERROR: "$parentScript.Name$", Action "$s$": "$reason;
	SLog(s);
}

// findByLabel
function Actor findByLabel(class<Actor> actorClass, Name label)
{
	return parentScript.findByLabel(actorClass, label);
}

// findStaticByLabel
function Actor findStaticByLabel(class<Actor> actorClass, Name label)
{
	return parentScript.findStaticByLabel(actorClass, label);
}

simulated function PrecacheSpeech(SpeechManager Manager);

// newVariable
// Convenience
function Variable newVariable(Name variableName, class<Variable> variableType)
{
	return parentScript.newVariable(variableName, variableType);
}

// newTemporaryVariable
// Convenience
function Variable newTemporaryVariable(class<Variable> variableType, optional string initValue)
{
	return parentScript.newTemporaryVariable(variableType, initValue);
}

// findVariable
// Convenience
function Variable findVariable(coerce string variableName)
{
	local Variable v;

    v = class'Variable'.static.findVariable(variableName, parentScript);
	if (v == None)
	{
		logError("Variable "$variableName$" not found");
	}

	return v;
}

// tryFindVariable
// Convenience, doesn't log, use for situations where the find can fail without causing an error (i.e. a test for existance)
function Variable tryFindVariable(coerce string variableName)
{
	local Variable v;

    v = class'Variable'.static.findVariable(variableName, parentScript);

	return v;
}

// execute
latent function Variable execute()
{
	resolveParameters();
	return None;
}

// propertyDisplayString
// resolves a property if necessary and determines the appropriate display string for it
function string propertyDisplayString(Name propName)
{
	local string s;
	local int i;

	for (i = 0; i < resolveInfoList.Length; i++)
	{
		if (resolveInfoList[i].propertyName == propName)
		{
			if (resolveInfoList[i].action != None)
			{
				resolveInfoList[i].action.editorDisplayString(s);
				return s;
			}
			else if (resolveInfoList[i].variable != '')
			{
				return string(resolveInfoList[i].variable);
			}
		}
	}

	return GetPropertyText(string(propName));
}

// editorDisplayString
// called by UnrealEd to get a display string
event function editorDisplayString(out string s)
{
	s = actionDisplayName;
}

// editcombotype list fill functions
// enumScriptLabelList
event function enumScriptLabels(Engine.LevelInfo level, out Array<Name> s)
{
	local Actor a;
	
	ForEach level.AllActors(class'Actor', a)
	{
		if (a.label != a.name && a.label != '')
		{
			s[s.Length] = a.label;
		}
	}
}

// enum all scripts with a valid label
event function enumScripts(Engine.LevelInfo level, out Array<Name> s)
{
	local Script aScript;
	
	ForEach level.AllActors(class'Script', aScript)
	{
		if (aScript.label != '')
		{
			s[s.Length] = aScript.label;
		}
	}
}


defaultproperties
{
	returnType			= None
	actionDisplayName	= "<actionDisplayName>"
	actionHelp			= "<actionHelp>"
	category			= "Default Category"
	acceptAllTypes		= false
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:42.000 - Creation time: st 23.5.2018 00:10:39.997 - Created with UnCodeX