Doolittle/Sandbox – User
No edit summary |
Lou Montana (talk | contribs) m (Text replacement - "<code>" to "<code style="display: block">") |
||
(16 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Misc == | |||
Ah, scripting. Here's some fun stuff: | Ah, scripting. Here's some fun stuff: | ||
<code>myfunc = {objnull}; | <code style="display: block">myfunc = {objnull}; | ||
_unit = ["foo"] call myfunk; | _unit = ["foo"] call myfunk; | ||
if (isnull _unit) then {hint "wow!"}; | if (isnull _unit) then {hint "wow!"}; | ||
Line 7: | Line 9: | ||
More interesting stuff about '''private'''. I never got private. Why is it needed? This was interesting: | More interesting stuff about '''private'''. I never got private. Why is it needed? This was interesting: | ||
<code>myfunc = { | <code style="display: block">myfunc = { | ||
_temp = [1,2,3]; | _temp = [1,2,3]; | ||
myglobal = _temp; | myglobal = _temp; | ||
Line 17: | Line 19: | ||
:I've noticed that when you are working with arrays, if the array isn't properly initialized, either with private or a simple _temp []; then you get some undefined type errors and unexpected results. As soon as you initialize the array it seems ok. I've just noticed this over the past few days myself. [[User:Hoz|hoz]] | :I've noticed that when you are working with arrays, if the array isn't properly initialized, either with private or a simple _temp []; then you get some undefined type errors and unexpected results. As soon as you initialize the array it seems ok. I've just noticed this over the past few days myself. [[User:Hoz|hoz]] | ||
More about ''scope'': | |||
<code style="display: block">//_v = objnull; | |||
switch (_foo) do { | |||
case "woof": {_v = player}; | |||
default {_v = objnull}; | |||
}; | |||
if (isnull _v) then {hint "null!"}; | |||
</code> | |||
If _v was assigned a value for the first time inside the '''switch''' statement, and then you checked for if it was null outside... it wouldn't detect a null _v. If however you declare _v before you step into the '''switch''' (see the commented out //_v), then the '''if''' statement at the end ''does'' detect it. This little nuance stuff throws me off. --[[User:Doolittle|Doolittle]] 22:59, 4 August 2007 (CEST) | |||
<hr/> | |||
Why does this give error? | |||
<code style="display: block">_myFunc = { | |||
if (true) exitwith {true}; | |||
false | |||
}; | |||
_ret = [] call _myFunc; | |||
if (true and _ret) then { | |||
player sidechat "it worked 1"; | |||
}; | |||
if (true and [] call _myFunc) then { // generic error in expression | |||
player sidechat "it worked 2"; | |||
}; | |||
</code> Putting parenthesis doesn't fix it either. It's because of the [[and]] and [[exitwith]]. | |||
Technical: if you [[setVehicleInit]] an existing variable it is actually assigned a new memory space. So if you have an array pointing to that var then it now points to nothing. | |||
Click and drag on map to get dialog coords: | |||
(findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonDown", "downX = _this select 2; downY = _this select 3"]; | |||
(findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonUp", "saveXY = format [""x = %1; y = %2; w = %3; h = %4; time = %5"", downX, downY, (_this select 2) - downX, (_this select 3) - downY, floor time]; player sideChat saveXY; localize saveXY"]; | |||
== Important Links == | == Important Links == | ||
[http://community.bistudio.com/wiki/ | [[ArmA:_Version_History]] | ||
[[:Category:ArmA:_Editing]] | |||
[[ArmA:_Moves]] | |||
http://www.ofpec.com/COMREF/armavehicles.php | |||
http://www.ofpec.com/index.php?option=com_smf&Itemid=36&topic=28876.0 Voices | |||
http://community.bistudio.com/wiki/Multiplayer_framework | |||
http://www.armatechsquad.com/ArmA2Class/ | |||
http://dev-heaven.net/wiki/cmb | |||
== My Fav Function So Far == | |||
I figured this out the other day. Maybe it's worth a share. If you have the server sending out publicVars from several scripts... and you want to make sure the users receive all of them (some might get squashed).. here's an easy way to "cache" those publicVariables so that they get sent out at least 1 sec. from each other. | |||
<code style="display: block">publicvarcode = { | |||
if (isnil format ["%1time", _this select 0]) then {call compile format ["%1time = time", _this select 0]}; | |||
waituntil {call compile format ["%1time < time", _this select 0]}; | |||
call compile format ["%1 = _this select 1; publicvariable ""%1""; %1time = time + 1", _this select 0]; | |||
}; | |||
// example | |||
["foobar", "The base is under attack!"] spawn publicvarcode; | |||
["foobar", "Oh no!"] spawn publicvarcode; | |||
["foobar", "Run!"] spawn publicvarcode; | |||
["anObj", player] spawn publicvarcode; | |||
</code> | |||
Note waituntil with a call compile inside may be expensive. It took a while to figure out how to get the second argument to send no matter what var type it was. | |||
== Weird Commands No One Knows About == | |||
[[addVehicle]] | |||
[[deleteCollection]] | |||
[[enableEnvironment]] | |||
[[finishMissionInit]] | |||
[[inGameUISetEventHandler]] | |||
[[initAmbientLife]] | |||
[[isMarkedForCollection]] | |||
[[setAttributes]] | |||
[ | [[supportInfo]] | ||
[ | [[Category:Sandbox]] |
Latest revision as of 11:53, 11 January 2023
Misc
Ah, scripting. Here's some fun stuff:
myfunc = {objnull};
_unit = ["foo"] call myfunk;
if (isnull _unit) then {hint "wow!"};
You won't see "wow". The error is it should be spelled myfunc... but it's hard to catch because, since myfunk is not defined, _unit is not defined, so isnull on a not defined var doesn't even work. So it's hard to track what went wrong here.
More interesting stuff about private. I never got private. Why is it needed? This was interesting:
myfunc = {
_temp = [1,2,3];
myglobal = _temp;
};
call myfunc;
player sidechat str myglobal;
myglobal comes out empty. But if you put private ["_temp"] then it is filled with values. Like the engine knows it's a temp var and so copies it over. Otherwise it doesn't think it's temp (without private) so it doesn't bother to copy, but then the value gets dropped from memory anyways.
- I've noticed that when you are working with arrays, if the array isn't properly initialized, either with private or a simple _temp []; then you get some undefined type errors and unexpected results. As soon as you initialize the array it seems ok. I've just noticed this over the past few days myself. hoz
More about scope:
//_v = objnull;
switch (_foo) do {
case "woof": {_v = player};
default {_v = objnull};
};
if (isnull _v) then {hint "null!"};
If _v was assigned a value for the first time inside the switch statement, and then you checked for if it was null outside... it wouldn't detect a null _v. If however you declare _v before you step into the switch (see the commented out //_v), then the if statement at the end does detect it. This little nuance stuff throws me off. --Doolittle 22:59, 4 August 2007 (CEST)
Why does this give error?
_myFunc = {
if (true) exitwith {true};
false
};
_ret = [] call _myFunc;
if (true and _ret) then {
player sidechat "it worked 1";
};
if (true and [] call _myFunc) then { // generic error in expression
player sidechat "it worked 2";
};
Putting parenthesis doesn't fix it either. It's because of the and and exitwith.
Technical: if you setVehicleInit an existing variable it is actually assigned a new memory space. So if you have an array pointing to that var then it now points to nothing.
Click and drag on map to get dialog coords:
(findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonDown", "downX = _this select 2; downY = _this select 3"]; (findDisplay 12 displayCtrl 51) ctrlSetEventHandler ["MouseButtonUp", "saveXY = format [""x = %1; y = %2; w = %3; h = %4; time = %5"", downX, downY, (_this select 2) - downX, (_this select 3) - downY, floor time]; player sideChat saveXY; localize saveXY"];
Important Links
http://www.ofpec.com/COMREF/armavehicles.php
http://www.ofpec.com/index.php?option=com_smf&Itemid=36&topic=28876.0 Voices
http://community.bistudio.com/wiki/Multiplayer_framework
http://www.armatechsquad.com/ArmA2Class/
http://dev-heaven.net/wiki/cmb
My Fav Function So Far
I figured this out the other day. Maybe it's worth a share. If you have the server sending out publicVars from several scripts... and you want to make sure the users receive all of them (some might get squashed).. here's an easy way to "cache" those publicVariables so that they get sent out at least 1 sec. from each other.
publicvarcode = {
if (isnil format ["%1time", _this select 0]) then {call compile format ["%1time = time", _this select 0]};
waituntil {call compile format ["%1time < time", _this select 0]};
call compile format ["%1 = _this select 1; publicvariable ""%1""; %1time = time + 1", _this select 0];
};
// example
["foobar", "The base is under attack!"] spawn publicvarcode;
["foobar", "Oh no!"] spawn publicvarcode;
["foobar", "Run!"] spawn publicvarcode;
["anObj", player] spawn publicvarcode;
Note waituntil with a call compile inside may be expensive. It took a while to figure out how to get the second argument to send no matter what var type it was.