
Announcement
Collapse
No announcement yet.
Prettier way to fill an array within a function?
Collapse
X
-
RattleSN4K3 repliedOriginally posted by coldscooter View PostBit of a weird question, but this is bothering me.
If I want to fill a temporary array within a function, is there a nicer way to do it than this:
Code:local Array<Int> myArray; myArray.AddItem(1); myArray.AddItem(2); myArray.AddItem(3); myArray.AddItem(4); ...
https://github.com/RattleSN4K3/UC-MiscArrayOps
With that UnrealScript UCI pre-processor script, you can very much create any array with an inline expression.
Code:local array<byte> array_byte; local array<int> array_int; local array<float> array_float; local array<string> array_string; local array<name> array_name; local array<Object> array_object; local array<Actor> array_actor; local array<class> array_class; array_byte = ! byte(1) + 2 + 127 + 255; // {1,2,127,255} array_int = ! 3 + 4 + 42 + 1337; // {3,4,42,1337} array_float = ! 1.337f + 0.666f; // {1.337f, 0.666f} array_string = ! "Some" + "Fancy" + "Array"; // {"Some","Fancy","Array"} array_name = ! 'Could' + 'be' + 'useful'; // {'Could','be','useful'} array_object = ! self + self.Owner + Sprite; // {MyActor_0,MyPlayerController_0,Sprite} array_actor = ! self + self.Owner; // {MyActor_0,MyPlayerController_0} array_class = ! class'MyInv1' + class'MyInv2'; // {MyInv1,MyInv2}
ArrayOp.uci
PS: CobaltUDK's solution is also included:
Code:array_int /= "3,4,42,1337" / ",";
Code:array_int = int("") ~= "3,4,42,1337" / ",";
Leave a comment:
-
CobaltUDK repliedlocal array<string> A;
local string B;
B = "1,2,3,4,5,6,7,8,9,a,b,c,d,e";
A = SplitString(B,",",false);
then A[0] = 1, A[1] = 2, etc.
good for small strings.
You can do a bucle to copy the array to other, converting strings to float or int or what you need.
Leave a comment:
-
UnrealEverything repliedNot really, no. At least I don't think so.
What you can do is have a function that only contains the array initialization. Or if it is really just a sequence of numbers 1-n, at least use a for loop.
If you're repeatedly using the same array you could think about a static dynamic array initialized in defaultproperties or an array of constant size (not sure if either of these are applicable in your scenario). You may still need to copy that but at least you wouldn't need the initialization every time.
Leave a comment:
-
coldscooter started a topic Prettier way to fill an array within a function?Prettier way to fill an array within a function?
Bit of a weird question, but this is bothering me.
If I want to fill a temporary array within a function, is there a nicer way to do it than this:
Code:local Array<Int> myArray; myArray.AddItem(1); myArray.AddItem(2); myArray.AddItem(3); myArray.AddItem(4); ...
Code:local Array<Int>myArray; myArray = [1,2,3,4];
Tags: None
Leave a comment: