Array – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
(Kilobyte= 1000bytes, Kibibyte = 1024bytes)
mNo edit summary
Line 13: Line 13:


not working, why? I've also tried "tmp = tmp - val1;" --[[User:Messiah2|MessiahUA]] 16:14, 19 September 2008 (CEST)
not working, why? I've also tried "tmp = tmp - val1;" --[[User:Messiah2|MessiahUA]] 16:14, 19 September 2008 (CEST)
-----
How are arrays stored in memory? Last night, I was successfully able to create an array containing 26905 elements. (one for each land grid square on Altis)
<code>[] spawn
{
_number = 0;
_test = [];
_brushes = ["Solid","Horizontal","Vertical","Grid","FDiagonal","BDiagonal","DiagGrid","Cross"];
for "_i" from 0 to 308 do
{
for "_o" from 0 to 308 do
{
if (!surfaceIsWater [(_o * 100) + 50, (_i * 100) + 50]) then
{
_name = format["%1_%2",_o,_i];
_marker = createMarker [_name, [(_o * 100) + 50, (_i * 100) + 50]];
_marker setMarkerShape "RECTANGLE";
_marker setMarkerSize [50,50];
_marker setMarkerBrush (_brushes select (floor random (count _brushes)));
_marker setMarkerColor "ColorRed";
_number = _number + 1;
_test pushBack _marker;
};
};
sleep 0.01;
};
hint str _number;
player setVariable ["holy_shit", _test];
_test = nil;
};</code>
I was able to confirm that the array did actually contain my elements with:
<code>'''//ran from debug console'''
_array = (player getVariable "holy_shit");
_array spawn
{
for "_i" from 0 to ((count _this) - 1) do
{
hintSilent (_this select _i);
sleep 0.05;
};
};</code>
I thought it was strange, at first, that my game didn't crash from running out of memory, but after doing some quick math everything seems to be in order. ASCII uses 7 bits and I was saving 5-6 character strings so:<br>
7 * 6 = 42<br>
42 * 26905 = 1130010 '''bits'''<br>
1130010 / 8 = 141251 '''bytes'''<br>
141251 / 1024 = 138 '''[http://en.wikipedia.org/wiki/Kibibyte kibibytes]''' or 141251 / 1000 = 141 '''[http://en.wikipedia.org/wiki/Kilobyte kilobytes]'''<br>
- [https://community.bistudio.com/wiki/User_talk:DreadedEntity DreadedEntity]

Revision as of 21:39, 15 December 2014

Should there be any comment here or in random about randomly selecting an array element given the rounding rules? Or am I being ridiculous?

e.g.

_myArray select ((random (count _myArray)) - 0.5)

--Mr.Peanut 21:11, 28 September 2006 (CEST)


tmp = []; val1 = [1,2,3]; val2 = [3,4,5]; tmp = tmp + [val1]; tmp = tmp + [val2]; tmp = tmp - [val1];

not working, why? I've also tried "tmp = tmp - val1;" --MessiahUA 16:14, 19 September 2008 (CEST)